The Basket Service is a microservice for managing shopping baskets in an e-commerce application. It provides APIs for adding, removing, and updating items in a user's basket.
- .NET 8
- SQL Server (or an alternative database)
- RabbitMQ (if event-driven architecture is used)
- Clone the repository:
git clone https://github.com/nosratifarhad/Basket.git cd basket-service - Install dependencies:
dotnet restore
- Run the application:
dotnet run
- ASP.NET Core 8 - Web API framework
- MediatR - CQRS pattern implementation
- Dapper - Data access
- Repository Pattern - Separation of concerns
- MassTransit - Message-based event-driven architecture
GET /api/v1/baskets{
"userBasketId": 1,
"userId": 123,
"amount": 100.00,
"totalAmount": 120.00,
"deliveryPrice": 10.00,
"vatAmount": 10.00,
"userBasketItems": [
{
"userBasketId": 1,
"slug": "product-1",
"productName": "Product 1",
"price": 50.00,
"latestPrice": 45.00,
"userChangedSeen": false,
"quantity": 2,
"discount": 5.00,
"priceChanged": true
},
{
"userBasketId": 1,
"slug": "product-2",
"productName": "Product 2",
"price": 30.00,
"latestPrice": null,
"userChangedSeen": true,
"quantity": 1,
"discount": null,
"priceChanged": false
}
]
}200 Ok
POST /api/v1/baskets{
"userId": 123,
"slug": "product-xyz",
"price": 50000,
"productName": "Product XYZ"
}201 Created
DELETE /api/v1/baskets204 NoContent
PUT /api/v1/baskets/{userBasketItemId}/decrease204 NoContent
PUT /api/v1/baskets/{userBasketItemId}/increase204 NoContent
Handles basket operations including adding/removing items and updating quantities.
Responsible for building basket objects and calculating VAT.
IBasketReadRepository- Read operationsIBasketWriteRepository- Write operations
Handles price change events using MassTransit. Updates basket items and recalculates total amounts when a price change event occurs.
- Fetches all basket items related to the changed price.
- Updates the price, sets
UserChangedSeentofalse. - Updates affected baskets by recalculating VAT and total amount.
Feel free to contribute by submitting a pull request.
MIT License.