-
-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature/IL-77/Add-OpenAPI-for-cart-package #100
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to @OverRide the method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are overrided automaticly, isn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using this annotation is like a best practice |
||
public ResponseEntity<ShoppingSessionDto> addNewItemToShoppingSession(@RequestBody @Valid final AddNewItemsToShoppingSessionRequest request) { | ||
public ResponseEntity<ShoppingSessionDto> addNewItemToShoppingSession(@RequestBody final AddNewItemsToShoppingSessionRequest request) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you delete ‘@Valid'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this annotation we have a trouble in case when we try to use our API not in IDE (i use Postman): Hibernate validator HV000151 "A method overriding another method must not alter the parameter constraint configuration"). |
||
log.warn("Received the request to add a new items to the shoppingSession"); | ||
Set<NewShoppingSessionItemDto> items = request.items(); | ||
ShoppingSessionDto shoppingSessionDto = cartApi.addItemsToShoppingSession(items); | ||
|
@@ -57,7 +58,7 @@ public ResponseEntity<ShoppingSessionDto> getShoppingSession(@AuthenticationPrin | |
} | ||
|
||
@PatchMapping(value = "/items") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to @OverRide the method |
||
public ResponseEntity<ShoppingSessionDto> updateProductsQuantityInShoppingSessionItem(@RequestBody @Valid final UpdateProductsQuantityInShoppingSessionItemRequest request) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rollback ‘@Valid' annotation, please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
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: {}.", | ||
|
@@ -69,7 +70,7 @@ public ResponseEntity<ShoppingSessionDto> updateProductsQuantityInShoppingSessio | |
} | ||
|
||
@DeleteMapping(value = "/items") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to @OverRide the method |
||
public ResponseEntity<ShoppingSessionDto> deleteItemsFromShoppingSession(@RequestBody @Valid final DeleteItemsFromShoppingSessionRequest request) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rollback ‘@Valid' annotation, please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
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()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
openapi: "3.0.3" | ||
|
||
info: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to write in a common style as in Zufar's example in product-openapi.yaml info: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
title: "Online_Store API" | ||
description: "Online_Store API for Cart package" | ||
version: "1.0.0" | ||
|
||
servers: | ||
- url: "http://localhost:8083" | ||
|
||
tags: | ||
- name: "Carts" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cart is better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to write path as in a common style |
||
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CartApi sounds better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are already have CartApi in this class (import com.zufar.onlinestore.cart.api.CartApi). Is it ok to use same names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is no problem