From 23c9f8aa568deb30cee39d6cec1284a3ad476aae Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Mon, 13 Jan 2025 22:22:04 +0900 Subject: [PATCH 01/12] =?UTF-8?q?[Refactor]=20=EB=B3=80=EC=88=98=EB=AA=85?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/market/controller/MarketController.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/appcenter/marketplace/domain/market/controller/MarketController.java b/src/main/java/com/appcenter/marketplace/domain/market/controller/MarketController.java index 92a0342..a695d04 100644 --- a/src/main/java/com/appcenter/marketplace/domain/market/controller/MarketController.java +++ b/src/main/java/com/appcenter/marketplace/domain/market/controller/MarketController.java @@ -121,7 +121,7 @@ public ResponseEntity>> getTopFavorite @GetMapping("/top-latest-coupon") public ResponseEntity>> getLatestTopCouponList( @RequestParam Long memberId, - @RequestParam(defaultValue = "10", name = "count") Integer size) { + @RequestParam(defaultValue = "10", name = "size") Integer size) { return ResponseEntity.ok(CommonResponse.from(COUPON_FOUND.getMessage(), marketService.getTopLatestCoupons(memberId, size))); } @@ -137,13 +137,13 @@ public ResponseEntity>> getLatestTopCoup public ResponseEntity>> getLatestMarketByCoupon( @RequestParam(required = true) Long memberId, @Parameter(description = "각 페이지의 마지막 couponId (e.g. 5)") - @RequestParam(required = false, name = "lastPageIndex") Long couponId, - @Parameter(description = "위에 작성한 couponId의 createdAt (e.g. 2024-11-20T00:59:33.469 OR 2024-11-20T00:59:33.469664 )") + @RequestParam(required = false, name = "lastPageIndex") Long marketId, + @Parameter(description = "위에 작성한 marketId의 createdAt (e.g. 2024-11-20T00:59:33.469 OR 2024-11-20T00:59:33.469664 )") @RequestParam(required = false, name = "lastCreatedAt") LocalDateTime lastCreatedAt, @RequestParam(defaultValue = "10", name = "pageSize") Integer size) { return ResponseEntity .ok(CommonResponse.from(MARKET_FOUND.getMessage(), - marketService.getLatestCouponPage(memberId, lastCreatedAt, couponId, size))); + marketService.getLatestCouponPage(memberId, lastCreatedAt, marketId, size))); } @Operation(summary = "마감 임박 쿠폰 TOP 조회", @@ -152,7 +152,7 @@ public ResponseEntity>> getLatestM "만약 쿠폰의 마감일자가 같을 시, 최신 등록 매장 순으로 보여지게 됩니다.") @GetMapping("/top-closing-coupon") public ResponseEntity>> getClosingTopCouponList( - @RequestParam(defaultValue = "10", name="count") Integer size){ + @RequestParam(defaultValue = "10", name="size") Integer size){ return ResponseEntity.ok(CommonResponse.from(COUPON_FOUND.getMessage(), marketService.getTopClosingCoupons(size))); } From 2db998fc0e700b62defcf331b6946b09f552763d Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Mon, 13 Jan 2025 22:22:22 +0900 Subject: [PATCH 02/12] =?UTF-8?q?[Refactor]=20boolean->Boolean=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/market/dto/res/TopFavoriteMarketRes.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/appcenter/marketplace/domain/market/dto/res/TopFavoriteMarketRes.java b/src/main/java/com/appcenter/marketplace/domain/market/dto/res/TopFavoriteMarketRes.java index 8e27e2e..92e1683 100644 --- a/src/main/java/com/appcenter/marketplace/domain/market/dto/res/TopFavoriteMarketRes.java +++ b/src/main/java/com/appcenter/marketplace/domain/market/dto/res/TopFavoriteMarketRes.java @@ -8,10 +8,10 @@ public class TopFavoriteMarketRes { private final Long marketId; private final String marketName; private final String thumbnail; - private final boolean isFavorite; + private final Boolean isFavorite; @QueryProjection - public TopFavoriteMarketRes(Long marketId, String marketName, String thumbnail, boolean isFavorite) { + public TopFavoriteMarketRes(Long marketId, String marketName, String thumbnail, Boolean isFavorite) { this.marketId = marketId; this.marketName = marketName; this.thumbnail = thumbnail; From a98c63af1b152d9e57bf2084ff1ad8118447b81e Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Wed, 15 Jan 2025 02:58:06 +0900 Subject: [PATCH 03/12] =?UTF-8?q?[Refactor]=20cheera=20api=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../marketplace/domain/cheer/controller/CheerController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/appcenter/marketplace/domain/cheer/controller/CheerController.java b/src/main/java/com/appcenter/marketplace/domain/cheer/controller/CheerController.java index bccd35f..1f91215 100644 --- a/src/main/java/com/appcenter/marketplace/domain/cheer/controller/CheerController.java +++ b/src/main/java/com/appcenter/marketplace/domain/cheer/controller/CheerController.java @@ -13,7 +13,7 @@ @Tag(name = "[공감]", description = "[공감] 임시 매장 공감하기") @RestController @RequiredArgsConstructor -@RequestMapping("/cheer") +@RequestMapping("/api/cheer") public class CheerController { private final CheerService cheerService; From 55d345e1e6d70c44d668218bfae7187029679a70 Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Wed, 15 Jan 2025 17:02:37 +0900 Subject: [PATCH 04/12] =?UTF-8?q?[Refactor]=20=EC=A4=91=EB=B3=B5=20Dto=201?= =?UTF-8?q?=EA=B0=9C=EB=A1=9C=20=EC=9D=BC=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../appcenter/marketplace/domain/coupon/Coupon.java | 12 ++++++------ .../coupon/controller/CouponOwnerController.java | 5 ++--- .../domain/coupon/service/CouponOwnerService.java | 3 +-- .../coupon/service/impl/CouponOwnerServiceImpl.java | 5 ++--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/Coupon.java b/src/main/java/com/appcenter/marketplace/domain/coupon/Coupon.java index f46c457..7738f51 100644 --- a/src/main/java/com/appcenter/marketplace/domain/coupon/Coupon.java +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/Coupon.java @@ -1,6 +1,6 @@ package com.appcenter.marketplace.domain.coupon; -import com.appcenter.marketplace.domain.coupon.dto.req.CouponUpdateReq; +import com.appcenter.marketplace.domain.coupon.dto.req.CouponReq; import com.appcenter.marketplace.domain.market.Market; import com.appcenter.marketplace.global.common.BaseEntity; import jakarta.persistence.*; @@ -54,11 +54,11 @@ public Coupon(String name, String description, LocalDateTime deadLine, Integer s this.isDeleted = isDeleted; } - public void update(CouponUpdateReq couponUpdateReq) { - this.name = couponUpdateReq.getCouponName(); - this.description = couponUpdateReq.getDescription(); - this.deadLine = couponUpdateReq.getDeadLine(); - this.stock = couponUpdateReq.getStock(); + public void update(CouponReq couponUpReq) { + this.name = couponUpReq.getCouponName(); + this.description = couponUpReq.getDescription(); + this.deadLine = couponUpReq.getDeadLine(); + this.stock = couponUpReq.getStock(); } public void updateHidden() { diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/controller/CouponOwnerController.java b/src/main/java/com/appcenter/marketplace/domain/coupon/controller/CouponOwnerController.java index e963146..4a31ca6 100644 --- a/src/main/java/com/appcenter/marketplace/domain/coupon/controller/CouponOwnerController.java +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/controller/CouponOwnerController.java @@ -1,7 +1,6 @@ package com.appcenter.marketplace.domain.coupon.controller; import com.appcenter.marketplace.domain.coupon.dto.req.CouponReq; -import com.appcenter.marketplace.domain.coupon.dto.req.CouponUpdateReq; import com.appcenter.marketplace.domain.coupon.dto.res.CouponHiddenRes; import com.appcenter.marketplace.domain.coupon.dto.res.CouponRes; import com.appcenter.marketplace.domain.coupon.service.CouponOwnerService; @@ -48,9 +47,9 @@ public ResponseEntity>> getCouponList(@RequestPar @Operation(summary = "사장님 쿠폰 내용 수정", description = "사장님이 생성한 쿠폰의 내용을 수정합니다. " + "
'숨김처리'를 제외한 내용을 수정할 수 있습니다. ") @PutMapping("/coupons/{couponId}") - public ResponseEntity> updateCoupon(@RequestBody @Valid CouponUpdateReq couponUpdateReq, + public ResponseEntity> updateCoupon(@RequestBody @Valid CouponReq couponReq, @PathVariable Long couponId ){ - return ResponseEntity.status(COUPON_UPDATE.getStatus()).body(CommonResponse.from(COUPON_UPDATE.getMessage(),couponService.updateCoupon(couponUpdateReq, couponId))); + return ResponseEntity.status(COUPON_UPDATE.getStatus()).body(CommonResponse.from(COUPON_UPDATE.getMessage(),couponService.updateCoupon(couponReq, couponId))); } @Operation(summary = "숨김/공개 처리 기능", description = "사장님은 생성한 쿠폰을 숨김 / 공개 처리 할 수 있습니다.") diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/service/CouponOwnerService.java b/src/main/java/com/appcenter/marketplace/domain/coupon/service/CouponOwnerService.java index 4ba8c8f..554fa2c 100644 --- a/src/main/java/com/appcenter/marketplace/domain/coupon/service/CouponOwnerService.java +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/service/CouponOwnerService.java @@ -1,7 +1,6 @@ package com.appcenter.marketplace.domain.coupon.service; import com.appcenter.marketplace.domain.coupon.dto.req.CouponReq; -import com.appcenter.marketplace.domain.coupon.dto.req.CouponUpdateReq; import com.appcenter.marketplace.domain.coupon.dto.res.CouponHiddenRes; import com.appcenter.marketplace.domain.coupon.dto.res.CouponRes; @@ -19,7 +18,7 @@ public interface CouponOwnerService { List getCouponList(Long marketId); // 쿠폰 내용 수정 메서드 - CouponRes updateCoupon(CouponUpdateReq couponUpdateReq, Long couponId); + CouponRes updateCoupon(CouponReq couponReq, Long couponId); // 쿠폰 숨김 처리 메서드 CouponHiddenRes updateCouponHidden(Long couponId); diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/service/impl/CouponOwnerServiceImpl.java b/src/main/java/com/appcenter/marketplace/domain/coupon/service/impl/CouponOwnerServiceImpl.java index 436cdb0..b5cc832 100644 --- a/src/main/java/com/appcenter/marketplace/domain/coupon/service/impl/CouponOwnerServiceImpl.java +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/service/impl/CouponOwnerServiceImpl.java @@ -2,7 +2,6 @@ import com.appcenter.marketplace.domain.coupon.Coupon; import com.appcenter.marketplace.domain.coupon.dto.req.CouponReq; -import com.appcenter.marketplace.domain.coupon.dto.req.CouponUpdateReq; import com.appcenter.marketplace.domain.coupon.dto.res.CouponHiddenRes; import com.appcenter.marketplace.domain.coupon.dto.res.CouponRes; import com.appcenter.marketplace.domain.coupon.repository.CouponRepository; @@ -48,9 +47,9 @@ public List getCouponList(Long marketId) { @Override @Transactional - public CouponRes updateCoupon(CouponUpdateReq couponUpdateReq, Long couponId) { + public CouponRes updateCoupon(CouponReq couponReq, Long couponId) { Coupon coupon = findCouponById(couponId); - coupon.update(couponUpdateReq); + coupon.update(couponReq); return CouponRes.toDto(coupon); } From cd1d6cf9aaa1ee234c3326b205c5d80b396b36e9 Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Wed, 15 Jan 2025 17:56:45 +0900 Subject: [PATCH 05/12] =?UTF-8?q?[Feat]=20=EC=9E=84=EC=8B=9C=EB=A7=A4?= =?UTF-8?q?=EC=9E=A5=20=EC=A0=95=EB=B3=B4=20=EC=83=81=EC=84=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tempMarket/controller/TempMarketAdminController.java | 9 ++++++++- .../tempMarket/service/TempMarketAdminService.java | 5 +++-- .../service/impl/TempMarketAdminServiceImpl.java | 7 +++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/appcenter/marketplace/domain/tempMarket/controller/TempMarketAdminController.java b/src/main/java/com/appcenter/marketplace/domain/tempMarket/controller/TempMarketAdminController.java index cbb0868..ec5545d 100644 --- a/src/main/java/com/appcenter/marketplace/domain/tempMarket/controller/TempMarketAdminController.java +++ b/src/main/java/com/appcenter/marketplace/domain/tempMarket/controller/TempMarketAdminController.java @@ -9,6 +9,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import lombok.Getter; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -54,7 +55,7 @@ public ResponseEntity> updateTempMarket( @Operation(summary = "매장 정보 전체 조회", description = "매장 전체를 조회합니다.
" + "pageNum의 기본값은 1입니다. (1페이지)
" + "size의 기본값은 10입니다. 한페이지당 나타나는 데이터의 갯수입니다.") - @GetMapping + @GetMapping("/all") public ResponseEntity>> getAllTempMarket( @RequestParam(defaultValue = "1", name= "page") Integer page, @RequestParam(defaultValue = "10", name = "size") Integer size @@ -62,6 +63,12 @@ public ResponseEntity>> getAllTempMarke return ResponseEntity.ok(CommonResponse.from(MARKET_FOUND.getMessage(), tempMarketAdminService.getMarketList(page, size))); } + @Operation(summary = "매장 정보 상세 조회", description = "매장 정보를 상세 조회합니다.") + @GetMapping("/{tempMarketId}") + public ResponseEntity> getTempMarket(@PathVariable Long tempMarketId){ + return ResponseEntity.ok(CommonResponse.from(MARKET_FOUND.getMessage(), tempMarketAdminService.getMarket(tempMarketId))); + } + @Operation(summary = "매장 공개(숨김) 처리", description = "매장을 공개(숨김)처리가 가능합니다." ) @PutMapping("/hidden/{tempMarketId}") public ResponseEntity> toggleTempMarket( diff --git a/src/main/java/com/appcenter/marketplace/domain/tempMarket/service/TempMarketAdminService.java b/src/main/java/com/appcenter/marketplace/domain/tempMarket/service/TempMarketAdminService.java index 1f39079..a958845 100644 --- a/src/main/java/com/appcenter/marketplace/domain/tempMarket/service/TempMarketAdminService.java +++ b/src/main/java/com/appcenter/marketplace/domain/tempMarket/service/TempMarketAdminService.java @@ -1,11 +1,9 @@ package com.appcenter.marketplace.domain.tempMarket.service; -import com.appcenter.marketplace.domain.tempMarket.TempMarket; import com.appcenter.marketplace.domain.tempMarket.dto.req.TempMarketReq; import com.appcenter.marketplace.domain.tempMarket.dto.res.TempMarketDetailRes; import com.appcenter.marketplace.domain.tempMarket.dto.res.TempMarketHiddenRes; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -17,8 +15,11 @@ public interface TempMarketAdminService { Page getMarketList(Integer page, Integer size); + TempMarketDetailRes getMarket(Long marketId); + TempMarketHiddenRes toggleHidden(Long marketId); void deleteMarket(Long marketId); + } diff --git a/src/main/java/com/appcenter/marketplace/domain/tempMarket/service/impl/TempMarketAdminServiceImpl.java b/src/main/java/com/appcenter/marketplace/domain/tempMarket/service/impl/TempMarketAdminServiceImpl.java index c107449..2b55d87 100644 --- a/src/main/java/com/appcenter/marketplace/domain/tempMarket/service/impl/TempMarketAdminServiceImpl.java +++ b/src/main/java/com/appcenter/marketplace/domain/tempMarket/service/impl/TempMarketAdminServiceImpl.java @@ -88,6 +88,12 @@ public Page getMarketList(Integer page, Integer size) { return tempMarketPage.map(TempMarketDetailRes::toDto); } + @Override + public TempMarketDetailRes getMarket(Long marketId) { + TempMarket tempMarket = findMarket(marketId); + return TempMarketDetailRes.toDto(tempMarket); + } + @Override @Transactional public TempMarketHiddenRes toggleHidden(Long marketId) { @@ -104,6 +110,7 @@ public void deleteMarket(Long marketId) { } + private Category findCategory(String category) { if (Major.exists(category)) { return categoryRepository.findByMajor(Major.valueOf(category)) From ae875c8a42a3e21c0b319d0d929bbcbe6af691d1 Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Wed, 15 Jan 2025 18:03:14 +0900 Subject: [PATCH 06/12] =?UTF-8?q?[Refactor]=20=EC=9E=84=EC=8B=9C=EB=A7=A4?= =?UTF-8?q?=EC=9E=A5=20url=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tempMarket/controller/TempMarketAdminController.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/appcenter/marketplace/domain/tempMarket/controller/TempMarketAdminController.java b/src/main/java/com/appcenter/marketplace/domain/tempMarket/controller/TempMarketAdminController.java index ec5545d..78fb57f 100644 --- a/src/main/java/com/appcenter/marketplace/domain/tempMarket/controller/TempMarketAdminController.java +++ b/src/main/java/com/appcenter/marketplace/domain/tempMarket/controller/TempMarketAdminController.java @@ -1,6 +1,5 @@ package com.appcenter.marketplace.domain.tempMarket.controller; -import com.appcenter.marketplace.domain.tempMarket.TempMarket; import com.appcenter.marketplace.domain.tempMarket.dto.req.TempMarketReq; import com.appcenter.marketplace.domain.tempMarket.dto.res.TempMarketDetailRes; import com.appcenter.marketplace.domain.tempMarket.dto.res.TempMarketHiddenRes; @@ -9,24 +8,20 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; -import lombok.Getter; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import java.util.List; - import static com.appcenter.marketplace.global.common.StatusCode.*; import static com.appcenter.marketplace.global.common.StatusCode.MARKET_HIDDEN; @Tag(name ="[관리자 공감매장]", description = "[관리자] 관리자 공감매장 관리") @RestController @RequiredArgsConstructor -@RequestMapping("/api/admin/tempMarkets") +@RequestMapping("/api/admin/temp-markets") public class TempMarketAdminController { private final TempMarketAdminService tempMarketAdminService; @@ -55,7 +50,7 @@ public ResponseEntity> updateTempMarket( @Operation(summary = "매장 정보 전체 조회", description = "매장 전체를 조회합니다.
" + "pageNum의 기본값은 1입니다. (1페이지)
" + "size의 기본값은 10입니다. 한페이지당 나타나는 데이터의 갯수입니다.") - @GetMapping("/all") + @GetMapping public ResponseEntity>> getAllTempMarket( @RequestParam(defaultValue = "1", name= "page") Integer page, @RequestParam(defaultValue = "10", name = "size") Integer size From fa795ea14afab4c29564bb0db7374420e19383f4 Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Wed, 15 Jan 2025 18:22:15 +0900 Subject: [PATCH 07/12] =?UTF-8?q?[Refactor]=20=EB=A0=88=ED=8F=AC=EC=A7=80?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=20->=20=EC=84=9C=EB=B9=84=EC=8A=A4=EA=B3=84?= =?UTF-8?q?=EC=B8=B5=20=EC=B0=B8=EC=A1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/RequestMarketService.java | 6 ++++++ .../service/impl/RequestMarketServiceImpl.java | 15 +++++++++++++++ .../service/impl/TempMarketAdminServiceImpl.java | 14 ++++++++------ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/appcenter/marketplace/domain/requestMarket/service/RequestMarketService.java b/src/main/java/com/appcenter/marketplace/domain/requestMarket/service/RequestMarketService.java index 092424f..e31322b 100644 --- a/src/main/java/com/appcenter/marketplace/domain/requestMarket/service/RequestMarketService.java +++ b/src/main/java/com/appcenter/marketplace/domain/requestMarket/service/RequestMarketService.java @@ -10,4 +10,10 @@ public interface RequestMarketService { RequestMarketRes createRequestMarket(RequestMarketCreateReq requestMarketCreateReq); Page getRequestMarkets(Integer page, Integer size); + + boolean existRequestMarket(String marketName); + + void deleteRequestMarket(Long marketId); + + RequestMarket getRequestMarketName(String marketName); } diff --git a/src/main/java/com/appcenter/marketplace/domain/requestMarket/service/impl/RequestMarketServiceImpl.java b/src/main/java/com/appcenter/marketplace/domain/requestMarket/service/impl/RequestMarketServiceImpl.java index a9e26e6..12a1c15 100644 --- a/src/main/java/com/appcenter/marketplace/domain/requestMarket/service/impl/RequestMarketServiceImpl.java +++ b/src/main/java/com/appcenter/marketplace/domain/requestMarket/service/impl/RequestMarketServiceImpl.java @@ -39,4 +39,19 @@ public Page getRequestMarkets(Integer page, Integer size) { Pageable pageable = PageRequest.of(page-1, size, Sort.by("count").descending()); return requestMarketRepository.findAll(pageable); } + + @Override + public boolean existRequestMarket(String marketName) { + return requestMarketRepository.existsByName(marketName); + } + + @Override + public void deleteRequestMarket(Long marketId) { + requestMarketRepository.deleteById(marketId); + } + + @Override + public RequestMarket getRequestMarketName(String marketName) { + return requestMarketRepository.findRequestMarketByName(marketName); + } } diff --git a/src/main/java/com/appcenter/marketplace/domain/tempMarket/service/impl/TempMarketAdminServiceImpl.java b/src/main/java/com/appcenter/marketplace/domain/tempMarket/service/impl/TempMarketAdminServiceImpl.java index 2b55d87..d982fd7 100644 --- a/src/main/java/com/appcenter/marketplace/domain/tempMarket/service/impl/TempMarketAdminServiceImpl.java +++ b/src/main/java/com/appcenter/marketplace/domain/tempMarket/service/impl/TempMarketAdminServiceImpl.java @@ -3,7 +3,7 @@ import com.appcenter.marketplace.domain.category.Category; import com.appcenter.marketplace.domain.category.CategoryRepository; import com.appcenter.marketplace.domain.requestMarket.RequestMarket; -import com.appcenter.marketplace.domain.requestMarket.repository.RequestMarketRepository; +import com.appcenter.marketplace.domain.requestMarket.service.RequestMarketService; import com.appcenter.marketplace.domain.tempMarket.TempMarket; import com.appcenter.marketplace.domain.tempMarket.dto.req.TempMarketReq; import com.appcenter.marketplace.domain.tempMarket.dto.res.TempMarketDetailRes; @@ -32,7 +32,8 @@ public class TempMarketAdminServiceImpl implements TempMarketAdminService { private final TempMarketRepository tempMarketRepository; private final CategoryRepository categoryRepository; - private final RequestMarketRepository requestMarketRepository; + + private final RequestMarketService requestMarketService; @Value("${tempImage.upload.path}") private String imageFolder; @@ -49,11 +50,12 @@ public TempMarketDetailRes createMarket(TempMarketReq marketReq, MultipartFile m TempMarket market =tempMarketRepository.save(marketReq.toEntity(category, imageName)); // 요청 매장 삭제 로직 - // 요청 매장의 이름이나 주소가 일치하는 매장만 삭제 - if(requestMarketRepository.existsByName(market.getName()) || requestMarketRepository.existsByAddress(market.getAddress())) { - RequestMarket requestMarket = requestMarketRepository.findRequestMarketByName(market.getName()); - requestMarketRepository.deleteById(requestMarket.getId()); + // 요청 매장의 이름(unique)가 일치하는 매장만 삭제 + if(requestMarketService.existRequestMarket(market.getName())){ + RequestMarket requestMarket = requestMarketService.getRequestMarketName(market.getName()); + requestMarketService.deleteRequestMarket(requestMarket.getId()); } + return TempMarketDetailRes.toDto(market); } From 28de8f7cc77eb0acdac1867217b3b364ceff5af3 Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Fri, 17 Jan 2025 01:44:25 +0900 Subject: [PATCH 08/12] =?UTF-8?q?[Refactor]=20=EB=B0=9B=EC=9D=80=20?= =?UTF-8?q?=EC=BF=A0=ED=8F=B0=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member_coupon/MemberCouponType.java | 5 ++ .../service/MemberCouponService.java | 6 +-- .../service/impl/MemberCouponServiceImpl.java | 47 +++++++++++-------- 3 files changed, 35 insertions(+), 23 deletions(-) create mode 100644 src/main/java/com/appcenter/marketplace/domain/member_coupon/MemberCouponType.java diff --git a/src/main/java/com/appcenter/marketplace/domain/member_coupon/MemberCouponType.java b/src/main/java/com/appcenter/marketplace/domain/member_coupon/MemberCouponType.java new file mode 100644 index 0000000..9625723 --- /dev/null +++ b/src/main/java/com/appcenter/marketplace/domain/member_coupon/MemberCouponType.java @@ -0,0 +1,5 @@ +package com.appcenter.marketplace.domain.member_coupon; + +public enum MemberCouponType { + ISSUED, EXPIRED, USED +} diff --git a/src/main/java/com/appcenter/marketplace/domain/member_coupon/service/MemberCouponService.java b/src/main/java/com/appcenter/marketplace/domain/member_coupon/service/MemberCouponService.java index bfc843d..7e05f8e 100644 --- a/src/main/java/com/appcenter/marketplace/domain/member_coupon/service/MemberCouponService.java +++ b/src/main/java/com/appcenter/marketplace/domain/member_coupon/service/MemberCouponService.java @@ -1,5 +1,7 @@ package com.appcenter.marketplace.domain.member_coupon.service; +import com.appcenter.marketplace.domain.coupon.dto.res.CouponPageRes; +import com.appcenter.marketplace.domain.member_coupon.MemberCouponType; import com.appcenter.marketplace.domain.member_coupon.dto.res.IssuedCouponRes; import com.appcenter.marketplace.domain.member_coupon.dto.res.CouponHandleRes; @@ -7,9 +9,7 @@ public interface MemberCouponService { void issuedCoupon(Long memberId, Long couponId); - List getMemberCouponList(Long memberId); - List getExpiredMemberCouponList(Long memberId); - List getUsedMemberCouponList(Long memberId); + CouponPageRes getMemberCouponList(Long memberId, MemberCouponType type, Long couponId, Integer size); CouponHandleRes updateCoupon(Long memberCouponId); IssuedCouponRes getMemberCoupon(Long memberCouponId); diff --git a/src/main/java/com/appcenter/marketplace/domain/member_coupon/service/impl/MemberCouponServiceImpl.java b/src/main/java/com/appcenter/marketplace/domain/member_coupon/service/impl/MemberCouponServiceImpl.java index 9ff4b3c..5394782 100644 --- a/src/main/java/com/appcenter/marketplace/domain/member_coupon/service/impl/MemberCouponServiceImpl.java +++ b/src/main/java/com/appcenter/marketplace/domain/member_coupon/service/impl/MemberCouponServiceImpl.java @@ -1,10 +1,12 @@ package com.appcenter.marketplace.domain.member_coupon.service.impl; import com.appcenter.marketplace.domain.coupon.Coupon; +import com.appcenter.marketplace.domain.coupon.dto.res.CouponPageRes; import com.appcenter.marketplace.domain.coupon.repository.CouponRepository; import com.appcenter.marketplace.domain.member.Member; import com.appcenter.marketplace.domain.member.repository.MemberRepository; import com.appcenter.marketplace.domain.member_coupon.MemberCoupon; +import com.appcenter.marketplace.domain.member_coupon.MemberCouponType; import com.appcenter.marketplace.domain.member_coupon.dto.res.IssuedCouponRes; import com.appcenter.marketplace.domain.member_coupon.dto.res.CouponHandleRes; import com.appcenter.marketplace.domain.member_coupon.repository.MemberCouponRepository; @@ -40,7 +42,7 @@ public void issuedCoupon(Long memberId, Long couponId) { // 회원이 이미 해당 쿠폰을 발급받았는지 확인 if (!memberCouponRepository.existCouponByMemberId(member.getId(), coupon.getId())) { - MemberCoupon memberCoupon = memberCouponRepository.save(MemberCoupon.builder() + memberCouponRepository.save(MemberCoupon.builder() .member(member) .coupon(coupon) .isUsed(false) @@ -54,20 +56,19 @@ public void issuedCoupon(Long memberId, Long couponId) { @Override @Transactional - public List getMemberCouponList(Long memberId) { - return getMemberCouponList(memberId, memberCouponRepository::findIssuedCouponResDtoByMemberId); - } - - @Override - @Transactional - public List getExpiredMemberCouponList(Long memberId) { - return getMemberCouponList(memberId, memberCouponRepository::findExpiredCouponResDtoByMemberId); - } - - @Override - @Transactional - public List getUsedMemberCouponList(Long memberId) { - return getMemberCouponList(memberId, memberCouponRepository::findUsedMemberCouponResDtoByMemberId); + public CouponPageRes getMemberCouponList(Long memberId, MemberCouponType type, Long memberCouponId, Integer size) { + List couponList; + + switch (type) { + case EXPIRED -> + couponList = memberCouponRepository.findExpiredCouponResDtoByMemberId(memberId, memberCouponId, size); + case USED -> + couponList = memberCouponRepository.findUsedMemberCouponResDtoByMemberId(memberId, memberCouponId, size); + default -> + couponList = memberCouponRepository.findIssuedCouponResDtoByMemberId(memberId, memberCouponId, size); + }; + + return checkNextPageAndReturn(couponList, size); } @Override @@ -84,11 +85,6 @@ public IssuedCouponRes getMemberCoupon(Long memberCouponId) { return IssuedCouponRes.toDto(memberCoupon); } - private List getMemberCouponList(Long memberId, Function> findCoupons) { - Member member = findMemberById(memberId); - return findCoupons.apply(member.getId()); - } - private Member findMemberById(Long memberId) { return memberRepository.findById(memberId).orElseThrow(() -> new CustomException(MEMBER_NOT_EXIST)); } @@ -104,4 +100,15 @@ private Coupon findCouponById(Long couponId) { private MemberCoupon findMemberCouponById(Long memberCouponId) { return memberCouponRepository.findById(memberCouponId).orElseThrow(() -> new CustomException(COUPON_NOT_EXIST)); } + + private CouponPageRes checkNextPageAndReturn(List couponList, Integer size) { + boolean hasNext = false; + + if(couponList.size() > size){ + hasNext = true; + couponList.remove(size.intValue()); + } + + return new CouponPageRes<>(couponList, hasNext); + } } \ No newline at end of file From 9828eeba293b23b0a9587711d7542eb8e440c746 Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Fri, 17 Jan 2025 01:44:52 +0900 Subject: [PATCH 09/12] =?UTF-8?q?[Refactor]=20=EB=B0=9B=EC=9D=80=20?= =?UTF-8?q?=EC=BF=A0=ED=8F=B0=20=EC=A1=B0=ED=9A=8C=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=95=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberCouponController.java | 33 ++++++++++++------- .../MemberCouponRepositoryCustom.java | 6 ++-- .../MemberCouponRepositoryCustomImpl.java | 31 ++++++++++++----- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/appcenter/marketplace/domain/member_coupon/controller/MemberCouponController.java b/src/main/java/com/appcenter/marketplace/domain/member_coupon/controller/MemberCouponController.java index e3e992a..e17b1b5 100644 --- a/src/main/java/com/appcenter/marketplace/domain/member_coupon/controller/MemberCouponController.java +++ b/src/main/java/com/appcenter/marketplace/domain/member_coupon/controller/MemberCouponController.java @@ -1,5 +1,6 @@ package com.appcenter.marketplace.domain.member_coupon.controller; +import com.appcenter.marketplace.domain.coupon.dto.res.CouponPageRes; import com.appcenter.marketplace.domain.member_coupon.dto.res.IssuedCouponRes; import com.appcenter.marketplace.domain.member_coupon.dto.res.CouponHandleRes; import com.appcenter.marketplace.domain.member_coupon.service.MemberCouponService; @@ -12,6 +13,7 @@ import java.util.List; +import static com.appcenter.marketplace.domain.member_coupon.MemberCouponType.*; import static com.appcenter.marketplace.global.common.StatusCode.*; @Tag(name = "[회원 쿠폰]", description = "[회원] 회원의 쿠폰 발급 및 사용처리, 리스트 확인") @@ -32,31 +34,40 @@ public ResponseEntity> issuedCoupon(@RequestParam(name="m } @Operation(summary = "사용 가능한 쿠폰 리스트", description = "쿠폰 리스트를 조회하면 기본적으로 조회되는 리스트입니다." + - "
'사용가능'한 쿠폰 리스트를 의미합니다." ) + "
'사용가능'한 쿠폰 리스트를 의미합니다.
" + + "무한 스크롤 방식으로 hasNext가 true 면 마지막 데이터의 memberCouponId를 입력하여, 다음 페이지==다음 데이터를 받아올 수 있습니다." ) @GetMapping("/valid") - public ResponseEntity>> getCouponList(@RequestParam(name="memberId")Long memberId){ + public ResponseEntity>> getCouponList(@RequestParam(name="memberId")Long memberId, + @RequestParam(name="memberCouponId", required = false) Long memberCouponId, + @RequestParam(name="size", defaultValue = "10")Integer size) { return ResponseEntity.status(COUPON_FOUND.getStatus()) - .body(CommonResponse.from(COUPON_FOUND.getMessage(), memberCouponService.getMemberCouponList(memberId))); + .body(CommonResponse.from(COUPON_FOUND.getMessage(), memberCouponService.getMemberCouponList(memberId, ISSUED, memberCouponId, size))); } @Operation(summary = "만료된 쿠폰 리스트", description = "기간이 만료된 쿠폰 리스트를 조회합니다." + "
조건은 다음과 같습니다." + - "1. 쿠폰의 deadLine(만료날짜) 이후여야 합니다." + - "2. 쿠폰은 발급받았지만, 사용처리가 되지 않아야 합니다.") + "1. 쿠폰의 deadLine(만료날짜) 이후여야 합니다.
" + + "2. 쿠폰은 발급받았지만, 사용처리가 되지 않아야 합니다.
" + + "무한 스크롤 방식으로 hasNext가 true 면 마지막 데이터의 memberCouponId를 입력하여, 다음 페이지==다음 데이터를 받아올 수 있습니다.") @GetMapping("/expired") - public ResponseEntity>> getExpiredCouponList(@RequestParam(name="memberId")Long memberId){ + public ResponseEntity>> getExpiredCouponList(@RequestParam(name="memberId")Long memberId, + @RequestParam(name="memberCouponId", required = false) Long memberCouponId, + @RequestParam(name="size", defaultValue = "10")Integer size){ return ResponseEntity.status(COUPON_FOUND.getStatus()) - .body(CommonResponse.from(COUPON_FOUND.getMessage(), memberCouponService.getExpiredMemberCouponList(memberId))); + .body(CommonResponse.from(COUPON_FOUND.getMessage(), memberCouponService.getMemberCouponList(memberId, EXPIRED, memberCouponId, size))); } @Operation(summary = "사용완료된 쿠폰 리스트", description = "사용이 완료된 쿠폰 리스트를 조회합니다." + "
조건은 다음과 같습니다." + - "1. 쿠폰을 발급받고, 사용처리가 완료되어야 합니다." + - "2. 쿠폰의 deadLine(만료날짜)와는 상관이 없습니다.") + "1. 쿠폰을 발급받고, 사용처리가 완료되어야 합니다.
" + + "2. 쿠폰의 deadLine(만료날짜)와는 상관이 없습니다.
" + + "무한 스크롤 방식으로 hasNext가 true 면 마지막 데이터의 memberCouponId를 입력하여, 다음 페이지==다음 데이터를 받아올 수 있습니다.") @GetMapping("/used") - public ResponseEntity>> getUsedCouponList(@RequestParam(name="memberId")Long memberId){ + public ResponseEntity>> getUsedCouponList(@RequestParam(name="memberId")Long memberId, + @RequestParam(name="memberCouponId", required = false) Long memberCouponId, + @RequestParam(name="size", defaultValue = "10")Integer size){ return ResponseEntity.status(COUPON_FOUND.getStatus()) - .body(CommonResponse.from(COUPON_FOUND.getMessage(), memberCouponService.getUsedMemberCouponList(memberId))); + .body(CommonResponse.from(COUPON_FOUND.getMessage(), memberCouponService.getMemberCouponList(memberId, USED, memberCouponId, size))); } @Operation(summary = "회원 쿠폰 사용처리", description = "회원은 발급받은 memberCouponId로 사용처리를 할 수 있습니다." ) diff --git a/src/main/java/com/appcenter/marketplace/domain/member_coupon/repository/MemberCouponRepositoryCustom.java b/src/main/java/com/appcenter/marketplace/domain/member_coupon/repository/MemberCouponRepositoryCustom.java index 610eb73..663bf95 100644 --- a/src/main/java/com/appcenter/marketplace/domain/member_coupon/repository/MemberCouponRepositoryCustom.java +++ b/src/main/java/com/appcenter/marketplace/domain/member_coupon/repository/MemberCouponRepositoryCustom.java @@ -7,7 +7,7 @@ public interface MemberCouponRepositoryCustom { boolean existCouponByMemberId(Long memberId, Long couponId); - List findIssuedCouponResDtoByMemberId(Long memberId); - List findExpiredCouponResDtoByMemberId(Long memberId); - List findUsedMemberCouponResDtoByMemberId(Long memberId); + List findIssuedCouponResDtoByMemberId(Long memberId, Long memberCouponId, Integer size); + List findExpiredCouponResDtoByMemberId(Long memberId, Long memberCouponId, Integer size); + List findUsedMemberCouponResDtoByMemberId(Long memberId, Long memberCouponId, Integer size); } diff --git a/src/main/java/com/appcenter/marketplace/domain/member_coupon/repository/MemberCouponRepositoryCustomImpl.java b/src/main/java/com/appcenter/marketplace/domain/member_coupon/repository/MemberCouponRepositoryCustomImpl.java index 89717be..477b2af 100644 --- a/src/main/java/com/appcenter/marketplace/domain/member_coupon/repository/MemberCouponRepositoryCustomImpl.java +++ b/src/main/java/com/appcenter/marketplace/domain/member_coupon/repository/MemberCouponRepositoryCustomImpl.java @@ -2,6 +2,7 @@ import com.appcenter.marketplace.domain.member_coupon.dto.res.IssuedCouponRes; import com.appcenter.marketplace.domain.member_coupon.dto.res.QIssuedCouponRes; +import com.querydsl.core.BooleanBuilder; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; @@ -27,19 +28,19 @@ public boolean existCouponByMemberId(Long memberId, Long couponId) { } @Override - public List findIssuedCouponResDtoByMemberId(Long memberId) { + public List findIssuedCouponResDtoByMemberId(Long memberId, Long memberCouponId, Integer size) { // 만료되기 전의 쿠폰만 조회가 가능합니다. - return findCouponsByMemberId(memberId, false); + return findCouponsByMemberId(memberId, false, memberCouponId, size); } @Override - public List findExpiredCouponResDtoByMemberId(Long memberId) { + public List findExpiredCouponResDtoByMemberId(Long memberId, Long memberCouponId, Integer size) { // 발급 받은 쿠폰 중, 기간이 만료된 쿠폰만 조회합니다. - return findCouponsByMemberId(memberId, true); + return findCouponsByMemberId(memberId, true,memberCouponId, size); } @Override - public List findUsedMemberCouponResDtoByMemberId(Long memberId) { + public List findUsedMemberCouponResDtoByMemberId(Long memberId, Long memberCouponId, Integer size ) { return jpaQueryFactory.select(new QIssuedCouponRes(memberCoupon.id, coupon.id, coupon.name, @@ -48,12 +49,15 @@ public List findUsedMemberCouponResDtoByMemberId(Long memberId) memberCoupon.isUsed)) .from(coupon) .join(memberCoupon).on(memberCoupon.coupon.id.eq(coupon.id)) - .where(memberCoupon.member.id.eq(memberId) + .where(ltMemberCouponId(memberCouponId) + .and(memberCoupon.member.id.eq(memberId)) .and(memberCoupon.isUsed.eq(true))) + .orderBy(memberCoupon.id.desc()) + .limit(size+1) .fetch(); } - private List findCouponsByMemberId(Long memberId, boolean isExpired) { + private List findCouponsByMemberId(Long memberId, boolean isExpired,Long memberCouponId, Integer size) { return jpaQueryFactory.select(new QIssuedCouponRes(memberCoupon.id, coupon.id, coupon.name, @@ -62,13 +66,24 @@ private List findCouponsByMemberId(Long memberId, boolean isExp memberCoupon.isUsed)) .from(coupon) .join(memberCoupon).on(memberCoupon.coupon.id.eq(coupon.id)) - .where(memberCoupon.member.id.eq(memberId) + .where(ltMemberCouponId(memberCouponId) + .and(memberCoupon.member.id.eq(memberId)) .and(memberCoupon.isUsed.eq(false)) .and(isExpired ? memberCoupon.coupon.deadLine.before(LocalDateTime.now()) : memberCoupon.coupon.deadLine.after(LocalDateTime.now()))) + .orderBy(memberCoupon.id.desc()) + .limit(size+1) .fetch(); } + + private BooleanBuilder ltMemberCouponId(Long memberCouponId){ + BooleanBuilder builder = new BooleanBuilder(); + if( memberCouponId != null){ + builder.and(memberCoupon.id.lt(memberCouponId)); + } + return builder; + } } From c70720d5bdbfa8f3520cc3ff48119142e13860af Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Fri, 17 Jan 2025 01:45:37 +0900 Subject: [PATCH 10/12] =?UTF-8?q?[Feat]=20=ED=8E=98=EC=9D=B4=EC=A7=95=20DT?= =?UTF-8?q?O=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/coupon/dto/res/CouponPageRes.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/appcenter/marketplace/domain/coupon/dto/res/CouponPageRes.java diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/dto/res/CouponPageRes.java b/src/main/java/com/appcenter/marketplace/domain/coupon/dto/res/CouponPageRes.java new file mode 100644 index 0000000..c8ae551 --- /dev/null +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/dto/res/CouponPageRes.java @@ -0,0 +1,16 @@ +package com.appcenter.marketplace.domain.coupon.dto.res; + +import lombok.Getter; + +import java.util.List; + +@Getter +public class CouponPageRes { + private final List couponResDtos; + private final boolean hasNext; + + public CouponPageRes(List couponResDtos, boolean hasNext){ + this.couponResDtos = couponResDtos; + this.hasNext = hasNext; + } +} From 9383e6690b196a047d7f2778303260a2cbc45d86 Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Fri, 17 Jan 2025 01:46:20 +0900 Subject: [PATCH 11/12] =?UTF-8?q?[Refactor]=20=ED=9A=8C=EC=9B=90-=EC=BF=A0?= =?UTF-8?q?=ED=8F=B0=20=ED=8E=98=EC=9D=B4=EC=A7=95=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coupon/controller/CouponController.java | 16 +++++++++---- .../repository/CouponRepositoryCustom.java | 5 ++-- .../CouponRepositoryCustomImpl.java | 23 +++++++++++++++---- .../domain/coupon/service/CouponService.java | 3 ++- .../service/impl/CouponServiceImpl.java | 16 ++++++++++--- 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/controller/CouponController.java b/src/main/java/com/appcenter/marketplace/domain/coupon/controller/CouponController.java index f8680e0..9d16523 100644 --- a/src/main/java/com/appcenter/marketplace/domain/coupon/controller/CouponController.java +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/controller/CouponController.java @@ -1,6 +1,7 @@ package com.appcenter.marketplace.domain.coupon.controller; import com.appcenter.marketplace.domain.coupon.dto.res.CouponMemberRes; +import com.appcenter.marketplace.domain.coupon.dto.res.CouponPageRes; import com.appcenter.marketplace.domain.coupon.service.CouponService; import com.appcenter.marketplace.global.common.CommonResponse; import io.swagger.v3.oas.annotations.Operation; @@ -9,6 +10,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -23,11 +25,17 @@ public class CouponController { private final CouponService couponService; - @Operation(summary = "유효 쿠폰 조회 리스트", description = "사장님이 공개처리 & 만료되지 않은 쿠폰 리스트가 조회됩니다." + - "
매장 상세 정보에서 조회가 이루어집니다.") + @Operation(summary = "유효 쿠폰 조회 리스트", description = "사장님이 공개처리 & 만료되지 않은 쿠폰 리스트가 조회됩니다.
" + + "매장 상세 정보에서 조회가 이루어집니다.
" + + "couponId는 다음 페이징 처리를 위해 사용되는 파라미터 입니다. 다음") @GetMapping - public ResponseEntity>> getCouponList(Long marketId) { - return ResponseEntity.status(COUPON_FOUND.getStatus()).body(CommonResponse.from(COUPON_FOUND.getMessage(),couponService.getCouponList(marketId))); + public ResponseEntity>> getCouponList( + @RequestParam(name= "marketId")Long marketId, + @RequestParam(name="couponId", required = false) Long couponId, + @RequestParam(name="size", defaultValue = "10") Integer size + ) { + return ResponseEntity.status(COUPON_FOUND.getStatus()) + .body(CommonResponse.from(COUPON_FOUND.getMessage(),couponService.getCouponList(marketId, couponId, size))); } diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/repository/CouponRepositoryCustom.java b/src/main/java/com/appcenter/marketplace/domain/coupon/repository/CouponRepositoryCustom.java index 22b6619..e9c556b 100644 --- a/src/main/java/com/appcenter/marketplace/domain/coupon/repository/CouponRepositoryCustom.java +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/repository/CouponRepositoryCustom.java @@ -5,8 +5,7 @@ import java.util.List; public interface CouponRepositoryCustom { + List findCouponsForOwnerByMarketId(Long marketId, Long couponId, Integer size); - List findOwnerCouponResDtoByMarketId(Long marketId); - - List findMemberCouponResDtoByMarketId(Long marketId); + List findCouponsForMemberByMarketId(Long marketId, Long couponId, Integer size); } diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/repository/CouponRepositoryCustomImpl.java b/src/main/java/com/appcenter/marketplace/domain/coupon/repository/CouponRepositoryCustomImpl.java index 0af1afb..3ccf07c 100644 --- a/src/main/java/com/appcenter/marketplace/domain/coupon/repository/CouponRepositoryCustomImpl.java +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/repository/CouponRepositoryCustomImpl.java @@ -4,6 +4,7 @@ import com.appcenter.marketplace.domain.coupon.dto.res.CouponRes; import com.appcenter.marketplace.domain.coupon.dto.res.QCouponMemberRes; import com.appcenter.marketplace.domain.coupon.dto.res.QCouponRes; +import com.querydsl.core.BooleanBuilder; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; @@ -19,7 +20,7 @@ public class CouponRepositoryCustomImpl implements CouponRepositoryCustom { // 사장님) '숨김처리'에 관계없이 발행한 모든 쿠폰을 확인할 수 있습니다. @Override - public List findOwnerCouponResDtoByMarketId(Long marketId) { + public List findCouponsForOwnerByMarketId(Long marketId, Long couponId, Integer size) { return jpaQueryFactory.select(new QCouponRes(coupon.id, coupon.market.id, @@ -30,14 +31,17 @@ public List findOwnerCouponResDtoByMarketId(Long marketId) { coupon.isHidden)) .from(coupon) .join(market).on(coupon.market.id.eq(market.id)) - .where(coupon.market.id.eq(marketId) + .where(ltCouponId(couponId) + .and(coupon.market.id.eq(marketId)) .and(coupon.isDeleted.eq(false))) + .orderBy(coupon.id.desc()) + .limit(size + 1) .fetch(); } // 유저) 사장님이 발행한 쿠폰 중 '공개처리'가 된 쿠폰들만 유저는 리스트에서 확인 가능합니다. @Override - public List findMemberCouponResDtoByMarketId(Long marketId) { + public List findCouponsForMemberByMarketId(Long marketId, Long couponId, Integer size) { return jpaQueryFactory.select(new QCouponMemberRes(coupon.id, coupon.name, @@ -45,10 +49,21 @@ public List findMemberCouponResDtoByMarketId(Long marketId) { coupon.deadLine)) .from(coupon) .innerJoin(coupon).on(coupon.market.id.eq(market.id)) - .where(coupon.market.id.eq(marketId) + .where(ltCouponId(couponId) + .and(coupon.market.id.eq(marketId)) .and(coupon.isDeleted.eq(false)) .and(coupon.isHidden.eq(false))) + .orderBy(coupon.id.desc()) + .limit(size + 1) .fetch(); } + + private BooleanBuilder ltCouponId(Long couponId) { + BooleanBuilder builder = new BooleanBuilder(); + if( couponId != null){ + builder.and(coupon.id.lt(couponId)); + } + return builder; + } } diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/service/CouponService.java b/src/main/java/com/appcenter/marketplace/domain/coupon/service/CouponService.java index 65df71f..2e1d5dc 100644 --- a/src/main/java/com/appcenter/marketplace/domain/coupon/service/CouponService.java +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/service/CouponService.java @@ -1,10 +1,11 @@ package com.appcenter.marketplace.domain.coupon.service; import com.appcenter.marketplace.domain.coupon.dto.res.CouponMemberRes; +import com.appcenter.marketplace.domain.coupon.dto.res.CouponPageRes; import java.util.List; public interface CouponService { - List getCouponList(Long marketId); + CouponPageRes getCouponList(Long marketId, Long couponId, Integer size); } diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/service/impl/CouponServiceImpl.java b/src/main/java/com/appcenter/marketplace/domain/coupon/service/impl/CouponServiceImpl.java index a051c6e..907d1c9 100644 --- a/src/main/java/com/appcenter/marketplace/domain/coupon/service/impl/CouponServiceImpl.java +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/service/impl/CouponServiceImpl.java @@ -23,10 +23,10 @@ public class CouponServiceImpl implements CouponService { @Override @Transactional - public List getCouponList(Long marketId) { + public CouponPageRes getCouponList(Long marketId, Long couponId, Integer size) { Market market = findMarketById(marketId); - List couponList = couponRepository.findMemberCouponResDtoByMarketId(marketId); - return couponList; + List couponList = couponRepository.findCouponsForMemberByMarketId(market.getId(), couponId, size); + return checkNextPageAndReturn(couponList, size); } private Market findMarketById(Long marketId) { @@ -34,4 +34,14 @@ private Market findMarketById(Long marketId) { } + private CouponPageRes checkNextPageAndReturn(List couponList, Integer size) { + boolean hasNext = false; + + if(couponList.size() > size){ + hasNext = true; + couponList.remove(size.intValue()); + } + + return new CouponPageRes<>(couponList, hasNext); + } } From 87f65c70dedfc1fa17d4d7d30e4a166793e8ed30 Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Fri, 17 Jan 2025 01:46:37 +0900 Subject: [PATCH 12/12] =?UTF-8?q?[Refactor]=20=EC=82=AC=EC=9E=A5=EB=8B=98?= =?UTF-8?q?=20=EC=BF=A0=ED=8F=B0=20=EC=A1=B0=ED=9A=8C=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=95=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CouponOwnerController.java | 8 ++++++-- .../coupon/service/CouponOwnerService.java | 5 ++--- .../service/impl/CouponOwnerServiceImpl.java | 18 ++++++++++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/controller/CouponOwnerController.java b/src/main/java/com/appcenter/marketplace/domain/coupon/controller/CouponOwnerController.java index 4a31ca6..9ffc625 100644 --- a/src/main/java/com/appcenter/marketplace/domain/coupon/controller/CouponOwnerController.java +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/controller/CouponOwnerController.java @@ -2,6 +2,7 @@ import com.appcenter.marketplace.domain.coupon.dto.req.CouponReq; import com.appcenter.marketplace.domain.coupon.dto.res.CouponHiddenRes; +import com.appcenter.marketplace.domain.coupon.dto.res.CouponPageRes; import com.appcenter.marketplace.domain.coupon.dto.res.CouponRes; import com.appcenter.marketplace.domain.coupon.service.CouponOwnerService; import com.appcenter.marketplace.global.common.CommonResponse; @@ -40,8 +41,11 @@ public ResponseEntity> getCoupon(@PathVariable Long co @Operation(summary = "사장님 매장별 전체 쿠폰 조회", description = "사장님의 특정 매장(MarketId)의 전체 쿠폰 리스트를 조회합니다.") @GetMapping("/coupons") - public ResponseEntity>> getCouponList(@RequestParam(name= "marketId")Long id) { - return ResponseEntity.status(COUPON_FOUND.getStatus()).body(CommonResponse.from(COUPON_FOUND.getMessage(),couponService.getCouponList(id))); + public ResponseEntity>> getCouponList(@RequestParam(name= "marketId")Long marketId, + @RequestParam(name="couponId", required = false) Long couponId, + @RequestParam(name="size", defaultValue = "10") Integer size + ) { + return ResponseEntity.status(COUPON_FOUND.getStatus()).body(CommonResponse.from(COUPON_FOUND.getMessage(),couponService.getCouponList(marketId, couponId, size))); } @Operation(summary = "사장님 쿠폰 내용 수정", description = "사장님이 생성한 쿠폰의 내용을 수정합니다. " + diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/service/CouponOwnerService.java b/src/main/java/com/appcenter/marketplace/domain/coupon/service/CouponOwnerService.java index 554fa2c..ad7b82d 100644 --- a/src/main/java/com/appcenter/marketplace/domain/coupon/service/CouponOwnerService.java +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/service/CouponOwnerService.java @@ -2,10 +2,9 @@ import com.appcenter.marketplace.domain.coupon.dto.req.CouponReq; import com.appcenter.marketplace.domain.coupon.dto.res.CouponHiddenRes; +import com.appcenter.marketplace.domain.coupon.dto.res.CouponPageRes; import com.appcenter.marketplace.domain.coupon.dto.res.CouponRes; -import java.util.List; - public interface CouponOwnerService { // 쿠폰 등록 메서드 @@ -15,7 +14,7 @@ public interface CouponOwnerService { CouponRes getCoupon(Long couponId); // 매장별 전체 쿠폰 확인 메서드 - List getCouponList(Long marketId); + CouponPageRes getCouponList(Long marketId, Long CouponId, Integer size); // 쿠폰 내용 수정 메서드 CouponRes updateCoupon(CouponReq couponReq, Long couponId); diff --git a/src/main/java/com/appcenter/marketplace/domain/coupon/service/impl/CouponOwnerServiceImpl.java b/src/main/java/com/appcenter/marketplace/domain/coupon/service/impl/CouponOwnerServiceImpl.java index b5cc832..9704f30 100644 --- a/src/main/java/com/appcenter/marketplace/domain/coupon/service/impl/CouponOwnerServiceImpl.java +++ b/src/main/java/com/appcenter/marketplace/domain/coupon/service/impl/CouponOwnerServiceImpl.java @@ -3,6 +3,7 @@ import com.appcenter.marketplace.domain.coupon.Coupon; import com.appcenter.marketplace.domain.coupon.dto.req.CouponReq; import com.appcenter.marketplace.domain.coupon.dto.res.CouponHiddenRes; +import com.appcenter.marketplace.domain.coupon.dto.res.CouponPageRes; import com.appcenter.marketplace.domain.coupon.dto.res.CouponRes; import com.appcenter.marketplace.domain.coupon.repository.CouponRepository; import com.appcenter.marketplace.domain.coupon.service.CouponOwnerService; @@ -40,9 +41,11 @@ public CouponRes getCoupon(Long couponId) { @Override @Transactional - public List getCouponList(Long marketId) { + public CouponPageRes getCouponList(Long marketId, Long couponId, Integer size) { Market market = findMarketById(marketId); - return couponRepository.findOwnerCouponResDtoByMarketId(market.getId()); + List couponResList = couponRepository.findCouponsForOwnerByMarketId(market.getId(), couponId, size); + + return checkNextPageAndReturn(couponResList, size); } @Override @@ -84,4 +87,15 @@ private Coupon findCouponById(Long couponId) { else throw new CustomException(COUPON_IS_DELETED); } + + private CouponPageRes checkNextPageAndReturn(List couponList, Integer size) { + boolean hasNext = false; + + if(couponList.size() > size){ + hasNext = true; + couponList.remove(size.intValue()); + } + + return new CouponPageRes<>(couponList, hasNext); + } }