Skip to content

Commit

Permalink
Merge pull request #100 from Sunagatov/feature/IL-77/Add-OpenAPI-for-…
Browse files Browse the repository at this point in the history
…cart-package

feature/IL-77/Add-OpenAPI-for-cart-package
  • Loading branch information
Sunagatov authored Sep 17, 2023
2 parents 97180fb + 105d3b7 commit 1e6c954
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 4 deletions.
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,23 @@
</configOptions>
</configuration>
</execution>
<execution>
<id>generate-from-cart-openapi-spec</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api-specs/cart-openapi.yaml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.zufar.onlinestore.openapi.cart.api</apiPackage>
<modelPackage>com.zufar.onlinestore.cart.dto</modelPackage>
<generateModels>false</generateModels>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<useTags>true</useTags>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ShoppingSessionDto> addNewItemToShoppingSession(@RequestBody @Valid final AddNewItemsToShoppingSessionRequest request) {
public ResponseEntity<ShoppingSessionDto> addNewItemToShoppingSession(@RequestBody final AddNewItemsToShoppingSessionRequest request) {
log.warn("Received the request to add a new items to the shoppingSession");
Set<NewShoppingSessionItemDto> items = request.items();
ShoppingSessionDto shoppingSessionDto = cartApi.addItemsToShoppingSession(items);
Expand All @@ -57,7 +58,7 @@ public ResponseEntity<ShoppingSessionDto> getShoppingSession(@AuthenticationPrin
}

@PatchMapping(value = "/items")
public ResponseEntity<ShoppingSessionDto> updateProductsQuantityInShoppingSessionItem(@RequestBody @Valid final UpdateProductsQuantityInShoppingSessionItemRequest request) {
public ResponseEntity<ShoppingSessionDto> 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: {}.",
Expand All @@ -69,7 +70,7 @@ public ResponseEntity<ShoppingSessionDto> updateProductsQuantityInShoppingSessio
}

@DeleteMapping(value = "/items")
public ResponseEntity<ShoppingSessionDto> deleteItemsFromShoppingSession(@RequestBody @Valid final DeleteItemsFromShoppingSessionRequest request) {
public ResponseEntity<ShoppingSessionDto> 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());
Expand Down
192 changes: 192 additions & 0 deletions src/main/resources/api-specs/cart-openapi.yaml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 1e6c954

Please sign in to comment.