On this page
Final project: complete product catalog API
Final project: product catalog API
This project integrates all the course concepts into a functional, well-structured API. You will implement:
- Related entities with EF Core (Product, Category, Tag β N:M relationship)
- Immutable DTOs with records and DataAnnotations validation
- Advanced search and filtering with LINQ (multiple chained filters, pagination)
- JWT authentication with Admin/User roles
- Request logging middleware
- Unit and integration tests
Project structure
CatalogApi/
βββ Domain/
β βββ Entities/
β β βββ Product.cs
β β βββ Category.cs
β β βββ Tag.cs
β βββ Interfaces/
β βββ IProductRepository.cs
βββ Infrastructure/
β βββ Data/
β β βββ CatalogDbContext.cs
β β βββ Configurations/
β β βββ ProductConfiguration.cs
β βββ Repositories/
β βββ ProductRepository.cs
βββ Application/
β βββ DTOs/
β β βββ ProductDtos.cs
β βββ Services/
β βββ IProductService.cs
β βββ ProductService.cs
βββ API/
β βββ Controllers/
β β βββ AuthController.cs
β β βββ ProductsController.cs
β βββ Middleware/
β βββ RequestLogMiddleware.cs
βββ Tests/
β βββ Unit/
β β βββ ProductServiceTests.cs
β βββ Integration/
β βββ ProductsApiTests.cs
βββ Program.csImplementation milestones
Milestone 1: Data and DB (30 min)
Implement the entities, DbContext with Fluent API, and the N:M relationship between Product and Tag using UsingEntity. Generate the initial migration and apply it to SQLite:
dotnet add package Microsoft.EntityFrameworkCore.Sqlite
dotnet ef migrations add InitialCreate
dotnet ef database updateMilestone 2: Repository and LINQ (30 min)
Implement SearchAsync with chained filters, pagination, and DTO projection. Write at least 5 unit tests with InMemory DB to verify the filters.
Milestone 3: Controllers and JWT (30 min)
Create the AuthController with POST /auth/login and POST /auth/register. Protect the create, update, and delete endpoints with [Authorize].
Milestone 4: Middleware and integration tests (20 min)
Add RequestLogMiddleware with response times. Write integration tests with WebApplicationFactory for the main endpoints.
Bonus features
Once you complete the main milestones, add:
// 1. Export products to CSV
[HttpGet("export")]
[Authorize(Roles = "Admin")]
public async Task<FileResult> ExportCsv()
{
var products = await _repo.GetAllAsync();
var csv = new StringBuilder();
csv.AppendLine("Id,Name,Price,Stock,Category");
foreach (var p in products)
csv.AppendLine($"{p.Id},{p.Name},{p.Price},{p.Stock},{p.Category}");
var bytes = Encoding.UTF8.GetBytes(csv.ToString());
return File(bytes, "text/csv", "products.csv");
}
// 2. Statistics endpoint with LINQ GroupBy
[HttpGet("stats")]
public async Task<ActionResult<object>> Statistics()
{
var stats = await _db.Products
.Where(p => p.Active)
.GroupBy(p => p.Category.Name)
.Select(g => new
{
Category = g.Key,
Count = g.Count(),
InventoryValue = g.Sum(p => p.Price * p.Stock),
AverageStock = g.Average(p => p.Stock),
})
.ToListAsync();
return Ok(stats);
}
// 3. Full-text search suggestions with LINQ
[HttpGet("suggestions")]
public async Task<ActionResult<IEnumerable<string>>> Suggestions([FromQuery] string q)
{
var names = await _db.Products
.Where(p => p.Active && p.Name.Contains(q))
.OrderBy(p => p.Name)
.Take(10)
.Select(p => p.Name)
.ToListAsync();
return Ok(names);
}Delivery checklist
Verify that your project:
- Compiles without errors or warnings (
dotnet build) - All migrations are applied
- All tests pass (
dotnet test) - Swagger correctly documents all endpoints
- Protected endpoints return 401 without a token
- Search with combined filters works correctly
- Pagination returns the correct total and page counts
- Middleware logs all requests with timing
Resources to continue
With these solid fundamentals, natural next steps are:
- gRPC with .NET β for efficient communication between microservices
- SignalR β for real-time communication (WebSockets)
- Blazor β for interactive web applications with C# in the browser
- MAUI β for cross-platform mobile and desktop applications
- Orleans β for distributed systems and the actor model
- Clean Architecture β for scalable enterprise projects
Congratulations on completing the .NET with C# course!
Sign in to track your progress