From 7757e97a8dcfe8a041063422c5e01540d00d12b5 Mon Sep 17 00:00:00 2001 From: moonyaeyoon Date: Fri, 26 Jul 2024 16:07:45 +0900 Subject: [PATCH 1/7] =?UTF-8?q?fix=20:=20=EC=B0=9C=ED=95=9C=20=EC=83=81?= =?UTF-8?q?=ED=92=88=20=EB=8D=94=EB=B3=B4=EA=B8=B0=EC=97=90=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/accounts/controller/BuyerController.java | 13 ++++++++----- .../domain/accounts/service/BuyerQueryService.java | 8 +++++--- .../repository/FavoriteProductRepository.java | 11 +++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/umc/unimade/domain/accounts/controller/BuyerController.java b/src/main/java/umc/unimade/domain/accounts/controller/BuyerController.java index 0544664..4bce1f2 100644 --- a/src/main/java/umc/unimade/domain/accounts/controller/BuyerController.java +++ b/src/main/java/umc/unimade/domain/accounts/controller/BuyerController.java @@ -5,9 +5,11 @@ import lombok.*; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import umc.unimade.domain.accounts.dto.BuyerOrderHistoryResponse; import umc.unimade.domain.accounts.dto.BuyerPageResponse; +import umc.unimade.domain.accounts.entity.Buyer; import umc.unimade.domain.accounts.service.BuyerCommandService; import umc.unimade.domain.accounts.service.BuyerQueryService; import umc.unimade.domain.favorite.dto.FavoriteProductsListResponse; @@ -71,12 +73,13 @@ public ResponseEntity> getOrderHistory( @Tag(name = "FavoriteProduct") @Operation(summary = "찜한 상품 더보기") - @GetMapping("/{buyerId}/favorite-products") - public ResponseEntity> getFavoriteProductsList(@PathVariable Long buyerId, - @RequestParam(required = false) Long cursor, - @RequestParam int pageSize) { + @GetMapping("/favorite-products") + public ResponseEntity> getFavoriteProductsList(@RequestParam(required = false) Long cursor, + @RequestParam int pageSize, + @AuthenticationPrincipal Buyer currentBuyer + ) { try { - return ResponseEntity.ok(ApiResponse.onSuccess(buyerQueryService.getFavoriteProdutsList(buyerId, cursor, pageSize))); + return ResponseEntity.ok(ApiResponse.onSuccess(buyerQueryService.getFavoriteProdutsList(currentBuyer, cursor, pageSize))); } catch (IllegalArgumentException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.onFailure(HttpStatus.BAD_REQUEST.name(), e.getMessage())); } catch (UserExceptionHandler e) { diff --git a/src/main/java/umc/unimade/domain/accounts/service/BuyerQueryService.java b/src/main/java/umc/unimade/domain/accounts/service/BuyerQueryService.java index 4af46f4..bb4c717 100644 --- a/src/main/java/umc/unimade/domain/accounts/service/BuyerQueryService.java +++ b/src/main/java/umc/unimade/domain/accounts/service/BuyerQueryService.java @@ -57,15 +57,17 @@ public BuyerOrderHistoryResponse getOrderHistory(Long buyerId, Long cursor, Inte } // 찜한 상품 더보기 - public FavoriteProductsListResponse getFavoriteProdutsList(Long buyerId,Long cursor, int pageSize){ + public FavoriteProductsListResponse getFavoriteProdutsList(Buyer currentBuyer,Long cursor, int pageSize){ + Buyer buyer = findBuyerById(currentBuyer.getId()); + Pageable pageable = PageRequest.of(0, pageSize, Sort.by(Sort.Direction.DESC, "createdAt")); List favoriteProducts; if (cursor == null) { - favoriteProducts = favoriteProductRepository.findByBuyerIdOrderByCreatedAtDesc(buyerId, pageable); + favoriteProducts = favoriteProductRepository.findByBuyerOrderByCreatedAtDesc(buyer, pageable); } else { - favoriteProducts = favoriteProductRepository.findByBuyerIdAndIdLessThanOrderByCreatedAtDesc(buyerId, cursor, pageable); + favoriteProducts = favoriteProductRepository.findByBuyerAndIdLessThanOrderByCreatedAtDesc(buyer, cursor, pageable); } Long nextCursor = favoriteProducts.isEmpty() ? null : favoriteProducts.get(favoriteProducts.size() - 1).getId(); diff --git a/src/main/java/umc/unimade/domain/favorite/repository/FavoriteProductRepository.java b/src/main/java/umc/unimade/domain/favorite/repository/FavoriteProductRepository.java index 81ab6d3..d0fc232 100644 --- a/src/main/java/umc/unimade/domain/favorite/repository/FavoriteProductRepository.java +++ b/src/main/java/umc/unimade/domain/favorite/repository/FavoriteProductRepository.java @@ -3,6 +3,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; import umc.unimade.domain.accounts.entity.Buyer; import umc.unimade.domain.favorite.entity.FavoriteProduct; import umc.unimade.domain.products.entity.Products; @@ -10,14 +11,16 @@ import java.util.List; import java.util.Optional; +@Repository public interface FavoriteProductRepository extends JpaRepository { + Optional findByProductAndBuyer(Products product, Buyer buyer); List findTop4ByBuyerOrderByCreatedAtDesc(Buyer buyer); - @Query("SELECT fp FROM FavoriteProduct fp WHERE fp.buyer.id = :buyerId ORDER BY fp.createdAt DESC") - List findByBuyerIdOrderByCreatedAtDesc(Long buyerId, Pageable pageable); + @Query("SELECT fp FROM FavoriteProduct fp WHERE fp.buyer = :buyer ORDER BY fp.createdAt DESC") + List findByBuyerOrderByCreatedAtDesc(Buyer buyer, Pageable pageable); - @Query("SELECT fp FROM FavoriteProduct fp WHERE fp.buyer.id = :buyerId AND fp.id < :cursor ORDER BY fp.createdAt DESC") - List findByBuyerIdAndIdLessThanOrderByCreatedAtDesc(Long buyerId, Long cursor, Pageable pageable); + @Query("SELECT fp FROM FavoriteProduct fp WHERE fp.buyer = :buyer AND fp.id < :cursor ORDER BY fp.createdAt DESC") + List findByBuyerAndIdLessThanOrderByCreatedAtDesc(Buyer buyer, Long cursor, Pageable pageable); } From 82abc1c4716d10189772186cd36b434bb02ce8e7 Mon Sep 17 00:00:00 2001 From: moonyaeyoon Date: Fri, 26 Jul 2024 19:48:25 +0900 Subject: [PATCH 2/7] =?UTF-8?q?=20fix=20:=20optionValues=20=EB=B0=98?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/products/dto/OptionResponse.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/umc/unimade/domain/products/dto/OptionResponse.java b/src/main/java/umc/unimade/domain/products/dto/OptionResponse.java index 8f7eaec..8069295 100644 --- a/src/main/java/umc/unimade/domain/products/dto/OptionResponse.java +++ b/src/main/java/umc/unimade/domain/products/dto/OptionResponse.java @@ -1,6 +1,11 @@ package umc.unimade.domain.products.dto; + import lombok.*; import umc.unimade.domain.products.entity.OptionCategory; +import umc.unimade.domain.products.entity.OptionValue; + +import java.util.List; +import java.util.stream.Collectors; @Getter @AllArgsConstructor @@ -9,12 +14,17 @@ public class OptionResponse { private Long optionId; private String name; + private List values; + public static OptionResponse from(OptionCategory category) { + List values = category.getValues().stream() + .map(OptionValue::getValue) + .collect(Collectors.toList()); - public static OptionResponse from(OptionCategory option){ return OptionResponse.builder() - .optionId(option.getId()) - .name(option.getName()) + .optionId(category.getId()) + .name(category.getName()) + .values(values) .build(); } } From 2f40f25c07340d0e63b792c340cfe8bf122c908d Mon Sep 17 00:00:00 2001 From: moonyaeyoon Date: Fri, 26 Jul 2024 19:53:25 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=20fix=20:=20=EA=B5=AC=EB=A7=A4=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EB=B0=9B=EC=95=84=EC=98=A4=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/accounts/controller/BuyerController.java | 12 ++++++------ .../domain/accounts/service/BuyerQueryService.java | 4 ++-- .../domain/orders/repository/OrderRepository.java | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/umc/unimade/domain/accounts/controller/BuyerController.java b/src/main/java/umc/unimade/domain/accounts/controller/BuyerController.java index 4bce1f2..3de0dfa 100644 --- a/src/main/java/umc/unimade/domain/accounts/controller/BuyerController.java +++ b/src/main/java/umc/unimade/domain/accounts/controller/BuyerController.java @@ -57,13 +57,13 @@ public ResponseEntity> getBuyerPage(@PathVariable } @Tag(name = "Buyer", description = "구매자 관련 API") @Operation(summary = "구매 내역 리스트") - @GetMapping("/history/{buyerId}") + @GetMapping("/history") public ResponseEntity> getOrderHistory( - @RequestParam Long buyerId, + @AuthenticationPrincipal Buyer currentBuyer, @RequestParam(required = false) Long cursor, @RequestParam int pageSize) { try { - return ResponseEntity.ok(ApiResponse.onSuccess(buyerQueryService.getOrderHistory(buyerId, cursor, pageSize))); + return ResponseEntity.ok(ApiResponse.onSuccess(buyerQueryService.getOrderHistory(currentBuyer, cursor, pageSize))); } catch (IllegalArgumentException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.onFailure(HttpStatus.BAD_REQUEST.name(), e.getMessage())); } catch (UserExceptionHandler e) { @@ -74,9 +74,9 @@ public ResponseEntity> getOrderHistory( @Tag(name = "FavoriteProduct") @Operation(summary = "찜한 상품 더보기") @GetMapping("/favorite-products") - public ResponseEntity> getFavoriteProductsList(@RequestParam(required = false) Long cursor, - @RequestParam int pageSize, - @AuthenticationPrincipal Buyer currentBuyer + public ResponseEntity> getFavoriteProductsList(@AuthenticationPrincipal Buyer currentBuyer, + @RequestParam(required = false) Long cursor, + @RequestParam int pageSize ) { try { return ResponseEntity.ok(ApiResponse.onSuccess(buyerQueryService.getFavoriteProdutsList(currentBuyer, cursor, pageSize))); diff --git a/src/main/java/umc/unimade/domain/accounts/service/BuyerQueryService.java b/src/main/java/umc/unimade/domain/accounts/service/BuyerQueryService.java index bb4c717..019a2de 100644 --- a/src/main/java/umc/unimade/domain/accounts/service/BuyerQueryService.java +++ b/src/main/java/umc/unimade/domain/accounts/service/BuyerQueryService.java @@ -47,9 +47,9 @@ public BuyerPageResponse getBuyerPage(Long buyerId){ } // 구매 내역 - public BuyerOrderHistoryResponse getOrderHistory(Long buyerId, Long cursor, Integer pageSize){ + public BuyerOrderHistoryResponse getOrderHistory(Buyer buyer, Long cursor, Integer pageSize){ Pageable pageable = PageRequest.of(0, pageSize); - List orders = orderRepository.findOrdersByBuyerIdWithCursorPagination(buyerId, cursor, pageable); + List orders = orderRepository.findOrdersByBuyerWithCursorPagination(buyer, cursor, pageable); Long nextCursor = orders.isEmpty() ? null : orders.get(orders.size() - 1).getId(); boolean isLast = orders.size() < pageSize; diff --git a/src/main/java/umc/unimade/domain/orders/repository/OrderRepository.java b/src/main/java/umc/unimade/domain/orders/repository/OrderRepository.java index ec73824..bec709f 100644 --- a/src/main/java/umc/unimade/domain/orders/repository/OrderRepository.java +++ b/src/main/java/umc/unimade/domain/orders/repository/OrderRepository.java @@ -4,6 +4,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import umc.unimade.domain.accounts.entity.Buyer; import umc.unimade.domain.orders.entity.OrderStatus; import umc.unimade.domain.orders.entity.Orders; @@ -18,8 +19,8 @@ public interface OrderRepository extends JpaRepository { @Query("SELECT o FROM Orders o WHERE o.product.id = :productId") List findOrdersByProductId(Long productId, Pageable pageable); - @Query("SELECT o FROM Orders o WHERE o.buyer.id = :buyerId AND (:cursor IS NULL OR o.id < :cursor) ORDER BY o.id DESC") - List findOrdersByBuyerIdWithCursorPagination(@Param("buyerId") Long buyerId, @Param("cursor") Long cursor, Pageable pageable); + @Query("SELECT o FROM Orders o WHERE o.buyer = :buyer AND (:cursor IS NULL OR o.id < :cursor) ORDER BY o.id DESC") + List findOrdersByBuyerWithCursorPagination(Buyer buyer, @Param("cursor") Long cursor, Pageable pageable); @Query("SELECT o FROM Orders o WHERE o.purchaseForm.createdAt < :threeDaysAgo AND o.status = :status") List findOrdersCreatedBefore(LocalDateTime threeDaysAgo, OrderStatus status); From 48e64c73c435ad7c86f29e115235f3e21bc6d24e Mon Sep 17 00:00:00 2001 From: moonyaeyoon Date: Fri, 26 Jul 2024 19:59:59 +0900 Subject: [PATCH 4/7] =?UTF-8?q?fix=20:=20BuyerController=EC=97=90=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accounts/controller/BuyerController.java | 18 +++++++++--------- .../accounts/service/BuyerCommandService.java | 5 +++-- .../accounts/service/BuyerQueryService.java | 9 ++++----- .../repository/FavoriteSellerRepository.java | 8 ++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/umc/unimade/domain/accounts/controller/BuyerController.java b/src/main/java/umc/unimade/domain/accounts/controller/BuyerController.java index 3de0dfa..d6ed470 100644 --- a/src/main/java/umc/unimade/domain/accounts/controller/BuyerController.java +++ b/src/main/java/umc/unimade/domain/accounts/controller/BuyerController.java @@ -32,10 +32,10 @@ public class BuyerController { @Tag(name = "FavoriteSeller") @Operation(summary = "찜하지 않은 상태라면 찜하기. \n 찜한 상태라면 찜하기 취소") - @PostMapping("/favorite/{sellerId}/{buyerId}") - public ResponseEntity> toggleFavoriteSeller(@PathVariable Long sellerId, @PathVariable Long buyerId) { + @PostMapping("/favorite/{sellerId}") + public ResponseEntity> toggleFavoriteSeller(@AuthenticationPrincipal Buyer currentBuyer,@PathVariable Long sellerId) { try { - return ResponseEntity.ok(buyerCommandService.toggleFavoriteSeller(sellerId, buyerId)); + return ResponseEntity.ok(buyerCommandService.toggleFavoriteSeller(sellerId, currentBuyer)); } catch (IllegalArgumentException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.onFailure(HttpStatus.BAD_REQUEST.name(), e.getMessage())); } catch (UserExceptionHandler e) { @@ -45,10 +45,10 @@ public ResponseEntity> toggleFavoriteSeller(@PathVariable Long @Tag(name = "Buyer", description = "구매자 관련 API") @Operation(summary = "구매자 마이페이지에서 찜한 상품과 메이더를 보여준다.") - @GetMapping("/myPage/{buyerId}") - public ResponseEntity> getBuyerPage(@PathVariable Long buyerId) { + @GetMapping("/myPage") + public ResponseEntity> getBuyerPage(@AuthenticationPrincipal Buyer currentBuyer) { try { - return ResponseEntity.ok(ApiResponse.onSuccess(buyerQueryService.getBuyerPage(buyerId))); + return ResponseEntity.ok(ApiResponse.onSuccess(buyerQueryService.getBuyerPage(currentBuyer))); } catch (IllegalArgumentException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.onFailure(HttpStatus.BAD_REQUEST.name(), e.getMessage())); } catch (UserExceptionHandler e) { @@ -89,12 +89,12 @@ public ResponseEntity> getFavoriteProd @Tag(name = "FavoriteSeller") @Operation(summary = "찜한 메이더 더보기") - @GetMapping("/{buyerId}/favorite-sellers") - public ResponseEntity> getFavoriteSellersList(@PathVariable Long buyerId, + @GetMapping("/favorite-sellers") + public ResponseEntity> getFavoriteSellersList(@AuthenticationPrincipal Buyer currentBuyer, @RequestParam(required = false) Long cursor, @RequestParam int pageSize) { try { - return ResponseEntity.ok(ApiResponse.onSuccess(buyerQueryService.getFavoriteSellersList(buyerId, cursor, pageSize))); + return ResponseEntity.ok(ApiResponse.onSuccess(buyerQueryService.getFavoriteSellersList(currentBuyer, cursor, pageSize))); } catch (IllegalArgumentException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.onFailure(HttpStatus.BAD_REQUEST.name(), e.getMessage())); } catch (UserExceptionHandler e) { diff --git a/src/main/java/umc/unimade/domain/accounts/service/BuyerCommandService.java b/src/main/java/umc/unimade/domain/accounts/service/BuyerCommandService.java index 4fcd289..a94d505 100644 --- a/src/main/java/umc/unimade/domain/accounts/service/BuyerCommandService.java +++ b/src/main/java/umc/unimade/domain/accounts/service/BuyerCommandService.java @@ -15,6 +15,8 @@ import java.util.Optional; +import static umc.unimade.domain.accounts.entity.QBuyer.buyer; + @Service @RequiredArgsConstructor public class BuyerCommandService { @@ -24,9 +26,8 @@ public class BuyerCommandService { private final FavoriteSellerRepository favoriteSellerRepository; @Transactional - public ApiResponse toggleFavoriteSeller(Long sellerId,Long buyerId){ + public ApiResponse toggleFavoriteSeller(Long sellerId, Buyer buyer){ Seller seller = findSellerById(sellerId); - Buyer buyer = findBuyerById(buyerId); Optional existingFavorite = findFavoriteSeller(seller,buyer); if(existingFavorite.isPresent()){ diff --git a/src/main/java/umc/unimade/domain/accounts/service/BuyerQueryService.java b/src/main/java/umc/unimade/domain/accounts/service/BuyerQueryService.java index 019a2de..e35febe 100644 --- a/src/main/java/umc/unimade/domain/accounts/service/BuyerQueryService.java +++ b/src/main/java/umc/unimade/domain/accounts/service/BuyerQueryService.java @@ -35,8 +35,7 @@ public class BuyerQueryService { private final OrderRepository orderRepository; // 구매자 마이페이지 - public BuyerPageResponse getBuyerPage(Long buyerId){ - Buyer buyer = findBuyerById(buyerId); + public BuyerPageResponse getBuyerPage(Buyer buyer){ List favoriteProducts = favoriteProductRepository.findTop4ByBuyerOrderByCreatedAtDesc(buyer).stream() .map(FavoriteProductResponse::from) .collect(Collectors.toList()); @@ -77,13 +76,13 @@ public FavoriteProductsListResponse getFavoriteProdutsList(Buyer currentBuyer,Lo } // 찜한 메이더 더보기 - public FavoriteSellersListResponse getFavoriteSellersList(Long buyerId, Long cursor, int pageSize){ + public FavoriteSellersListResponse getFavoriteSellersList(Buyer buyer, Long cursor, int pageSize){ Pageable pageable = PageRequest.of(0, pageSize, Sort.by(Sort.Direction.DESC, "createdAt")); List favoriteSellers; if (cursor == null){ - favoriteSellers = favoriteSellerRepository.findByBuyerIdOrderByCreatedAtDesc(buyerId, pageable); + favoriteSellers = favoriteSellerRepository.findByBuyerOrderByCreatedAtDesc(buyer, pageable); }else { - favoriteSellers = favoriteSellerRepository.findByBuyerIdAndIdLessThanOrderByCreatedAtDesc(buyerId, cursor, pageable); + favoriteSellers = favoriteSellerRepository.findByBuyerAndIdLessThanOrderByCreatedAtDesc(buyer, cursor, pageable); } Long nextCursor = favoriteSellers.isEmpty() ? null : favoriteSellers.get(favoriteSellers.size() - 1).getId(); Boolean isLast = favoriteSellers.size() < pageSize; diff --git a/src/main/java/umc/unimade/domain/favorite/repository/FavoriteSellerRepository.java b/src/main/java/umc/unimade/domain/favorite/repository/FavoriteSellerRepository.java index 57dce22..f201b46 100644 --- a/src/main/java/umc/unimade/domain/favorite/repository/FavoriteSellerRepository.java +++ b/src/main/java/umc/unimade/domain/favorite/repository/FavoriteSellerRepository.java @@ -17,9 +17,9 @@ public interface FavoriteSellerRepository extends JpaRepository findTop4ByBuyerOrderByCreatedAtDesc(Buyer buyer); - @Query("SELECT fs FROM FavoriteSeller fs WHERE fs.buyer.id = :buyerId ORDER BY fs.createdAt DESC") - List findByBuyerIdOrderByCreatedAtDesc(Long buyerId, Pageable pageable); + @Query("SELECT fs FROM FavoriteSeller fs WHERE fs.buyer = :buyer ORDER BY fs.createdAt DESC") + List findByBuyerOrderByCreatedAtDesc(Buyer buyer, Pageable pageable); - @Query("SELECT fs FROM FavoriteSeller fs WHERE fs.buyer.id = :buyerId AND fs.id < :cursor ORDER BY fs.createdAt DESC") - List findByBuyerIdAndIdLessThanOrderByCreatedAtDesc(Long buyerId, Long cursor, Pageable pageable); + @Query("SELECT fs FROM FavoriteSeller fs WHERE fs.buyer = :buyer AND fs.id < :cursor ORDER BY fs.createdAt DESC") + List findByBuyerAndIdLessThanOrderByCreatedAtDesc(Buyer buyer, Long cursor, Pageable pageable); } From e635af269f27ca5a947e23ed3481c0063078fa52 Mon Sep 17 00:00:00 2001 From: moonyaeyoon Date: Fri, 26 Jul 2024 20:02:58 +0900 Subject: [PATCH 5/7] =?UTF-8?q?fix=20:=20OrderController=EC=97=90=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unimade/domain/orders/controller/OrderController.java | 8 +++++--- .../domain/orders/service/OrderCommandService.java | 4 +--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/umc/unimade/domain/orders/controller/OrderController.java b/src/main/java/umc/unimade/domain/orders/controller/OrderController.java index 8127ad9..96373cd 100644 --- a/src/main/java/umc/unimade/domain/orders/controller/OrderController.java +++ b/src/main/java/umc/unimade/domain/orders/controller/OrderController.java @@ -6,7 +6,9 @@ import org.springframework.data.domain.PageRequest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import umc.unimade.domain.accounts.entity.Buyer; import umc.unimade.domain.accounts.entity.Seller; import umc.unimade.domain.orders.dto.*; import umc.unimade.domain.accounts.exception.UserExceptionHandler; @@ -34,10 +36,10 @@ public class OrderController { @Tag(name = "Order", description = "구매 관련 API") @Operation(summary = "상품 구매하기") - @PostMapping("/{productId}/{buyerId}") - public ResponseEntity> createOrder (@PathVariable Long productId, @PathVariable Long buyerId, @RequestBody OrderRequest orderRequest){ + @PostMapping("/{productId}") + public ResponseEntity> createOrder (@AuthenticationPrincipal Buyer currentBuyer, @PathVariable Long productId, @RequestBody OrderRequest orderRequest){ try { - return ResponseEntity.ok(ApiResponse.onSuccess(orderCommandService.createOrder(productId, buyerId, orderRequest))); + return ResponseEntity.ok(ApiResponse.onSuccess(orderCommandService.createOrder(productId, currentBuyer, orderRequest))); } catch (IllegalArgumentException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.onFailure(HttpStatus.BAD_REQUEST.name(), e.getMessage())); diff --git a/src/main/java/umc/unimade/domain/orders/service/OrderCommandService.java b/src/main/java/umc/unimade/domain/orders/service/OrderCommandService.java index 082b544..b197a19 100644 --- a/src/main/java/umc/unimade/domain/orders/service/OrderCommandService.java +++ b/src/main/java/umc/unimade/domain/orders/service/OrderCommandService.java @@ -35,12 +35,10 @@ public class OrderCommandService { private final OrderItemRepository orderItemRepository; @Transactional - public OrderResponse createOrder(Long productId, Long buyerId, OrderRequest orderRequest) { + public OrderResponse createOrder(Long productId, Buyer buyer, OrderRequest orderRequest) { if (!orderRequest.getPurchaseForm().getIsAgree()) { throw new OrderExceptionHandler(ErrorCode.ORDER_AGREEMENT_REQUIRED); } - - Buyer buyer = findBuyerById(buyerId); Products product = findProductById(productId); // PurchaseForm 엔티티 생성 및 저장 From 923636060e9fee6427766477380a4845b78d83f3 Mon Sep 17 00:00:00 2001 From: moonyaeyoon Date: Fri, 26 Jul 2024 20:07:32 +0900 Subject: [PATCH 6/7] =?UTF-8?q?fix=20:=20ProductsController=EC=97=90=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../products/controller/ProductsController.java | 17 +++++++++-------- .../service/ProductsCommandService.java | 3 +-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/umc/unimade/domain/products/controller/ProductsController.java b/src/main/java/umc/unimade/domain/products/controller/ProductsController.java index 392bf88..2347d89 100644 --- a/src/main/java/umc/unimade/domain/products/controller/ProductsController.java +++ b/src/main/java/umc/unimade/domain/products/controller/ProductsController.java @@ -6,9 +6,11 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import lombok.*; import org.springframework.web.multipart.MultipartFile; +import umc.unimade.domain.accounts.entity.Buyer; import umc.unimade.domain.products.dto.ProductRegisterResponse; import umc.unimade.domain.products.dto.ProductRequest.UpdateProductDto; import umc.unimade.domain.products.dto.ProductResponse; @@ -36,10 +38,10 @@ public class ProductsController extends BaseEntity { @Tag(name = "Products", description = "판매 상품 관련 API") @Operation(summary = "판매 상품 정보 가져오기") @GetMapping("/{productId}") - //To do : 토큰 구현 시 user 정보 추가 - public ResponseEntity> getProductDetails - (@PathVariable Long productId , @RequestParam ViewType viewType, @RequestParam(required = false) Long cursor, - @RequestParam(defaultValue = "10") int pageSize) { + public ResponseEntity> getProductDetails (@PathVariable Long productId , + @RequestParam ViewType viewType, + @RequestParam(required = false) Long cursor, + @RequestParam(defaultValue = "10") int pageSize) { try { return ResponseEntity.ok(ApiResponse.onSuccess(productsQueryService.getProduct(productId, viewType, cursor, pageSize))); } @@ -50,13 +52,12 @@ public class ProductsController extends BaseEntity { } } - //To do : buyerId 추후에 토큰으로 변경 @Tag(name = "FavoriteProduct") @Operation(summary = "찜하지 않은 상태라면 찜하기. \n 찜한 상태라면 찜하기 취소") - @PostMapping("/favorite/{productId}/{buyerId}") - public ResponseEntity> toggleFavoriteProduct(@PathVariable Long productId, @PathVariable Long buyerId) { + @PostMapping("/favorite/{productId}") + public ResponseEntity> toggleFavoriteProduct(@AuthenticationPrincipal Buyer currentBuyer, @PathVariable Long productId) { try { - return ResponseEntity.ok(productsCommandService.toggleFavoriteProduct(productId, buyerId)); + return ResponseEntity.ok(productsCommandService.toggleFavoriteProduct(productId, currentBuyer)); } catch (IllegalArgumentException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.onFailure(HttpStatus.BAD_REQUEST.name(), e.getMessage())); } catch (UserExceptionHandler e) { diff --git a/src/main/java/umc/unimade/domain/products/service/ProductsCommandService.java b/src/main/java/umc/unimade/domain/products/service/ProductsCommandService.java index 3c2e64a..e95ea76 100644 --- a/src/main/java/umc/unimade/domain/products/service/ProductsCommandService.java +++ b/src/main/java/umc/unimade/domain/products/service/ProductsCommandService.java @@ -48,9 +48,8 @@ public class ProductsCommandService { private final SellerRepository sellerRepository; @Transactional - public ApiResponse toggleFavoriteProduct(Long productId, Long buyerId) { + public ApiResponse toggleFavoriteProduct(Long productId, Buyer buyer) { Products product = findProductById(productId); - Buyer buyer = findBuyerById(buyerId); Optional existingFavorite = findFavoriteProduct(product,buyer); if (existingFavorite.isPresent()) { From f98d7d47deb2e5887f74f8a9190f7ce52ef4ddbb Mon Sep 17 00:00:00 2001 From: moonyaeyoon Date: Fri, 26 Jul 2024 20:13:28 +0900 Subject: [PATCH 7/7] =?UTF-8?q?fix=20:=20qna=20,=20=EB=A6=AC=EB=B7=B0?= =?UTF-8?q?=EC=97=90=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/qna/controller/QnAController.java | 19 +++++++++++-------- .../domain/qna/service/QnACommandService.java | 6 ++---- .../review/controller/ReviewController.java | 9 ++++++--- .../review/service/ReviewCommandService.java | 5 ++--- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/umc/unimade/domain/qna/controller/QnAController.java b/src/main/java/umc/unimade/domain/qna/controller/QnAController.java index 26de241..3bdc5ca 100644 --- a/src/main/java/umc/unimade/domain/qna/controller/QnAController.java +++ b/src/main/java/umc/unimade/domain/qna/controller/QnAController.java @@ -6,8 +6,11 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import umc.unimade.domain.accounts.entity.Buyer; +import umc.unimade.domain.accounts.entity.Seller; import umc.unimade.domain.qna.dto.AnswerCreateRequest; import umc.unimade.domain.qna.dto.AnswerResponse; import umc.unimade.domain.qna.dto.QuestionCreateRequest; @@ -27,13 +30,14 @@ public class QnAController { private final QnACommandService qnaCommandService; private final QnAQueryService qnaQueryService; - //To do : QnA DIR 생성 @Tag(name = "QnA", description = "qna 관련 API") @Operation(summary = "질문 생성") - @PostMapping(value = "/question/{productId}/{buyerId}") - public ResponseEntity> createQuestion(@PathVariable Long productId, @PathVariable Long buyerId, @RequestPart("questionCreateRequest") QuestionCreateRequest questionCreateRequest) { + @PostMapping(value = "/question/{productId}") + public ResponseEntity> createQuestion(@AuthenticationPrincipal Buyer currentBuyer, + @PathVariable Long productId, + @RequestPart("questionCreateRequest") QuestionCreateRequest questionCreateRequest) { try { - qnaCommandService.createQuestion(productId, buyerId, questionCreateRequest); + qnaCommandService.createQuestion(productId, currentBuyer, questionCreateRequest); return ResponseEntity.ok(ApiResponse.onSuccess(null)); } catch (IllegalArgumentException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.onFailure(HttpStatus.BAD_REQUEST.name(), e.getMessage())); @@ -56,13 +60,12 @@ public ResponseEntity> getQuestion(@PathVariable L } } - //To do : QnA DIR 생성 @Tag(name = "QnA", description = "qna 관련 API") @Operation(summary = "답변 생성") - @PostMapping(value = "/answer/{questionId}/{sellerId}") - public ResponseEntity> createAnswer(@PathVariable Long questionId, @PathVariable Long sellerId, @RequestPart("answerCreateRequest") AnswerCreateRequest answerCreateRequest) { + @PostMapping(value = "/answer/{questionId}") + public ResponseEntity> createAnswer(@PathVariable Long questionId, @AuthenticationPrincipal Seller currentSeller, @RequestPart("answerCreateRequest") AnswerCreateRequest answerCreateRequest) { try { - qnaCommandService.createAnswer(questionId, sellerId, answerCreateRequest); + qnaCommandService.createAnswer(questionId, currentSeller, answerCreateRequest); return ResponseEntity.ok(ApiResponse.onSuccess(null)); } catch (IllegalArgumentException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.onFailure(HttpStatus.BAD_REQUEST.name(), e.getMessage())); diff --git a/src/main/java/umc/unimade/domain/qna/service/QnACommandService.java b/src/main/java/umc/unimade/domain/qna/service/QnACommandService.java index a0307d8..c81f434 100644 --- a/src/main/java/umc/unimade/domain/qna/service/QnACommandService.java +++ b/src/main/java/umc/unimade/domain/qna/service/QnACommandService.java @@ -37,17 +37,15 @@ public class QnACommandService { private final AnswersRespository answersRespository; @Transactional - public void createQuestion(Long productId, Long buyerId, QuestionCreateRequest questionCreateRequest) { + public void createQuestion(Long productId, Buyer buyer, QuestionCreateRequest questionCreateRequest) { Products product = findProductById(productId); - Buyer buyer = findBuyerById(buyerId); Questions question = questionCreateRequest.toEntity(product, buyer); questionsRepository.save(question); } @Transactional - public void createAnswer(Long questionId,Long sellerId, AnswerCreateRequest answerCreateRequest){ + public void createAnswer(Long questionId, Seller seller , AnswerCreateRequest answerCreateRequest){ Questions question = findQuestionById(questionId); - Seller seller = findSellerById(sellerId); Answers answer = answerCreateRequest.toEntity(seller, question); answersRespository.save(answer); } diff --git a/src/main/java/umc/unimade/domain/review/controller/ReviewController.java b/src/main/java/umc/unimade/domain/review/controller/ReviewController.java index 3daf95d..41ef388 100644 --- a/src/main/java/umc/unimade/domain/review/controller/ReviewController.java +++ b/src/main/java/umc/unimade/domain/review/controller/ReviewController.java @@ -6,8 +6,10 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import umc.unimade.domain.accounts.entity.Buyer; import umc.unimade.domain.review.dto.ReviewCreateRequest; import umc.unimade.domain.review.dto.ReviewResponse; import umc.unimade.domain.review.service.ReviewCommandService; @@ -27,12 +29,13 @@ public class ReviewController { @Tag(name = "Review", description = "리뷰 관련 API") @Operation(summary = "리뷰 생성") - @PostMapping(value = "/{productId}/{buyerId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public ResponseEntity> createReview(@PathVariable Long productId, @PathVariable Long buyerId, + @PostMapping(value = "/{productId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public ResponseEntity> createReview(@PathVariable Long productId, + @AuthenticationPrincipal Buyer currentBuyer, @RequestPart("reviewCreateRequest") ReviewCreateRequest reviewCreateRequest, @RequestPart(value = "reviewImages", required = false) List reviewImages) { try { - reviewCommandService.createReview(productId, buyerId, reviewCreateRequest, reviewImages); + reviewCommandService.createReview(productId, currentBuyer, reviewCreateRequest, reviewImages); return ResponseEntity.ok(ApiResponse.onSuccess(null)); } catch (IllegalArgumentException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.onFailure(HttpStatus.BAD_REQUEST.name(), e.getMessage())); diff --git a/src/main/java/umc/unimade/domain/review/service/ReviewCommandService.java b/src/main/java/umc/unimade/domain/review/service/ReviewCommandService.java index 074634a..49e23be 100644 --- a/src/main/java/umc/unimade/domain/review/service/ReviewCommandService.java +++ b/src/main/java/umc/unimade/domain/review/service/ReviewCommandService.java @@ -28,11 +28,10 @@ public class ReviewCommandService { private final S3Provider s3Provider; @Transactional - public void createReview(Long productId, Long buyerId, ReviewCreateRequest reviewCreateRequest, List images) { + public void createReview(Long productId, Buyer buyer, ReviewCreateRequest reviewCreateRequest, List images) { Products product = findProductById(productId); - Buyer buyer = findBuyerById(buyerId); Review review = reviewCreateRequest.toEntity(product, buyer); - List reviewImages = reviewCreateRequest.toReviewImages(images, s3Provider, buyerId, review); + List reviewImages = reviewCreateRequest.toReviewImages(images, s3Provider, buyer.getId(), review); if (reviewImages != null) { review.setReviewImages(reviewImages); }