From 694f4763cc32eeae03b019ec63e0de0c72557a7a Mon Sep 17 00:00:00 2001 From: canyos <4581974@naver.com> Date: Fri, 15 Nov 2024 00:57:38 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EC=83=81=ED=92=88=EC=97=90=20?= =?UTF-8?q?=EC=BB=AC=EB=9F=BC=20=EC=B6=94=EA=B0=80,=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EC=97=94=EB=93=9C=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=88=98=EC=A0=95=20=EC=A3=BC=EB=AC=B8=ED=95=A0=20?= =?UTF-8?q?=EB=95=8C=20=EC=B5=9C=EB=8C=80=EA=B0=9C=EC=88=98=EB=B3=B4?= =?UTF-8?q?=EB=8B=A4=20=EC=A0=81=EC=9D=80=EC=A7=80=20=EC=B2=B4=ED=81=AC=20?= =?UTF-8?q?=EC=83=81=ED=92=88=20=EB=82=B4=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../deleteLinker/ProductDeleteLinker.java | 2 +- .../image/linker/ProductImageLinker.java | 2 +- .../order/service/ProductOrderService.java | 3 +++ .../_cart/controller/CartController.java | 2 +- .../dto/ProductListInCategoryResponse.java | 6 +++-- .../controller/ProductIntroController.java | 2 +- .../product/controller/ProductController.java | 2 +- .../controller/ProductFarmerController.java | 2 +- .../controller/ProductTagController.java | 6 +++-- .../product/dto/ProductRegisterRequest.java | 15 +++++------ .../domain/product/dto/ProductResponse.java | 11 +++++--- .../domain/product/entity/Product.java | 26 ++++++++++++++----- .../product/service/ProductFarmerService.java | 5 ---- .../controller/farm/FarmReviewController.java | 4 +-- .../store/controller/StoreController.java | 2 +- .../domain/wishlist/dto/WishListResponse.java | 6 +++-- 16 files changed, 58 insertions(+), 38 deletions(-) diff --git a/src/main/java/poomasi/domain/image/deleteLinker/ProductDeleteLinker.java b/src/main/java/poomasi/domain/image/deleteLinker/ProductDeleteLinker.java index c396cda2..bd259c1c 100644 --- a/src/main/java/poomasi/domain/image/deleteLinker/ProductDeleteLinker.java +++ b/src/main/java/poomasi/domain/image/deleteLinker/ProductDeleteLinker.java @@ -23,7 +23,7 @@ public boolean supports(ImageType type) { @Override public void handleImageDeletion(Image image) { Product product = productService.findProductById(image.getReferenceId()); - product.setImageUrl(null); + product.getImages().remove(image); productService.saveExistedProduct(product); } } diff --git a/src/main/java/poomasi/domain/image/linker/ProductImageLinker.java b/src/main/java/poomasi/domain/image/linker/ProductImageLinker.java index fc75dac6..9fd7dcd3 100644 --- a/src/main/java/poomasi/domain/image/linker/ProductImageLinker.java +++ b/src/main/java/poomasi/domain/image/linker/ProductImageLinker.java @@ -23,7 +23,7 @@ public boolean supports(ImageType type) { @Override public void link(Long referenceId, Image savedImage) { Product product = productService.findProductById(referenceId); - product.setImageUrl(savedImage.getImageUrl()); + product.getImages().add(savedImage); productService.saveExistedProduct(product); } } \ No newline at end of file diff --git a/src/main/java/poomasi/domain/order/service/ProductOrderService.java b/src/main/java/poomasi/domain/order/service/ProductOrderService.java index 101f8582..a43b4397 100644 --- a/src/main/java/poomasi/domain/order/service/ProductOrderService.java +++ b/src/main/java/poomasi/domain/order/service/ProductOrderService.java @@ -105,6 +105,9 @@ public PaymentPreRegisterRequest productPreOrderRegister(ProductOrderRegisterReq throw new BusinessException(PRODUCT_STOCK_ZERO); } + if(product.getOrderLimit() < quantityInCart) + throw new BusinessException(BusinessError.COUNT_LIMIT_EXCEEDED); + String productDescription = product.getDescription(); String productName = product.getName(); BigDecimal price = product.getPrice().multiply(BigDecimal.valueOf((long) quantityInCart)); diff --git a/src/main/java/poomasi/domain/product/_cart/controller/CartController.java b/src/main/java/poomasi/domain/product/_cart/controller/CartController.java index 1bb4edd1..dbd38361 100644 --- a/src/main/java/poomasi/domain/product/_cart/controller/CartController.java +++ b/src/main/java/poomasi/domain/product/_cart/controller/CartController.java @@ -20,7 +20,7 @@ @Controller @RequiredArgsConstructor -@RequestMapping("/api/cart") +@RequestMapping("/api/carts") public class CartController { private final CartService cartService; diff --git a/src/main/java/poomasi/domain/product/_category/dto/ProductListInCategoryResponse.java b/src/main/java/poomasi/domain/product/_category/dto/ProductListInCategoryResponse.java index edca351b..acdf22a4 100644 --- a/src/main/java/poomasi/domain/product/_category/dto/ProductListInCategoryResponse.java +++ b/src/main/java/poomasi/domain/product/_category/dto/ProductListInCategoryResponse.java @@ -1,7 +1,9 @@ package poomasi.domain.product._category.dto; import java.math.BigDecimal; +import java.util.List; import lombok.Builder; +import poomasi.domain.image.entity.Image; import poomasi.domain.product.entity.Product; @Builder @@ -9,7 +11,7 @@ public record ProductListInCategoryResponse( Long categoryId, String name, String description, - String imageUrl, + List images, Integer quantity, BigDecimal price ) { @@ -19,7 +21,7 @@ public static ProductListInCategoryResponse fromEntity(Product product) { .categoryId(product.getCategoryId()) .name(product.getName()) .description(product.getDescription()) - .imageUrl(product.getImageUrl()) + .images(product.getImages()) .quantity(product.getStock()) .price(product.getPrice()) .build(); diff --git a/src/main/java/poomasi/domain/product/_intro/controller/ProductIntroController.java b/src/main/java/poomasi/domain/product/_intro/controller/ProductIntroController.java index 8c24ccad..0189579c 100644 --- a/src/main/java/poomasi/domain/product/_intro/controller/ProductIntroController.java +++ b/src/main/java/poomasi/domain/product/_intro/controller/ProductIntroController.java @@ -18,7 +18,7 @@ @Controller @RequiredArgsConstructor -@RequestMapping("/api/product/{productId}/intro") +@RequestMapping("/api/products/{productId}/intro") public class ProductIntroController { private final ProductIntroService productIntroService; diff --git a/src/main/java/poomasi/domain/product/controller/ProductController.java b/src/main/java/poomasi/domain/product/controller/ProductController.java index 5d9b4444..720c594d 100644 --- a/src/main/java/poomasi/domain/product/controller/ProductController.java +++ b/src/main/java/poomasi/domain/product/controller/ProductController.java @@ -13,7 +13,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/product") +@RequestMapping("/api/products") public class ProductController { private final ProductService productService; diff --git a/src/main/java/poomasi/domain/product/controller/ProductFarmerController.java b/src/main/java/poomasi/domain/product/controller/ProductFarmerController.java index a86a28d1..e65de60f 100644 --- a/src/main/java/poomasi/domain/product/controller/ProductFarmerController.java +++ b/src/main/java/poomasi/domain/product/controller/ProductFarmerController.java @@ -22,7 +22,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/product") +@RequestMapping("/api/products") @Slf4j public class ProductFarmerController { diff --git a/src/main/java/poomasi/domain/product/controller/ProductTagController.java b/src/main/java/poomasi/domain/product/controller/ProductTagController.java index b49a0b59..536fb5b4 100644 --- a/src/main/java/poomasi/domain/product/controller/ProductTagController.java +++ b/src/main/java/poomasi/domain/product/controller/ProductTagController.java @@ -8,24 +8,26 @@ import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; import poomasi.domain.product.dto.ProductTagRequest; import poomasi.domain.product.service.ProductTagService; @Controller @RequiredArgsConstructor +@RequestMapping("/api/products") public class ProductTagController { private final ProductTagService productTagService; @Secured("ROLE_ADMIN") - @PostMapping("/api/products/tag") + @PostMapping("/tag") public ResponseEntity addTag(@RequestBody ProductTagRequest productTagRequest) { productTagService.addTag(productTagRequest); return new ResponseEntity<>(HttpStatus.CREATED); } @Secured("ROLE_ADMIN") - @DeleteMapping("/api/products/tag") + @DeleteMapping("/tag") public ResponseEntity deleteTag(@RequestBody ProductTagRequest productTagRequest) { productTagService.deleteTag(productTagRequest); return ResponseEntity.ok().build(); diff --git a/src/main/java/poomasi/domain/product/dto/ProductRegisterRequest.java b/src/main/java/poomasi/domain/product/dto/ProductRegisterRequest.java index a971474d..2db25a3b 100644 --- a/src/main/java/poomasi/domain/product/dto/ProductRegisterRequest.java +++ b/src/main/java/poomasi/domain/product/dto/ProductRegisterRequest.java @@ -23,38 +23,33 @@ public record ProductRegisterRequest( //product intro String mainTitle, - //Long mainImageId, String subTitle1, String subDesc1, - //Long subImage1Id, String subTitle2, String subDesc2, - //Long subImage2Id, String subTitle3, - String subDesc3 - //Long subImage3Id + String subDesc3, + + String oneLineDescription, + Integer orderLimit ) { public Product toEntity(Member member, Store store) { ProductIntro productIntro = ProductIntro.builder() .mainTitle(mainTitle) - //.mainImage(mainImage) .subTitle1(subTitle1) .subDesc1(subDesc1) - //.subImage1(subImage1) .subTitle2(subTitle2) .subDesc2(subDesc2) - //.subImage2(subImage2) .subTitle3(subTitle3) .subDesc3(subDesc3) - //.subImage3(subImage3) .build(); return Product.builder() @@ -70,6 +65,8 @@ public Product toEntity(Member member, Store store) { .growEnv(growEnv) .shippingFee(shippingFee) .productIntro(productIntro) + .oneLineDescription(oneLineDescription) + .orderLimit(orderLimit) .build(); } } diff --git a/src/main/java/poomasi/domain/product/dto/ProductResponse.java b/src/main/java/poomasi/domain/product/dto/ProductResponse.java index 49a4d81a..21e8fac1 100644 --- a/src/main/java/poomasi/domain/product/dto/ProductResponse.java +++ b/src/main/java/poomasi/domain/product/dto/ProductResponse.java @@ -3,6 +3,7 @@ import java.math.BigDecimal; import java.util.List; import lombok.Builder; +import poomasi.domain.image.entity.Image; import poomasi.domain.product._intro.dto.ProductIntroResponse; import poomasi.domain.product.entity.Product; import poomasi.domain.product.entity.ProductTagEnum; @@ -14,13 +15,15 @@ public record ProductResponse( BigDecimal price, Integer stock, String description, - String imageUrl, + List images, Long categoryId, String storeName, List tags, ProductIntroResponse productIntro, String growEnv, - BigDecimal shippingFee + BigDecimal shippingFee, + String oneLineDescription, + Integer orderLimit ) { public static ProductResponse fromEntity(Product product) { @@ -32,11 +35,13 @@ public static ProductResponse fromEntity(Product product) { .price(product.getPrice()) .stock(product.getStock()) .description(product.getDescription()) - .imageUrl(product.getImageUrl()) + .images(product.getImages()) .storeName(product.getStore().getName()) .categoryId(product.getCategoryId()) .growEnv(product.getGrowEnv()) .shippingFee(product.getShippingFee()) + .oneLineDescription(product.getOneLineDescription()) + .orderLimit(product.getOrderLimit()) .tags(tags) .productIntro(ProductIntroResponse.fromEntity(product.getProductIntro())) .build(); diff --git a/src/main/java/poomasi/domain/product/entity/Product.java b/src/main/java/poomasi/domain/product/entity/Product.java index fa5c1c2c..b6ea5f17 100644 --- a/src/main/java/poomasi/domain/product/entity/Product.java +++ b/src/main/java/poomasi/domain/product/entity/Product.java @@ -13,6 +13,7 @@ import org.hibernate.annotations.Comment; import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.UpdateTimestamp; +import poomasi.domain.image.entity.Image; import poomasi.domain.product._intro.entity.ProductIntro; import poomasi.domain.order.entity._product.OrderedProduct; import poomasi.domain.store.entity.Store; @@ -43,8 +44,9 @@ public class Product { private String description; @Setter - @Comment("이미지 URL") - private String imageUrl; + @Comment("이미지") + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) + private List images; @Comment("재고") private Integer stock; @@ -58,6 +60,12 @@ public class Product { @Comment("배송비") BigDecimal shippingFee; + @Comment("한줄 소개") + private String oneLineDescription; + + @Comment("인당 최대 개수 제한") + private Integer orderLimit; + @Comment("삭제 일시") private LocalDateTime deletedAt; @@ -69,7 +77,7 @@ public class Product { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "entityId") - List reviewList = new ArrayList<>(); + List reviewList; @ManyToOne @JoinColumn(name = "store_id") // 외래 키 컬럼 지정 @@ -111,30 +119,36 @@ public Product(Long productId, Store store, String growEnv, BigDecimal shippingFee, - ProductIntro productIntro) { + ProductIntro productIntro, + String oneLineDescription, + Integer orderLimit) { this.id = productId; this.categoryId = categoryId; this.farmerId = farmerId; this.name = name; this.description = description; - this.imageUrl = imageUrl; + this.images = new ArrayList<>(); this.stock = stock; this.price = price; this.store = store; this.productIntro = productIntro; this.growEnv = growEnv; this.shippingFee = shippingFee; + this.reviewList = new ArrayList<>(); + this.oneLineDescription = oneLineDescription; + this.orderLimit = orderLimit; } public Product modify(ProductRegisterRequest productRegisterRequest) { this.categoryId = productRegisterRequest.categoryId(); this.name = productRegisterRequest.name(); this.description = productRegisterRequest.description(); - this.imageUrl = productRegisterRequest.imageUrl(); this.stock = productRegisterRequest.stock(); this.price = productRegisterRequest.price(); this.growEnv = productRegisterRequest.growEnv(); this.shippingFee = productRegisterRequest.shippingFee(); + this.oneLineDescription = productRegisterRequest.oneLineDescription(); + this.orderLimit = productRegisterRequest.orderLimit(); return this; } diff --git a/src/main/java/poomasi/domain/product/service/ProductFarmerService.java b/src/main/java/poomasi/domain/product/service/ProductFarmerService.java index 7e71a72b..8f13a53e 100644 --- a/src/main/java/poomasi/domain/product/service/ProductFarmerService.java +++ b/src/main/java/poomasi/domain/product/service/ProductFarmerService.java @@ -35,11 +35,6 @@ public Long registerProduct(Member member, ProductRegisterRequest request) { Category category = getCategory(request.categoryId()); Store store = member.getStore(); -// Image introMainImage = getImage(request.mainImageId()); -// Image introSubImage1 = getImage(request.subImage1Id()); -// Image introSubImage2 = getImage(request.subImage2Id()); -// Image introSubImage3 = getImage(request.subImage3Id()); - Product saveProduct = productRepository.save(request.toEntity(member,store)); category.addProduct(saveProduct); diff --git a/src/main/java/poomasi/domain/review/controller/farm/FarmReviewController.java b/src/main/java/poomasi/domain/review/controller/farm/FarmReviewController.java index b100bf0b..a0b68265 100644 --- a/src/main/java/poomasi/domain/review/controller/farm/FarmReviewController.java +++ b/src/main/java/poomasi/domain/review/controller/farm/FarmReviewController.java @@ -22,13 +22,13 @@ public class FarmReviewController { private final FarmReviewService farmReviewService; - @GetMapping("/api/farm/{farmId}/reviews") + @GetMapping("/api/farms/{farmId}/reviews") public ResponseEntity getProductReviews(@PathVariable Long farmId) { List response = farmReviewService.getFarmReview(farmId); return new ResponseEntity<>(response, HttpStatus.OK); } - @PostMapping("/api/farm/{reservationId}/reviews") + @PostMapping("/api/farms/{reservationId}/reviews") public ResponseEntity registerProductReview( @AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable Long reservationId, diff --git a/src/main/java/poomasi/domain/store/controller/StoreController.java b/src/main/java/poomasi/domain/store/controller/StoreController.java index 3a5d46db..c6e2192f 100644 --- a/src/main/java/poomasi/domain/store/controller/StoreController.java +++ b/src/main/java/poomasi/domain/store/controller/StoreController.java @@ -12,7 +12,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/store") +@RequestMapping("/api/stores") public class StoreController { private final StoreService storeService; diff --git a/src/main/java/poomasi/domain/wishlist/dto/WishListResponse.java b/src/main/java/poomasi/domain/wishlist/dto/WishListResponse.java index fc7565d9..f6afb32b 100644 --- a/src/main/java/poomasi/domain/wishlist/dto/WishListResponse.java +++ b/src/main/java/poomasi/domain/wishlist/dto/WishListResponse.java @@ -1,13 +1,15 @@ package poomasi.domain.wishlist.dto; import java.math.BigDecimal; +import java.util.List; +import poomasi.domain.image.entity.Image; import poomasi.domain.wishlist.entity.WishList; public record WishListResponse( Long productId, String productName, BigDecimal price, - String imageUrl, + List images, String description ) { public static WishListResponse fromEntity(WishList wishList) { @@ -15,7 +17,7 @@ public static WishListResponse fromEntity(WishList wishList) { wishList.getProduct().getId(), wishList.getProduct().getName(), wishList.getProduct().getPrice(), - wishList.getProduct().getImageUrl(), + wishList.getProduct().getImages(), wishList.getProduct().getDescription() ); } From bf33da023700a642ccdc16bc3c0f75b4fe688fac Mon Sep 17 00:00:00 2001 From: canyos <4581974@naver.com> Date: Fri, 15 Nov 2024 00:57:56 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EB=B9=BC=EB=A8=B9=EC=9D=80?= =?UTF-8?q?=EA=B1=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/poomasi/global/error/BusinessError.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/poomasi/global/error/BusinessError.java b/src/main/java/poomasi/global/error/BusinessError.java index 5097ef70..b007e45a 100644 --- a/src/main/java/poomasi/global/error/BusinessError.java +++ b/src/main/java/poomasi/global/error/BusinessError.java @@ -96,6 +96,7 @@ public enum BusinessError { ORDER_PRODUCT_DETAILS_NOT_FOUND(HttpStatus.NOT_FOUND, "주문을 찾을 수 없습니다."), ORDER_PRODUCT_DETAILS_NOT_OWNED_EXCEPTION(HttpStatus.UNAUTHORIZED, "허가되지 않은 주문입니다."), ORDERED_PRODUCT_NOT_FOUND(HttpStatus.NOT_FOUND, "찾을 수 없는 주문입니다."), + COUNT_LIMIT_EXCEEDED(HttpStatus.BAD_REQUEST, "주문 가능 최대 개수 보다 많이 요청했습니다."), //Store STORE_NOT_FOUND(HttpStatus.NOT_FOUND, "등록된 상점이 없습니다."),