A standalone ASP.NET Core Web API for serving book data and related information. This API provides endpoints for managing books, book reviews, bookshelves, book tones, book tone recommendations, and book cover images.
- Book Management: CRUD operations for books with metadata
- Book Reviews: Store and retrieve book reviews with ratings
- Book Tone Recommendations: AI-powered tone suggestions with feedback system
- Bookshelves: Organize books into custom bookshelves with grouping support
- Book Cover Images: Automatic book cover image fetching and storage
- Search: Full-text search capabilities for books and reviews
- Tones: Categorize books by tone/mood with hierarchical structure
- Tone Assignment: Assign tones to books and book reviews
- Swagger Documentation: Interactive API documentation
This project uses a shared library architecture with BookDataApi.Shared containing:
- Core Models:
Book,BookToneRecommendation,Tone - All DTOs: Data transfer objects for API contracts
- Shared Contracts: Reusable across multiple projects
The main API project extends these shared models with Entity Framework navigation properties.
- .NET 8.0 SDK
- PostgreSQL database
- Install PostgreSQL if you haven't already
- Create a new database:
CREATE DATABASE book_data_api;
- Update the connection string in
appsettings.jsonif needed:{ "ConnectionStrings": { "DefaultConnection": "Host=localhost;Database=book_data_api;Username=your_username;Password=your_password" } }
- Copy
appsettings.Development.jsonand update the Google Custom Search API settings:{ "GoogleCustomSearch": { "ApiKey": "your-google-api-key", "SearchEngineId": "your-search-engine-id" } }
Run the following commands to set up the database:
# Install Entity Framework tools (if not already installed)
dotnet tool install --global dotnet-ef
# Create and apply database migrations
dotnet ef database update# Build the project
dotnet build
# Run the application
dotnet runThe API will be available at:
- API Base URL: http://localhost:5020
- Swagger Documentation: http://localhost:5020/swagger
GET /api/books- Get all books (with pagination and search)GET /api/books/{id}- Get book by IDPOST /api/books- Create new bookPUT /api/books/{id}- Update bookDELETE /api/books/{id}- Delete book
GET /api/booktonerecommendations- Get all recommendations (with optional tone filtering)GET /api/booktonerecommendations/{id}- Get recommendation by IDGET /api/booktonerecommendations/book/{bookId}- Get recommendations for a specific bookPOST /api/booktonerecommendations- Create new recommendationPUT /api/booktonerecommendations/{id}- Update recommendation feedback and tone
GET /api/bookreviews- Get all book reviewsGET /api/bookreviews/{id}- Get book review by IDPOST /api/bookreviews- Create new book reviewPUT /api/bookreviews/{id}- Update book reviewDELETE /api/bookreviews/{id}- Delete book review
GET /api/bookshelves- Get all bookshelves with configurationGET /api/bookshelves/{id}- Get bookshelf by IDPOST /api/bookshelves- Create new bookshelfPUT /api/bookshelves/{id}- Update bookshelfDELETE /api/bookshelves/{id}- Delete bookshelf
GET /api/bookshelfgroupings- Get all bookshelf groupingsPOST /api/bookshelfgroupings- Create new groupingPUT /api/bookshelfgroupings/{id}- Update groupingDELETE /api/bookshelfgroupings/{id}- Delete grouping
GET /api/bookcovers/{searchTerm}- Get book cover imagePOST /api/bookcovers- Upload book cover image
GET /api/tones- Get all tonesGET /api/tones/{id}- Get tone by IDPOST /api/tones- Create new tonePUT /api/tones/{id}- Update toneDELETE /api/tones/{id}- Delete tone
GET /api/toneassignment- Get tone assignment data for books and reviewsPOST /api/toneassignment/assignment- Update tone assignments
book-data-api/
├── Controllers/ # API controllers
├── Data/ # Database context and configuration
├── Models/ # Entity models (extend shared models)
├── Services/ # Business logic services
├── Migrations/ # Database migrations
├── Program.cs # Application entry point
└── BookDataApi.Shared/ # Shared library (separate project)
├── Models/ # Core models without EF navigation
└── Dtos/ # All DTOs for API contracts
The following DTOs are available in BookDataApi.Shared:
Book-related:
BookDto,CreateBookDto,UpdateBookDtoBookToneRecommendationDto,CreateBookToneRecommendationDto,UpdateBookToneRecommendationDto
Bookshelf-related:
BookshelfDto,BookshelfConfigurationDtoBookshelfDisplayItemDto,BookshelfGroupingItemDto
Tone-related:
ToneDto,ToneItemDto,ToneAssignmentDtoBookReviewToneItemDto,GenreToneAssociationDto
Other:
BookCoverImageDto,ErrorViewModel
- For shared functionality: Add to
BookDataApi.Sharedproject - For EF-specific features: Add to main project's
Models/directory - Create model classes in the appropriate location
- Add DbSet to
ApplicationDbContext - Create a new migration:
dotnet ef migrations add MigrationName - Apply the migration:
dotnet ef database update - Create controller in
Controllers/directory - Add any necessary services in
Services/directory
The application uses the following configuration sections:
- ConnectionStrings: Database connection string
- GoogleCustomSearch: Google Custom Search API settings
- Logging: Logging configuration
- Kestrel: Server configuration (port 5020)
The API is configured to allow all origins in development. For production, update the CORS policy in Program.cs.
- Database Connection: Ensure PostgreSQL is running and the connection string is correct
- Port Already in Use: The application runs on port 5020 by default. Change it in
appsettings.Development.jsonif needed - Migration Errors: If you encounter migration issues, you can remove the
Migrations/folder and create a new initial migration - Shared Library Build Issues: Ensure
BookDataApi.Sharedbuilds before the main project
Check the console output for detailed error messages and logs.
MIT License
Copyright (c) 2024 Levi Hobbs
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.