From d874940e77aef4831c9862d0583f16baa91aff69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=B0=EC=A7=84=ED=98=B8?= Date: Sat, 7 Dec 2024 20:37:49 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=83=81=EC=A0=90=20=ED=98=9C=ED=83=9D?= =?UTF-8?q?=20=EC=83=81=EC=84=B8=EB=B3=B4=EA=B8=B0=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#1123)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 혜택 카테고리별 상점 조회시 혜택 상세보기 추가 * test: 테스트 필드 추가 * fix: 피드백 반영 --- .../benefit/controller/AdminBenefitApi.java | 4 ++-- .../controller/AdminBenefitController.java | 6 +++--- ....java => AdminBenefitCategoriesResponse.java} | 6 +++--- .../benefit/service/AdminBenefitService.java | 6 +++--- .../domain/benefit/dto/BenefitShopsResponse.java | 12 +++++++++--- .../repository/BenefitCategoryMapRepository.java | 2 +- .../benefit/service/ShopBenefitService.java | 16 +++++++++++----- .../koin/acceptance/BenefitApiTest.java | 5 +++-- 8 files changed, 35 insertions(+), 22 deletions(-) rename src/main/java/in/koreatech/koin/admin/benefit/dto/{AdminBenefitCategoryResponse.java => AdminBenefitCategoriesResponse.java} (89%) diff --git a/src/main/java/in/koreatech/koin/admin/benefit/controller/AdminBenefitApi.java b/src/main/java/in/koreatech/koin/admin/benefit/controller/AdminBenefitApi.java index 510a696eb..9b0ea821f 100644 --- a/src/main/java/in/koreatech/koin/admin/benefit/controller/AdminBenefitApi.java +++ b/src/main/java/in/koreatech/koin/admin/benefit/controller/AdminBenefitApi.java @@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import in.koreatech.koin.admin.benefit.dto.AdminBenefitCategoryResponse; +import in.koreatech.koin.admin.benefit.dto.AdminBenefitCategoriesResponse; import in.koreatech.koin.admin.benefit.dto.AdminBenefitShopsResponse; import in.koreatech.koin.admin.benefit.dto.AdminCreateBenefitCategoryRequest; import in.koreatech.koin.admin.benefit.dto.AdminCreateBenefitCategoryResponse; @@ -44,7 +44,7 @@ public interface AdminBenefitApi { ) @Operation(summary = "상점 혜택 카테고리를 모두 조회한다.") @GetMapping("/categories") - ResponseEntity getBenefitCategories( + ResponseEntity getBenefitCategories( @Auth(permit = {ADMIN}) Integer adminId ); diff --git a/src/main/java/in/koreatech/koin/admin/benefit/controller/AdminBenefitController.java b/src/main/java/in/koreatech/koin/admin/benefit/controller/AdminBenefitController.java index d5fb072d4..544180fbc 100644 --- a/src/main/java/in/koreatech/koin/admin/benefit/controller/AdminBenefitController.java +++ b/src/main/java/in/koreatech/koin/admin/benefit/controller/AdminBenefitController.java @@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import in.koreatech.koin.admin.benefit.dto.AdminBenefitCategoryResponse; +import in.koreatech.koin.admin.benefit.dto.AdminBenefitCategoriesResponse; import in.koreatech.koin.admin.benefit.dto.AdminBenefitShopsResponse; import in.koreatech.koin.admin.benefit.dto.AdminCreateBenefitCategoryRequest; import in.koreatech.koin.admin.benefit.dto.AdminCreateBenefitCategoryResponse; @@ -36,10 +36,10 @@ public class AdminBenefitController implements AdminBenefitApi { private final AdminBenefitService adminBenefitService; @GetMapping("/categories") - public ResponseEntity getBenefitCategories( + public ResponseEntity getBenefitCategories( @Auth(permit = {ADMIN}) Integer adminId ) { - AdminBenefitCategoryResponse response = adminBenefitService.getBenefitCategories(); + AdminBenefitCategoriesResponse response = adminBenefitService.getBenefitCategories(); return ResponseEntity.ok(response); } diff --git a/src/main/java/in/koreatech/koin/admin/benefit/dto/AdminBenefitCategoryResponse.java b/src/main/java/in/koreatech/koin/admin/benefit/dto/AdminBenefitCategoriesResponse.java similarity index 89% rename from src/main/java/in/koreatech/koin/admin/benefit/dto/AdminBenefitCategoryResponse.java rename to src/main/java/in/koreatech/koin/admin/benefit/dto/AdminBenefitCategoriesResponse.java index 379d3019a..ce74fc882 100644 --- a/src/main/java/in/koreatech/koin/admin/benefit/dto/AdminBenefitCategoryResponse.java +++ b/src/main/java/in/koreatech/koin/admin/benefit/dto/AdminBenefitCategoriesResponse.java @@ -9,13 +9,13 @@ import io.swagger.v3.oas.annotations.media.Schema; @JsonNaming(SnakeCaseStrategy.class) -public record AdminBenefitCategoryResponse( +public record AdminBenefitCategoriesResponse( @Schema(description = "혜택 카테고리 리스트") List benefits ) { - public static AdminBenefitCategoryResponse from(List benefitCategories) { - return new AdminBenefitCategoryResponse( + public static AdminBenefitCategoriesResponse from(List benefitCategories) { + return new AdminBenefitCategoriesResponse( benefitCategories.stream().map(InnerBenefitResponse::from).toList() ); } diff --git a/src/main/java/in/koreatech/koin/admin/benefit/service/AdminBenefitService.java b/src/main/java/in/koreatech/koin/admin/benefit/service/AdminBenefitService.java index b00c2e819..7b349578e 100644 --- a/src/main/java/in/koreatech/koin/admin/benefit/service/AdminBenefitService.java +++ b/src/main/java/in/koreatech/koin/admin/benefit/service/AdminBenefitService.java @@ -7,7 +7,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import in.koreatech.koin.admin.benefit.dto.AdminBenefitCategoryResponse; +import in.koreatech.koin.admin.benefit.dto.AdminBenefitCategoriesResponse; import in.koreatech.koin.admin.benefit.dto.AdminBenefitShopsResponse; import in.koreatech.koin.admin.benefit.dto.AdminCreateBenefitCategoryRequest; import in.koreatech.koin.admin.benefit.dto.AdminCreateBenefitCategoryResponse; @@ -36,9 +36,9 @@ public class AdminBenefitService { private final AdminBenefitCategoryMapRepository adminBenefitCategoryMapRepository; private final AdminShopRepository adminShopRepository; - public AdminBenefitCategoryResponse getBenefitCategories() { + public AdminBenefitCategoriesResponse getBenefitCategories() { List categories = adminBenefitCategoryRepository.findAllByOrderByTitleAsc(); - return AdminBenefitCategoryResponse.from(categories); + return AdminBenefitCategoriesResponse.from(categories); } @Transactional diff --git a/src/main/java/in/koreatech/koin/domain/benefit/dto/BenefitShopsResponse.java b/src/main/java/in/koreatech/koin/domain/benefit/dto/BenefitShopsResponse.java index 477fdc100..b33d49f50 100644 --- a/src/main/java/in/koreatech/koin/domain/benefit/dto/BenefitShopsResponse.java +++ b/src/main/java/in/koreatech/koin/domain/benefit/dto/BenefitShopsResponse.java @@ -7,6 +7,7 @@ import java.time.LocalTime; import java.util.Comparator; import java.util.List; +import java.util.Map; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonNaming; @@ -67,7 +68,10 @@ public record InnerShopResponse( double averageRate, @Schema(example = "10", description = "리뷰 개수", requiredMode = REQUIRED) - long reviewCount + long reviewCount, + + @Schema(example = "콜라 서비스", description = "혜택 설명", requiredMode = NOT_REQUIRED) + String benefitDetail ) { public static Comparator getComparator() { @@ -80,7 +84,8 @@ public static Comparator getComparator() { public static InnerShopResponse from( Shop shop, boolean isEvent, - boolean isOpen + boolean isOpen, + String benefitDetail ) { return new InnerShopResponse( shop.getShopCategories().stream().map(shopCategoryMap -> @@ -102,7 +107,8 @@ public static InnerShopResponse from( .orElse(0.0) * 10) / 10.0, shop.getReviews().stream() .filter(review -> !review.isDeleted()) - .count() + .count(), + benefitDetail ); } diff --git a/src/main/java/in/koreatech/koin/domain/benefit/repository/BenefitCategoryMapRepository.java b/src/main/java/in/koreatech/koin/domain/benefit/repository/BenefitCategoryMapRepository.java index cb2590edb..1555fc173 100644 --- a/src/main/java/in/koreatech/koin/domain/benefit/repository/BenefitCategoryMapRepository.java +++ b/src/main/java/in/koreatech/koin/domain/benefit/repository/BenefitCategoryMapRepository.java @@ -9,7 +9,7 @@ public interface BenefitCategoryMapRepository extends Repository { - List findAllByBenefitCategoryId(Integer benefitCategoryId); + List findByBenefitCategoryId(Integer benefitCategoryId); @Query(""" SELECT bcm FROM BenefitCategoryMap bcm diff --git a/src/main/java/in/koreatech/koin/domain/benefit/service/ShopBenefitService.java b/src/main/java/in/koreatech/koin/domain/benefit/service/ShopBenefitService.java index a309885fc..9d41fb04f 100644 --- a/src/main/java/in/koreatech/koin/domain/benefit/service/ShopBenefitService.java +++ b/src/main/java/in/koreatech/koin/domain/benefit/service/ShopBenefitService.java @@ -35,18 +35,24 @@ public BenefitCategoryResponse getBenefitCategories() { } public BenefitShopsResponse getBenefitShops(Integer benefitId) { - List benefitCategoryMaps = benefitCategoryMapRepository - .findAllByBenefitCategoryId(benefitId); + List benefitCategoryMaps = benefitCategoryMapRepository.findByBenefitCategoryId(benefitId); LocalDateTime now = LocalDateTime.now(clock); + List innerShopResponses = benefitCategoryMaps.stream() .map(benefitCategoryMap -> { Shop shop = benefitCategoryMap.getShop(); + String benefitDetail = benefitCategoryMap.getDetail(); boolean isDurationEvent = eventArticleRepository.isDurationEvent(shop.getId(), now.toLocalDate()); - return InnerShopResponse.from(shop, isDurationEvent, shop.isOpen(now)); + return InnerShopResponse.from( + shop, + isDurationEvent, + shop.isOpen(now), + benefitDetail + ); }) .sorted(InnerShopResponse.getComparator()) .toList(); - BenefitShopsResponse shopsResponse = BenefitShopsResponse.from(innerShopResponses); - return shopsResponse; + + return BenefitShopsResponse.from(innerShopResponses); } } diff --git a/src/test/java/in/koreatech/koin/acceptance/BenefitApiTest.java b/src/test/java/in/koreatech/koin/acceptance/BenefitApiTest.java index 8de1c7301..836d56fc1 100644 --- a/src/test/java/in/koreatech/koin/acceptance/BenefitApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/BenefitApiTest.java @@ -95,7 +95,7 @@ void setup() { 성빈_학생 = userFixture.성빈_학생(); - benefitCategoryMapFixture.혜택_추가(김밥천국, 배달비_무료); + benefitCategoryMapFixture.설명이_포함된_혜택_추가(김밥천국, 배달비_무료, "무료"); benefitCategoryMapFixture.혜택_추가(마슬랜, 배달비_무료); benefitCategoryMapFixture.혜택_추가(영업중인_티바, 배달비_무료); benefitCategoryMapFixture.혜택_추가(영업중이_아닌_신전_떡볶이, 배달비_무료); @@ -183,7 +183,8 @@ void setup() { "is_event": false, "is_open": true, "average_rate": 5.0, - "review_count": 1 + "review_count": 1, + "benefit_detail": "무료" }, { "category_ids": [],