Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 상점 혜택 상세보기 필드 추가 #1123

Merged
merged 3 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,7 +44,7 @@ public interface AdminBenefitApi {
)
@Operation(summary = "상점 혜택 카테고리를 모두 조회한다.")
@GetMapping("/categories")
ResponseEntity<AdminBenefitCategoryResponse> getBenefitCategories(
ResponseEntity<AdminBenefitCategoriesResponse> getBenefitCategories(
@Auth(permit = {ADMIN}) Integer adminId
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,10 +36,10 @@ public class AdminBenefitController implements AdminBenefitApi {
private final AdminBenefitService adminBenefitService;

@GetMapping("/categories")
public ResponseEntity<AdminBenefitCategoryResponse> getBenefitCategories(
public ResponseEntity<AdminBenefitCategoriesResponse> getBenefitCategories(
@Auth(permit = {ADMIN}) Integer adminId
) {
AdminBenefitCategoryResponse response = adminBenefitService.getBenefitCategories();
AdminBenefitCategoriesResponse response = adminBenefitService.getBenefitCategories();
return ResponseEntity.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import io.swagger.v3.oas.annotations.media.Schema;

@JsonNaming(SnakeCaseStrategy.class)
public record AdminBenefitCategoryResponse(
public record AdminBenefitCategoriesResponse(
@Schema(description = "혜택 카테고리 리스트")
List<InnerBenefitResponse> benefits
) {

public static AdminBenefitCategoryResponse from(List<BenefitCategory> benefitCategories) {
return new AdminBenefitCategoryResponse(
public static AdminBenefitCategoriesResponse from(List<BenefitCategory> benefitCategories) {
return new AdminBenefitCategoriesResponse(
benefitCategories.stream().map(InnerBenefitResponse::from).toList()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,9 +36,9 @@ public class AdminBenefitService {
private final AdminBenefitCategoryMapRepository adminBenefitCategoryMapRepository;
private final AdminShopRepository adminShopRepository;

public AdminBenefitCategoryResponse getBenefitCategories() {
public AdminBenefitCategoriesResponse getBenefitCategories() {
List<BenefitCategory> categories = adminBenefitCategoryRepository.findAllByOrderByTitleAsc();
return AdminBenefitCategoryResponse.from(categories);
return AdminBenefitCategoriesResponse.from(categories);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<InnerShopResponse> getComparator() {
Expand All @@ -80,7 +84,8 @@ public static Comparator<InnerShopResponse> getComparator() {
public static InnerShopResponse from(
Shop shop,
boolean isEvent,
boolean isOpen
boolean isOpen,
String benefitDetail
) {
return new InnerShopResponse(
shop.getShopCategories().stream().map(shopCategoryMap ->
Expand All @@ -102,7 +107,8 @@ public static InnerShopResponse from(
.orElse(0.0) * 10) / 10.0,
shop.getReviews().stream()
.filter(review -> !review.isDeleted())
.count()
.count(),
benefitDetail
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public interface BenefitCategoryMapRepository extends Repository<BenefitCategoryMap, Integer> {

List<BenefitCategoryMap> findAllByBenefitCategoryId(Integer benefitCategoryId);
List<BenefitCategoryMap> findByBenefitCategoryId(Integer benefitCategoryId);

@Query("""
SELECT bcm FROM BenefitCategoryMap bcm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,24 @@ public BenefitCategoryResponse getBenefitCategories() {
}

public BenefitShopsResponse getBenefitShops(Integer benefitId) {
List<BenefitCategoryMap> benefitCategoryMaps = benefitCategoryMapRepository
.findAllByBenefitCategoryId(benefitId);
List<BenefitCategoryMap> benefitCategoryMaps = benefitCategoryMapRepository.findByBenefitCategoryId(benefitId);
LocalDateTime now = LocalDateTime.now(clock);

List<InnerShopResponse> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void setup() {

성빈_학생 = userFixture.성빈_학생();

benefitCategoryMapFixture.혜택_추가(김밥천국, 배달비_무료);
benefitCategoryMapFixture.설명이_포함된_혜택_추가(김밥천국, 배달비_무료, "무료");
benefitCategoryMapFixture.혜택_추가(마슬랜, 배달비_무료);
benefitCategoryMapFixture.혜택_추가(영업중인_티바, 배달비_무료);
benefitCategoryMapFixture.혜택_추가(영업중이_아닌_신전_떡볶이, 배달비_무료);
Expand Down Expand Up @@ -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": [],
Expand Down
Loading