From 105d3b76e02ad7c7d7c613918613f9b7a9f7c936 Mon Sep 17 00:00:00 2001 From: shpali4 Date: Sun, 17 Sep 2023 18:27:40 +0400 Subject: [PATCH] IL-77 add OpenAPI for cart package --- pom.xml | 17 ++ .../cart/endpoint/CartEndpoint.java | 9 +- .../resources/api-specs/cart-openapi.yaml | 192 ++++++++++++++++++ 3 files changed, 214 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/api-specs/cart-openapi.yaml diff --git a/pom.xml b/pom.xml index a17c81f0..3a4b0326 100644 --- a/pom.xml +++ b/pom.xml @@ -353,6 +353,23 @@ + + generate-from-cart-openapi-spec + + generate + + + ${project.basedir}/src/main/resources/api-specs/cart-openapi.yaml + spring + com.zufar.onlinestore.openapi.cart.api + com.zufar.onlinestore.cart.dto + false + + true + true + + + diff --git a/src/main/java/com/zufar/onlinestore/cart/endpoint/CartEndpoint.java b/src/main/java/com/zufar/onlinestore/cart/endpoint/CartEndpoint.java index 9ce155ed..b0ba5bde 100644 --- a/src/main/java/com/zufar/onlinestore/cart/endpoint/CartEndpoint.java +++ b/src/main/java/com/zufar/onlinestore/cart/endpoint/CartEndpoint.java @@ -6,6 +6,7 @@ import com.zufar.onlinestore.cart.dto.NewShoppingSessionItemDto; import com.zufar.onlinestore.cart.dto.ShoppingSessionDto; import com.zufar.onlinestore.cart.dto.UpdateProductsQuantityInShoppingSessionItemRequest; +import com.zufar.onlinestore.openapi.cart.api.CartsApi; import com.zufar.onlinestore.user.entity.UserEntity; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -30,14 +31,14 @@ @RequiredArgsConstructor @Validated @RequestMapping(value = CartEndpoint.CART_URL) -public class CartEndpoint { +public class CartEndpoint implements CartsApi { public static final String CART_URL = "/api/v1/cart"; private final CartApi cartApi; @PostMapping(value = "/items") - public ResponseEntity addNewItemToShoppingSession(@RequestBody @Valid final AddNewItemsToShoppingSessionRequest request) { + public ResponseEntity addNewItemToShoppingSession(@RequestBody final AddNewItemsToShoppingSessionRequest request) { log.warn("Received the request to add a new items to the shoppingSession"); Set items = request.items(); ShoppingSessionDto shoppingSessionDto = cartApi.addItemsToShoppingSession(items); @@ -57,7 +58,7 @@ public ResponseEntity getShoppingSession(@AuthenticationPrin } @PatchMapping(value = "/items") - public ResponseEntity updateProductsQuantityInShoppingSessionItem(@RequestBody @Valid final UpdateProductsQuantityInShoppingSessionItemRequest request) { + public ResponseEntity updateProductsQuantityInShoppingSessionItem(@RequestBody final UpdateProductsQuantityInShoppingSessionItemRequest request) { UUID shoppingSessionItemId = request.shoppingSessionItemId(); Integer productsQuantityChange = request.productsQuantityChange(); log.warn("Received the request to update the productsQuantity with the change = {} in the shoppingSessionItem with id: {}.", @@ -69,7 +70,7 @@ public ResponseEntity updateProductsQuantityInShoppingSessio } @DeleteMapping(value = "/items") - public ResponseEntity deleteItemsFromShoppingSession(@RequestBody @Valid final DeleteItemsFromShoppingSessionRequest request) { + public ResponseEntity deleteItemsFromShoppingSession(@RequestBody final DeleteItemsFromShoppingSessionRequest request) { log.info("Received the request to delete the shopping session items with ids: {}.", request.shoppingSessionItemIds()); ShoppingSessionDto shoppingSessionDto = cartApi.deleteItemsFromShoppingSession(request); log.info("The shopping session items with ids = {} were deleted.", request.shoppingSessionItemIds()); diff --git a/src/main/resources/api-specs/cart-openapi.yaml b/src/main/resources/api-specs/cart-openapi.yaml new file mode 100644 index 00000000..d9088680 --- /dev/null +++ b/src/main/resources/api-specs/cart-openapi.yaml @@ -0,0 +1,192 @@ +openapi: "3.0.3" + +info: + title: "Online_Store API" + description: "Online_Store API for Cart package" + version: "1.0.0" + +servers: + - url: "http://localhost:8083" + +tags: + - name: "Carts" + description: "An API for managing and retrieving cart information" + +paths: + /api/v1/cart/items: + post: + tags: + - "Carts" + summary: "Add a list of new products to the cart" + operationId: "addNewItemToShoppingSession" + requestBody: + description: "Add a list of new products to the cart by productIds and productsQuantity" + content: + application/json: + schema: + $ref: "#/components/schemas/AddNewItemsToShoppingSessionRequest" + required: true + responses: + "200": + description: "OK" + content: + '*/*': + schema: + $ref: "#/components/schemas/ShoppingSessionDto" + + patch: + tags: + - "Carts" + summary: "Update the item in the cart" + operationId: "updateProductsQuantityInShoppingSessionItem" + requestBody: + description: "Change the quantity of the item in the cart by shoppingSessionItemId and productsQuantityChange (example: '1' will increase the value by one, '-1' will reduce by one)" + content: + application/json: + schema: + $ref: "#/components/schemas/UpdateProductsQuantityInShoppingSessionItemRequest" + required: true + responses: + "200": + description: "OK" + content: + '*/*': + schema: + $ref: "#/components/schemas/ShoppingSessionDto" + + delete: + tags: + - "Carts" + summary: "Delete list of items from the cart" + operationId: "deleteItemsFromShoppingSession" + requestBody: + description: "Delete list of items from the cart by list of shoppingSessionItemIds" + content: + application/json: + schema: + $ref: "#/components/schemas/DeleteItemsFromShoppingSessionRequest" + required: true + responses: + "200": + description: "OK" + content: + '*/*': + schema: + $ref: "#/components/schemas/ShoppingSessionDto" + + /api/v1/cart: + get: + tags: + - "Carts" + summary: "Get the cart of authorized user" + description: "Get the cart of authorized user" + operationId: "getShoppingSession" + responses: + "200": + description: "OK" + content: + '*/*': + schema: + $ref: "#/components/schemas/ShoppingSessionDto" + +components: + schemas: + NewShoppingSessionItemDto: + type: "object" + properties: + productId: + type: "string" + format: "uuid" + productsQuantity: + type: "integer" + format: "int32" + + AddNewItemsToShoppingSessionRequest: + type: "object" + properties: + items: + type: "array" + items: + $ref: "#/components/schemas/NewShoppingSessionItemDto" + + ShoppingSessionDto: + type: "object" + properties: + id: + type: "string" + format: "uuid" + userId: + type: "string" + format: "uuid" + items: + type: "array" + items: + $ref: "#/components/schemas/ShoppingSessionItemDto" + itemsQuantity: + type: "integer" + format: "int32" + itemsTotalPrice: + type: "number" + format: "decimal" + productsQuantity: + type: "integer" + format: "int32" + createdAt: + type: "string" + format: "date-time" + closedAt: + type: "string" + format: "date-time" + + ShoppingSessionItemDto: + type: "object" + properties: + id: + type: "string" + format: "uuid" + productInfo: + type: "array" + items: + $ref: "#/components/schemas/ProductInfoFullDto" + productsQuantity: + type: "integer" + format: "int32" + + ProductInfoFullDto: + type: "object" + properties: + id: + type: "string" + format: "uuid" + name: + type: "string" + description: + type: "string" + price: + type: "number" + format: "decimal" + quantity: + type: "integer" + format: "int32" + active: + type: "boolean" + format: "yes" + + UpdateProductsQuantityInShoppingSessionItemRequest: + type: "object" + properties: + shoppingSessionItemId: + type: "string" + format: "uuid" + productsQuantityChange: + type: "integer" + format: "int32" + + DeleteItemsFromShoppingSessionRequest: + type: "object" + properties: + shoppingSessionItemIds: + type: "array" + items: + type: "string" + format: "uuid" \ No newline at end of file