https://github.com/nosratifarhad/basket
๐ Basket Service
https://github.com/nosratifarhad/basket
dapper dotnet dotnet-core event masstransit mediatr rest-api
Last synced: about 2 months ago
JSON representation
๐ Basket Service
- Host: GitHub
- URL: https://github.com/nosratifarhad/basket
- Owner: nosratifarhad
- Created: 2025-03-19T11:27:51.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-12T09:59:11.000Z (about 1 year ago)
- Last Synced: 2025-04-13T05:43:03.304Z (about 1 year ago)
- Topics: dapper, dotnet, dotnet-core, event, masstransit, mediatr, rest-api
- Language: C#
- Homepage:
- Size: 48.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ Basket Service
## ๐ Introduction
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.
## ๐ Getting Started
### ๐ Prerequisites
- .NET 8
- SQL Server (or an alternative database)
- RabbitMQ (if event-driven architecture is used)
### ๐ง Installation
1. Clone the repository:
```sh
git clone https://github.com/nosratifarhad/Basket.git
cd basket-service
```
2. Install dependencies:
```sh
dotnet restore
```
3. Run the application:
```sh
dotnet run
```
## ๐ Technologies Used
- **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
## ๐ API Endpoints
### ๐งต Get Basket
```http
GET /api/v1/baskets
```
#### Response
```json
{
"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**
### โ Add Item to Basket
```http
POST /api/v1/baskets
```
#### Request Body
```json
{
"userId": 123,
"slug": "product-xyz",
"price": 50000,
"productName": "Product XYZ"
}
```
#### Response
**201 Created**
---
### โ Remove Basket
```http
DELETE /api/v1/baskets
```
#### Response
**204 NoContent**
---
### ๐ฝ Decrease Item Quantity
```http
PUT /api/v1/baskets/{userBasketItemId}/decrease
```
#### Response
**204 NoContent**
---
### ๐ผ Increase Item Quantity
```http
PUT /api/v1/baskets/{userBasketItemId}/increase
```
#### Response
**204 NoContent**
## ๐ Code Structure
### `BasketService`
Handles basket operations including adding/removing items and updating quantities.
### `UserBasketBuilder`
Responsible for building basket objects and calculating VAT.
### `Repositories`
- `IBasketReadRepository` - Read operations
- `IBasketWriteRepository` - Write operations
### `ChangedPriceConsumer`
Handles price change events using **MassTransit**. Updates basket items and recalculates total amounts when a price change event occurs.
#### **Key Method: `Consume`**
- Fetches all basket items related to the changed price.
- Updates the price, sets `UserChangedSeen` to `false`.
- Updates affected baskets by recalculating VAT and total amount.
## ๐ค Contributing
Feel free to contribute by submitting a pull request.
## ๐ License
MIT License.