Skip to content

Commit

Permalink
cart-api open api spec changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jurabek committed Jan 21, 2024
1 parent c814d5a commit 54c4644
Show file tree
Hide file tree
Showing 10 changed files with 513 additions and 104 deletions.
2 changes: 1 addition & 1 deletion src/backend/docker/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
- CHECKOUT_TOPIC=checkout
- IDENTITY_URL=http://identity-api
- AUTH_URL=http://localhost:8080/identity
- BASE_PATH=/basket
- BASE_PATH=/shoppingcart
- OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317

payment-api:
Expand Down
2 changes: 1 addition & 1 deletion src/backend/docker/docker-compose.traefik.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:
cart-api:
labels:
- "traefik.enable=true"
- "traefik.http.routers.basket.rule=PathPrefix(`/basket/`)"
- "traefik.http.routers.basket.rule=PathPrefix(`/shoppingcart/`)"
- "traefik.port=5200"

order-api:
Expand Down
14 changes: 9 additions & 5 deletions src/backend/services/cart-api/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,16 @@ func main() {
basketRepository := repositories.NewCartRepository(redisClient)
cartHandler := handlers.NewCartHandler(basketRepository)

api := router.Group(basePath + "/api/v1/cart")
apiV1 := router.Group(basePath + "/api/v1")
{
api.POST("", handlers.ErrorHandler(cartHandler.Create))
api.GET(":id", handlers.ErrorHandler(cartHandler.Get))
api.DELETE(":id", handlers.ErrorHandler(cartHandler.Delete))
api.PUT(":id/items", handlers.ErrorHandler(cartHandler.UpdateItem)) // updates line item by CartID
cart := apiV1.Group("/cart")
{
cart.POST("", handlers.ErrorHandler(cartHandler.Create))
cart.GET(":id", handlers.ErrorHandler(cartHandler.Get))
cart.DELETE(":id", handlers.ErrorHandler(cartHandler.Delete))
cart.PUT(":id", handlers.ErrorHandler(cartHandler.Update))
cart.PUT(":id/item", handlers.ErrorHandler(cartHandler.UpdateItem)) // updates line item by CartID
}
}

// Home page should be redirected to swagger page
Expand Down
162 changes: 146 additions & 16 deletions src/backend/services/cart-api/internal/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/items": {
"/cart": {
"post": {
"description": "add by json new CustomerBasket",
"description": "add by json new Cart",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"CustomerBasket"
"Cart"
],
"summary": "Add a CustomerBasket",
"summary": "Creates new cart",
"parameters": [
{
"description": "Add CustomerBasket",
"name": "CustomerBasket",
"description": "Creates new cart",
"name": "cart",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.Cart"
"$ref": "#/definitions/models.CreateCartReq"
}
}
],
Expand Down Expand Up @@ -76,23 +76,23 @@ const docTemplate = `{
}
}
},
"/items/{id}": {
"/cart/{id}": {
"get": {
"description": "Get CustomerBasket by ID",
"description": "Get Cart by ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"CustomerBasket"
"Cart"
],
"summary": "Gets a CustomerBasket",
"summary": "Gets a Cart",
"parameters": [
{
"type": "string",
"description": "CustomerBasket ID",
"description": "Cart ID",
"name": "id",
"in": "path",
"required": true
Expand All @@ -119,22 +119,79 @@ const docTemplate = `{
}
}
},
"put": {
"description": "update by json cart",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Cart"
],
"summary": "Update cart",
"parameters": [
{
"type": "string",
"description": "Cart ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Updates cart",
"name": "update_cart",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.CreateCartReq"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Cart"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/models.HTTPError"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/models.HTTPError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/models.HTTPError"
}
}
}
},
"delete": {
"description": "Deletes CustomerBasket by ID",
"description": "Deletes Cart by ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"CustomerBasket"
"Cart"
],
"summary": "Deletes a CustomerBasket",
"summary": "Deletes a Cart",
"parameters": [
{
"type": "string",
"description": "CustomerBasket ID",
"description": "Cart ID",
"name": "id",
"in": "path",
"required": true
Expand Down Expand Up @@ -164,6 +221,65 @@ const docTemplate = `{
}
}
}
},
"/cart/{id}/item": {
"put": {
"description": "update by json new line item",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Cart"
],
"summary": "Update or add a line item",
"parameters": [
{
"type": "string",
"description": "Cart ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Update line item",
"name": "lineItem",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.LineItem"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Cart"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/models.HTTPError"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/models.HTTPError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/models.HTTPError"
}
}
}
}
}
},
"definitions": {
Expand Down Expand Up @@ -205,6 +321,20 @@ const docTemplate = `{
}
}
},
"models.CreateCartReq": {
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/models.LineItem"
}
},
"user_id": {
"type": "string"
}
}
},
"models.HTTPError": {
"type": "object",
"properties": {
Expand Down
Loading

0 comments on commit 54c4644

Please sign in to comment.