This is a .NET Web API developed using CQRS and Clean Architecture. The purpose of this API is to provide an API that users can perform basic CRUD operations.
The application has been dockerized for ease of deployment. When you run the docker image, it will run a postgre server in the background, create databases & tables, and fill the tables with the sample data provided with the case.
The requirements for the project were:
- Get sales history
- Add new sales history record
- Delete sales history record
- Update sales history record
- Get profit for given store
- Get the most profitable store
- Get the best seller product by sales quantity
- You can use table schemas specified in csv files. Please specify any changes you make - if any - in the database design.
- You should not use any ORM tool. All database operations should be done by queries.
- .NET 7
- Docker
- PostgreSQL
- .NET 7 SDK
- Docker
Clone the repository
git clone https://github.com/cansozbir/ProductService.git
Change to the project directory
cd ProductService
Run docker image
docker-compose up --build
If you want to avoid docker, you can use following commands to build & run the project, but in this case, please don't forget to create the database yourself.
Build the project
dotnet build
Run the project
dotnet ./src/ProductService.WebAPI/bin/Debug/net7.0/ProductService.WebAPI.dll
When you run the application with docker. You can access to the swagger with the following url:
http://localhost:8088/swagger/index.html
Most of the endpoints won't do anything with the specified Id. (eg. sending e request with id=0, storeName="Test" will only update the storeName, but not the id)
Every controller in this project has a documentation in it. You can visit them to see what each method does, which exceptions it throws, etc..
If you want to see the list of endpoints:
GET
/api/InventorySale
POST /api/InventorySale
GET /api/InventorySale/{id}
PUT /api/InventorySale/{id}
DELETE /api/InventorySale/{id}
GET /api/InventorySale/store/{storeId} Product
GET /api/Product
POST /api/Product
GET /api/Product/{id}
PUT /api/Product/{id}
DELETE /api/Product/{id}
GET /api/Product/bestSellerByQuantity Store
GET /api/Store
POST /api/Store
GET /api/Store/{id}
PUT /api/Store/{id}
DELETE /api/Store/{id}
GET /api/Store/{id}/profit
GET /api/Store/mostProfitable
This project is based on the Clean Architecture principles proposed by Robert C. Martin (Uncle Bob). The architecture is divided into the following layers:
Domain: This layer contains the business logic of the application.
Application: This layer contains the use cases of the application.
Infrastructure: This layer contains the implementation details of the application (e.g. data access, external services).
WebAPI: This layer exposes the application to the outside world through RESTful APIs.
Database names, column names, and the data was already provided in the case.
I only modified InventorySales
table, to have a Id column. Becase I wanted to have unique rows, so I can perform delete as well.
The database structure for this application is as follows:
Column Name | Data Type |
---|---|
Id | int |
Column Name | Data Type |
---|---|
Id | int |
ProductName | varchar |
Cost | decimal |
SalesPrice | decimal |
Column Name | Data Type |
---|---|
Id | int |
ProductId | int |
StoreId | int |
Date | datetime |
SalesQuantity | int |
Stock | int |
- Deploy to web, and make it publicly accessible.
- Write unit tests & architectural tests.
- Fork it (https://github.com/cansozbir/ProductService)
- Create your feature branch (git checkout -b feature/fooBar)
- Commit your changes (git commit -am 'Add some fooBar')
- Push to the branch (git push origin feature/fooBar)
- Create a new Pull Request