This project implements a Web API for managing orders and products in an e-commerce store, built with ASP.NET Core. It follows Domain-Driven Design (DDD) principles, and provides functionalities to create, manage, and query orders and products.
- Objective
- Implemented Features
- Routes
- Requirements
- Testing
- Setup Instructions
- Technologies Used
- License
The goal of this project is to create a Web API in ASP.NET Core that allows users to manage orders in an e-commerce store. The API includes functionalities such as adding/removing products to/from an order, closing orders, and retrieving orders by their ID.
- Create a new order: Allows the creation of a new order.
- Add products to an order: Allows products to be added to an open order.
- Remove products from an order: Allows removal of products from an open order.
- Close an order: Closes an order after ensuring it has at least one product.
- List orders: Retrieves all orders with pagination and filters.
- Get order by ID: Retrieves a specific order by its ID, including all associated products.
- Products cannot be added or removed from a closed order.
- An order can only be closed if it contains at least one product.
- Description: Starts a new order.
- Request: None
- Response: The ID of the created order.
- Description: Adds a product to an existing order.
- Request: Product details (ID, name, price).
- Response: None (Returns a status indicating success).
- Description: Removes a product from an existing order.
- Request: None
- Response: None (Returns a status indicating success).
- Description: Closes an existing order.
- Request: None
- Response: None (Returns a status indicating success).
- Description: Retrieves a list of orders, with pagination and filtering by status (open/closed).
- Request: Page number, page size, optional filters (status).
- Response: List of orders.
- Description: Retrieves a specific order by its ID.
- Request: Order ID.
- Response: Order details (including products).
- Entity Framework Core: Used for persistence.
- In-Memory Database: The project uses an in-memory database for simplicity.
- Swagger: Integrated for API documentation.
- DDD Principles: The project follows Domain-Driven Design (DDD) principles, with clearly separated layers for domain, application, and infrastructure.
The API can be tested using Swagger UI. It's also possible to run the unit tests in the Store.Tests project. Here’s a summary of the steps to test each feature:
-
Create an order:
- Send a
POSTrequest to/orders. - The response will return the
IDof the created order.
- Send a
-
Add a product:
- Send a
POSTrequest to/orders/{orderId}/productswith product details. - Check that the product has been added by retrieving the order details.
- Send a
-
Remove a product:
- Send a
DELETErequest to/orders/{orderId}/products/{productId}. - Verify the product is removed by checking the order details.
- Send a
-
Close the order:
- Send a
POSTrequest to/orders/{orderId}/close. - Verify that the order is closed by checking the order status.
- Send a
-
List orders:
- Send a
GETrequest to/orders. - Verify that orders are returned with pagination.
- Send a
-
Get order by ID:
- Send a
GETrequest to/orders/{orderId}. - Verify that the correct order and associated products are returned.
- Send a
-
Clone this repository to your local machine.
git clone https://github.com/gasn331/Store.git
-
Navigate to the project folder.
cd Store -
Open the solution file (
Store.sln) in Visual Studio or Visual Studio Code. -
Restore the required NuGet packages:
dotnet restore
-
Run the application:
dotnet run
-
Access the API documentation via Swagger at
http://localhost:5000/swagger(by default).
- ASP.NET Core: Web API framework.
- Entity Framework Core: ORM for database access.
- In-Memory Database: Simplified persistence for testing.
- Swagger: For API documentation.
- DDD (Domain-Driven Design): Project structure based on DDD principles.
This project is licensed under the MIT License - see the LICENSE file for details.