SalesStoreAPI This project implements a RESTful API for managing sales records, developed as part of a developer evaluation process. It follows Domain-Driven Design (DDD) principles and uses .NET 8.0, C#, EF Core, MediatR, AutoMapper, and PostgreSQL. Features
CRUD Operations for sales, including sale number, date, customer, branch, products, quantities, prices, discounts, and status. Business Rules: 10% discount for 4+ identical items. 20% discount for 10-20 identical items. Maximum 20 identical items per product. No discounts for <4 items.
Events: Logs for SaleCreated, SaleModified, SaleCancelled. Authentication: JWT-based authentication via POST /auth/login. Pagination, Sorting, Filtering: Supported in GET /sales. Tests: Unit tests with xUnit and NSubstitute.
Prerequisites
.NET 8.0 SDK PostgreSQL 15+ Git IDE (e.g., Visual Studio, Rider)
Setup
Clone the Repository: git clone cd SalesStoreAPI
Configure Database:
Create a PostgreSQL database named SalesStoreAPI. Update the connection string in src/SalesStoreAPI.Api/appsettings.json:{ "ConnectionStrings": { "DefaultConnection": "Host=localhost;Database=SalesStoreAPI;Username=postgres;Password=your-password" } }
Restore Dependencies: dotnet restore
Run Migrations: cd src/SalesStoreAPI.Api dotnet ef migrations add InitialCreate dotnet ef database update
Run the Application: dotnet run
The API will be available at https://localhost:5001.
API Endpoints
POST /auth/login: Authenticate user and get JWT token. POST /sales: Create a new sale. GET /sales/{id}: Retrieve a sale by ID. PUT /sales/{id}: Update a sale. DELETE /sales/{id}: Cancel a sale. GET /sales: List sales with pagination, sorting, and filtering.
See API Documentation for details. Testing
Run Unit Tests:cd tests/SalesStoreAPI.Tests.Unit dotnet test
Project Structure
src/: Source code (API, Application, Domain, Infrastructure). tests/: Unit tests. docs/: API documentation.
Dependencies
.NET 8.0 EF Core MediatR AutoMapper Npgsql xUnit NSubstitute Swashbuckle (Swagger)
Notes
The project uses Git Flow with semantic commits. Events are logged to the console for simplicity. The API is secured with JWT authentication.