Skip to content

Commit 6f96b5c

Browse files
committed
refactor #197: DiscountController 태스트 결과에 따른 기존 코드 수정
1 parent a1f6be1 commit 6f96b5c

5 files changed

Lines changed: 19 additions & 11 deletions

File tree

src/main/java/com/irum/come2us/domain/discount/application/service/DiscountService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
import java.util.List;
2121
import java.util.UUID;
2222
import lombok.RequiredArgsConstructor;
23+
import lombok.extern.slf4j.Slf4j;
2324
import org.springframework.stereotype.Service;
2425
import org.springframework.transaction.annotation.Transactional;
2526

2627
@Service
2728
@RequiredArgsConstructor
2829
@Transactional
30+
@Slf4j
2931
public class DiscountService {
3032
private final DiscountRepository discountRepository;
3133
private final ProductRepository productRepository;
@@ -46,16 +48,20 @@ public DiscountInfoResponse findDiscountInfoByProduct(UUID productId) {
4648

4749
@Transactional(readOnly = true)
4850
public DiscountInfoListResponse findDiscountInfoListByStore(
49-
UUID storeId, UUID cursor, int pageSize) {
51+
UUID storeId, UUID cursor, Integer size) {
5052
Store store = assertOwnerStore(storeId);
51-
int limit = pageSize + 1;
53+
if (size == null || (size != 10 && size != 30 && size != 50)) {
54+
log.warn("허용되지 않은 size 요청: {} -> 기본값 10으로 대체", size);
55+
size = 10;
56+
}
57+
int limit = size + 1;
5258
List<DiscountInfoResponse> discountList =
5359
discountRepository.findDiscountListByCursor(store.getId(), cursor, limit);
5460

55-
boolean hasNext = discountList.size() > pageSize;
61+
boolean hasNext = discountList.size() > size;
5662
UUID nextCursor = null;
5763
List<DiscountInfoResponse> responseList =
58-
hasNext ? discountList.subList(0, pageSize) : discountList;
64+
hasNext ? discountList.subList(0, size) : discountList;
5965
if (!responseList.isEmpty()) {
6066
nextCursor = responseList.get(responseList.size() - 1).discountId();
6167
}

src/main/java/com/irum/come2us/domain/discount/domain/repository/DiscountRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public interface DiscountRepository
1414
"SELECT CASE WHEN COUNT(d) > 0 THEN TRUE ELSE FALSE END FROM Discount d WHERE d.product.id = :productId")
1515
boolean existsByProductId(@Param("productId") UUID productId);
1616

17-
@Query("SELECT d FROM Discount d WHERE d.product.id = :productId")
17+
@Query("SELECT d FROM Discount d JOIN FETCH d.product p WHERE d.product.id = :productId")
1818
Optional<Discount> findByProductId(@Param("productId") UUID productId);
1919
}

src/main/java/com/irum/come2us/domain/discount/presentation/controller/DiscountController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public DiscountInfoResponse getDiscountInfo(@PathVariable UUID productId) {
3636
public DiscountInfoListResponse getDiscountListInfoByStore(
3737
@PathVariable UUID storeId,
3838
@RequestParam(required = false) UUID cursor,
39-
@RequestParam(required = false) Integer pageSize) {
40-
return discountService.findDiscountInfoListByStore(storeId, cursor, pageSize);
39+
@RequestParam(required = false) Integer size) {
40+
return discountService.findDiscountInfoListByStore(storeId, cursor, size);
4141
}
4242

4343
@PatchMapping("/discounts/{discountId}")

src/main/java/com/irum/come2us/domain/discount/presentation/dto/response/DiscountInfoListResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
import java.util.UUID;
55

66
public record DiscountInfoListResponse(
7-
List<DiscountInfoResponse> discountList, UUID nextCursor, boolean hasNext) {}
7+
List<DiscountInfoResponse> discountInfoList, UUID nextCursor, boolean hasNext) {}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.irum.come2us.domain.discount.presentation.dto.response;
22

33
import com.irum.come2us.domain.discount.domain.entity.Discount;
4-
import com.irum.come2us.domain.product.domain.entity.Product;
54
import java.util.UUID;
65

7-
public record DiscountInfoResponse(UUID discountId, String name, int amount, Product product) {
6+
public record DiscountInfoResponse(UUID discountId, String name, int amount, UUID productId) {
87
public static DiscountInfoResponse of(Discount discount) {
98
return new DiscountInfoResponse(
10-
discount.getId(), discount.getName(), discount.getAmount(), discount.getProduct());
9+
discount.getId(),
10+
discount.getName(),
11+
discount.getAmount(),
12+
discount.getProduct().getId());
1113
}
1214
}

0 commit comments

Comments
 (0)