Product Service
You are the main dev of a big online shop. The old product service is written in an esoteric language, which cannot handle more than 10.000 requests per second. Now you want to try Go, so let's do this!
Create a RESTful service with the http web-framework Gin.
It has the following endpoints:
GET /product - List all articles
GET /product/{id} - Get a specific article
POST /product - Create a product
PUT /product/{id} - Update a product
DELETE /product/{id} - Delete a product
The product struct uses the package https://pkg.go.dev/github.com/shopspring/decimal for prices:
core/domain/product.go | |
---|---|
The service should have two possible ways to store products and categories.
It should store all data in memory or in json files called products.json
.
Use interfaces, domain driven hexagonal architecture and dependency injection to built the service properly.
Example Requests:
Create products
Request:
Response:
Request:
Response:
Request:
Response:
{
"error": "Key: 'ProductBody.Name' Error:Field validation for 'Name' failed on the 'required' tag"
}
Get products
Request:
Response:
[
{
"id": 1,
"name": "iPhone 14 Pro",
"category": "smartphones",
"price": "99.99"
},
{
"id": 2,
"name": "iPhone 13 Pro",
"category": "smartphones",
"price": "999.99"
}
]
Get a specific product
Request:
Response:
{
"id": 1,
"name": "iPhone 14 Pro",
"category": "smartphones",
"price": "99.99"
}
Request:
Response:
Update a product
Request:
Response:
Delete a product
Request:
Response: