In this project, expectation is develop a basket service. The service will be a REST API developed in Go.
Customers will be able to purchase existing products. Use cases such as creating, updating, deleting products or creating users etc. for admin won’t be developed. You can just insert necessary data into the database using SQL for customer use cases to run. No UI will be developed. You can make your tests using REST test tools such as Postman.
- Users should be able to list all products.
- Users can add their products to the basket and the total of the basket changes accordingly.
- Users can list the products they have added to their cart and total price and VAT of the cart.
- Users can remove the products added from the cart. Notice removing an item may change discount.
- Users can create an order with the products they add to their cart. There is no need to implement any payment mechanism. You can assume that when an order is completed it is fully paid.
VAT might be different for different products. Typical VAT percentage is %1, %8 and %18. So use these values for your products.
- a. Every fourth order whose total is more than given amount may have discount depending on products. Products whose VAT is %1 don’t have any discount but products whose VAT is %8 and %18 have discount of %10 and %15 respectively.
- b. If there are more than 3 items of the same product, then fourth and subsequent ones would have %8 off.
- c. If the customer made purchase which is more than given amount in a month then all subsequent purchases should have %10 off.
- d. Only one discount can be applied at a time. Only the highest discount should be applied.
- Organize your code around packages.
- Observe cohesion and coupling.
- Apply clean code and clean architecture principles.
- Apply Go idioms.
- Create your own errors if needed.
- “Given amount” in requirements can change so make it changeable.
- Write unit tests for business logic only.
- Apply well-known REST API patterns.
- Use a well-known relational database such as MySQL or PostgreSQL.
git clone github.com/mervanerdem/PropertyFinderSaleAPI
After cloning if you don't have used library, install them.(It's not about using library but you can see in that link)
For building
go build ./
Or Runing
go run ./
In this project use the localhost.
baseURL: localhost:8080
In this case We will list product from MySQL database.
use GET
method with URL
and URL is:
/api/products
The response is be like
{
"Product List": "Successful",
"Products": [
{
"ProductID": 1,
"ProductName": "Bread",
"ProductPrice": 4,
"ProductVAT": 1
},
{
"ProductID": 2,
"ProductName": "Chicken",
"ProductPrice": 45,
"ProductVAT": 1
},
{
"ProductID": 3,
"ProductName": "cheese",
"ProductPrice": 18,
"ProductVAT": 1
},
{
"ProductID": 4,
"ProductName": "olives",
"ProductPrice": 30,
"ProductVAT": 1
}
]
}
In this case Products will be added to basket and save the data.
use POST
method with URL
and URL is:
/api/:idCustomer/basket/add
And the customer id has to be assigned.
The body type has to be like:
{
"ProductID": 4,
"ProductNumber" : 3
}
The response is be like
{
"Basket": [
{
"BasketID": 113,
"CustomerID": 1,
"ProductID": 4,
"ProductName": "olives",
"ProductPrice": 30,
"ProductVAT": 1,
"ProductNum": 3,
"ProductTotalPrice": 81
}
],
"Message": "Successful",
"Total Pay": 81
}
In this case We will list basket products. Data will be reading from database
use GET
method with URL
and URL is:
/api/:idCustomer/basket
And the customer id has to be assigned.
The response is be like
{
"Basket": [
{
"BasketID": 113,
"CustomerID": 1,
"ProductID": 4,
"ProductName": "olives",
"ProductPrice": 30,
"ProductVAT": 1,
"ProductNum": 3,
"ProductTotalPrice": 81
}
],
"Message": "Successful",
"Total Pay": 81
}
In this case Products will be deleted to basket and save the data.
use POST
method with URL
and URL is:
/api/:idCustomer/basket/delete
And the customer id has to be assigned.
The body type has to be like:
{
"ProductID": 4,
"ProductNumber" : 1
}
The response is be like
{
"Basket": [
{
"BasketID": 112,
"CustomerID": 1,
"ProductID": 4,
"ProductName": "olives",
"ProductPrice": 30,
"ProductVAT": 1,
"ProductNum": 2,
"ProductTotalPrice": 54
}
],
"Message": "Successful",
"Total Pay": 54
}
In this case, the products added to the cart by the customer will be sold and the data will be saved.
Use POST
method with URL
and URL is:
/api/:idCustomer/Sale
And the customer id has to be assigned.
No need body.
The response is be like
{
"Message": "Successful",
"Sale": [
{
"CustomerID": 1,
"ProductID": 4,
"ProductName": "olives",
"ProductPrice": 30,
"ProductVAT": 1,
"ProductNum": 5,
"ProductTotalPrice": 135,
"SaleDate": "2022-08-08 22:02:21",
"CampaignOrderNum": 2
}
],
"Total Pay": 135
}
Thanks to Patika.dev for all courses and bootcamp.
Thanks to the bootcamp sponsor Property Finder for all the attention and instructions.