https://github.com/sonalys/clean-architecture
A simple cart rest API using clean architecture
https://github.com/sonalys/clean-architecture
learning-by-doing
Last synced: 7 months ago
JSON representation
A simple cart rest API using clean architecture
- Host: GitHub
- URL: https://github.com/sonalys/clean-architecture
- Owner: sonalys
- Created: 2020-12-11T20:36:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-11T20:37:48.000Z (over 5 years ago)
- Last Synced: 2025-10-13T13:35:59.736Z (8 months ago)
- Topics: learning-by-doing
- Language: Go
- Homepage:
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Cart API
========
## Documentation
[Here](./documentation/readme.md)
### Domain Types
The Cart API consists of two simple types: `Cart` and `CartItem`. The `Cart`
holds zero or more `CartItem` objects.
### Create Cart
A new cart should be created and an ID generated. The new empty cart should be returned.
```sh
$ curl -X POST http://localhost:3000/carts -d '{}'
```
```json
{
"id": 1,
"items": []
}
```
### Add to cart
A new item should added to an existing cart. Should fail if the cart does not
exist, if the product name is blank, or if the quantity is non-positive. The
new item should be returned.
```sh
$ curl -X POST -H 'content-type: application/json' http://localhost:3000/carts/1/items -d '{
"product": "Shoes",
"quantity": 10
}'
```
```json
{
"id": 1,
"cart_id": 1,
"product": "Shoes",
"quantity": 10
}
```
### Remove from cart
An existing item should be removed from a cart. Should fail if the cart does not
exist or if the item does not exist.
```sh
$ curl -X DELETE http://localhost:3000/carts/1/items/1
```
```json
{}
```
### View cart
An existing cart should be able to be viewed with its items. Should fail if the
cart does not exist.
```sh
$ curl http://localhost:3000/carts/1
```
```json
{
"id": 1,
"items": [
{
"id": 1,
"cart_id": 1,
"product": "Shoes",
"quantity": 10
},
{
"id": 2,
"cart_id": 1,
"product": "Socks",
"quantity": 5
}
]
}
```