Cart Service - Orden-der-letzten-Haltestelle/WebEngineering GitHub Wiki
Contents
Info
All Request require a header with a bearer token
{
"Authorization": "Bearer dsölkjf2889425"
}
GetCart
This Endpoint will return a list of all CartItems, that the requesting user has.
Endpoint
GET /api/cart/
Response
200
[
{
"id": 18,
"product": {
"id": 1,
"name": "T-Shirt",
"description": "Schwarzes T-Shirt, Größe M",
"amount": 100,
"price": 1999
},
"amount": 10,
"addedAt": "2025-06-19T08:16:31.882Z",
"ownerId": 3
},
{
"id": 20,
"product": {
"id": 2,
"name": "Hoodie",
"description": "Grauer Hoodie, Größe L",
"amount": 50,
"price": 3999
},
"amount": 50,
"addedAt": "2025-06-19T08:22:17.290Z",
"ownerId": 3
}
]
Errors
- 500 (server Error)
GetOrderHistory
This Endpoint returns a list of all items, that the requesting user has already bought.
Endpoint
GET /api/cart/orders
Responses
200
[
{
"id": 4,
"product": {
"id": 1,
"name": "T-Shirt",
"description": "Schwarzes T-Shirt, Größe M",
"amount": 100,
"price": 1999
},
"amount": 1,
"addedAt": "2025-06-08T13:06:11.193Z",
"boughtAt": "2025-06-17T18:34:27.933Z"
},
{
"id": 16,
"product": {
"id": 2,
"name": "Hoodie",
"description": "Grauer Hoodie, Größe L",
"amount": 50,
"price": 3999
},
"amount": 10,
"addedAt": "2025-06-18T17:48:39.132Z",
"boughtAt": "2025-06-18T17:48:45.997Z"
},
{
"id": 12,
"product": {
"id": 3,
"name": "Cap",
"description": "Baseball Cap, schwarz",
"amount": 200,
"price": 1499
},
"amount": 28,
"addedAt": "2025-06-18T17:43:30.997Z",
"boughtAt": "2025-06-18T17:45:02.798Z"
},
{
"id": 2,
"product": {
"id": 3,
"name": "Cap",
"description": "Baseball Cap, schwarz",
"amount": 200,
"price": 1499
},
"amount": 1,
"addedAt": "2025-06-08T13:06:11.193Z",
"boughtAt": "2025-06-17T18:34:27.933Z"
}
]
Errors
- 500 (ServerError)
BuyCart
This Endpoint will set all items in the requesting users cart on bought and sends an email to the user, with the purchase confirmation.
Endpoint
POST /api/cart/buy
Responses
200
[
{
"id": 18,
"product": {
"id": 1,
"name": "T-Shirt",
"description": "Schwarzes T-Shirt, Größe M",
"amount": 100,
"price": 1999
},
"amount": 10,
"addedAt": "2025-06-19T08:16:31.882Z",
"boughtAt": "2025-06-19T08:55:21.979Z"
},
{
"id": 20,
"product": {
"id": 2,
"name": "Hoodie",
"description": "Grauer Hoodie, Größe L",
"amount": 50,
"price": 3999
},
"amount": 50,
"addedAt": "2025-06-19T08:22:17.290Z",
"boughtAt": "2025-06-19T08:55:21.979Z"
}
]
Errors
- 400
- Empty Cart
- Product not enough storage as requested
- 500 (Server Error)
AddProductToCart
This Endpoint adds an Product to the requesting users cart. If this product is already in the cart, the requested amount will be added to the already existing one.
Endpoint
POST /api/cart/product/:productId?amount={amount}
amount is optional, when not given, it will be set to 1
Response
200
[
{
"id": 22,
"product": {
"id": 2,
"name": "Hoodie",
"description": "Grauer Hoodie, Größe L",
"amount": 50,
"price": 3999
},
"amount": 20,
"addedAt": "2025-06-19T08:55:37.515Z",
"ownerId": 3
}
]
Errors
- 404 (Product doesn't exist)
- 400
- Amount below 1
- newAmount higher then products storage amount
- 500 (Server error)
UpdateAmount
This endpoint updates the amount of an cartItem
Endpoint
PUT /api/cart/item/:cartItemId?amount={amount}
Responses
200
[
{
"id": 22,
"product": {
"id": 2,
"name": "Hoodie",
"description": "Grauer Hoodie, Größe L",
"amount": 50,
"price": 3999
},
"amount": 3,
"addedAt": "2025-06-19T08:55:37.515Z",
"ownerId": 3
}
]
Errors
- 400
- Amount below 1
- newAmount higher then storage amount of product
- 404 (CartItem doesn't exist)
- 403 (CartItem isn't owned by user)
- 500 (server error)
DeleteCartItem
This Endpoint will delete one CartItem of the users Cart.
Endpoint
DELETE /api/cart/item/:cartItemId
Responses
200
Cart without the deleted item
[
{
"id": 23,
"product": {
"id": 2,
"name": "Hoodie",
"description": "Grauer Hoodie, Größe L",
"amount": 50,
"price": 3999
},
"amount": 20,
"addedAt": "2025-06-19T08:56:30.203Z",
"ownerId": 3
},
{
"id": 24,
"product": {
"id": 3,
"name": "Cap",
"description": "Baseball Cap, schwarz",
"amount": 200,
"price": 1499
},
"amount": 20,
"addedAt": "2025-06-19T08:56:32.264Z",
"ownerId": 3
}
]
Errors
- 403 (CartItem isn't owned by User)
- 404 (CartItem doesn't exist)
- 500 (Server Error)
DeleteCart
This Endpoint will delete all CartItems, that the requesting user has.
Endpoint
DELETE /api/cart/item/:cartItemId
Responses
200
{
"message": "Deleted Cart of User with Id: 1"
}
Errors
- 500 (Server Error)