Skip to content

Commit 90c84c6

Browse files
authored
Merge pull request #46 from hyujikoh/feat/sorted-list
refactor(cache): 캐시 키 형식 및 오류 메시지 개선
2 parents 5950d66 + a04f37e commit 90c84c6

8 files changed

Lines changed: 27 additions & 15 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/application/point/PointFacade.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.loopers.application.point;
22

3+
import java.math.BigDecimal;
4+
35
import org.springframework.stereotype.Component;
46
import org.springframework.transaction.annotation.Transactional;
57

@@ -36,7 +38,7 @@ public PointV1Dtos.PointInfo getPointInfo(String username) {
3638

3739
@Transactional
3840
public PointV1Dtos.PointChargeResponse chargePoint(String username, PointV1Dtos.PointChargeRequest request) {
39-
java.math.BigDecimal totalAmount = pointService.charge(username, request.amount());
41+
BigDecimal totalAmount = pointService.charge(username, request.amount());
4042

4143
return new PointV1Dtos.PointChargeResponse(username, totalAmount);
4244
}

apps/commerce-api/src/main/java/com/loopers/support/error/ErrorType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public enum ErrorType {
2929

3030
//좋아요 관련 오류
3131
ALREADY_LIKED_PRODUCT(HttpStatus.CONFLICT, HttpStatus.CONFLICT.getReasonPhrase(), "이미 좋아요한 상품입니다."),
32-
NOT_EXIST_LIKED(HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST.getReasonPhrase(), "좋아요하지 않은 상품입니다."),
32+
NOT_EXIST_LIKED(HttpStatus.BAD_REQUEST, HttpStatus.NOT_FOUND.getReasonPhrase(), "좋아요하지 않은 상품입니다."),
3333

3434
// 주문 관련 오류
3535
NOT_FOUND_ORDER(HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND.getReasonPhrase(), "존재하지 않는 주문입니다."),

apps/commerce-api/src/main/java/com/loopers/util/ProductDataGeneratorRunner.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.datafaker.Faker;
44
import java.math.BigDecimal;
5+
import java.math.RoundingMode;
56
import java.util.*;
67

78
import org.springframework.boot.CommandLineRunner;
@@ -219,7 +220,7 @@ private ProductEntity createRandomProduct(Long brandId) {
219220
BigDecimal originPrice = generateRandomPrice(10000, 500000);
220221
BigDecimal discountPrice = random.nextDouble() > 0.5
221222
? originPrice.multiply(BigDecimal.valueOf(random.nextDouble() * 0.8 + 0.1))
222-
.setScale(0, java.math.RoundingMode.HALF_UP)
223+
.setScale(0, RoundingMode.HALF_UP)
223224
: null;
224225
int stockQuantity = random.nextInt(1000) + 1;
225226

apps/commerce-api/src/test/java/com/loopers/domain/user/UserUnitTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.loopers.domain.user;
22

3+
import java.math.BigDecimal;
4+
35
import org.junit.jupiter.api.DisplayName;
46
import org.junit.jupiter.api.Nested;
57
import org.junit.jupiter.api.Test;
@@ -130,13 +132,13 @@ void can_charge_point() {
130132
// given
131133
UserDomainCreateRequest userRegisterRequest = UserTestFixture.createDefaultUserDomainRequest();
132134
UserEntity userEntity = UserEntity.createUserEntity(userRegisterRequest);
133-
java.math.BigDecimal chargeAmount = new java.math.BigDecimal("1000");
135+
BigDecimal chargeAmount = new BigDecimal("1000");
134136

135137
// when
136138
userEntity.chargePoint(chargeAmount);
137139

138140
// then
139-
UserTestFixture.assertUserPointAmount(userEntity, new java.math.BigDecimal("1000.00"));
141+
UserTestFixture.assertUserPointAmount(userEntity, new BigDecimal("1000.00"));
140142
}
141143

142144
@Test
@@ -147,8 +149,8 @@ void charge_fails_with_zero_or_negative_amount() {
147149
UserEntity userEntity = UserEntity.createUserEntity(userRegisterRequest);
148150

149151
// when & then
150-
UserTestFixture.assertChargePointFails(userEntity, java.math.BigDecimal.ZERO, "충전 금액은 0보다 커야 합니다.");
151-
UserTestFixture.assertChargePointFails(userEntity, new java.math.BigDecimal("-100"), "충전 금액은 0보다 커야 합니다.");
152+
UserTestFixture.assertChargePointFails(userEntity, BigDecimal.ZERO, "충전 금액은 0보다 커야 합니다.");
153+
UserTestFixture.assertChargePointFails(userEntity, new BigDecimal("-100"), "충전 금액은 0보다 커야 합니다.");
152154
}
153155
}
154156
}

apps/commerce-streamer/src/main/java/com/loopers/support/error/ErrorType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public enum ErrorType {
2929

3030
//좋아요 관련 오류
3131
ALREADY_LIKED_PRODUCT(HttpStatus.CONFLICT, HttpStatus.CONFLICT.getReasonPhrase(), "이미 좋아요한 상품입니다."),
32-
NOT_EXIST_LIKED(HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST.getReasonPhrase(), "좋아요하지 않은 상품입니다."),
32+
NOT_EXIST_LIKED(HttpStatus.BAD_REQUEST, HttpStatus.NOT_FOUND.getReasonPhrase(), "좋아요하지 않은 상품입니다."),
3333

3434
// 주문 관련 오류
3535
NOT_FOUND_ORDER(HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND.getReasonPhrase(), "존재하지 않는 주문입니다."),

modules/jpa/src/main/generated/com/loopers/domain/QBaseEntity.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* QBaseEntity is a Querydsl query type for BaseEntity
1414
*/
1515
@Generated("com.querydsl.codegen.DefaultSupertypeSerializer")
16-
public class QBaseEntity extends EntityPathBase<BaseEntity> {
16+
public class QBaseEntity extends EntityPathBase<BaseEntity<?>> {
1717

1818
private static final long serialVersionUID = 1030422725L;
1919

@@ -27,16 +27,19 @@ public class QBaseEntity extends EntityPathBase<BaseEntity> {
2727

2828
public final DateTimePath<java.time.ZonedDateTime> updatedAt = createDateTime("updatedAt", java.time.ZonedDateTime.class);
2929

30+
@SuppressWarnings({"all", "rawtypes", "unchecked"})
3031
public QBaseEntity(String variable) {
31-
super(BaseEntity.class, forVariable(variable));
32+
super((Class) BaseEntity.class, forVariable(variable));
3233
}
3334

35+
@SuppressWarnings({"all", "rawtypes", "unchecked"})
3436
public QBaseEntity(Path<? extends BaseEntity> path) {
35-
super(path.getType(), path.getMetadata());
37+
super((Class) path.getType(), path.getMetadata());
3638
}
3739

40+
@SuppressWarnings({"all", "rawtypes", "unchecked"})
3841
public QBaseEntity(PathMetadata metadata) {
39-
super(BaseEntity.class, metadata);
42+
super((Class) BaseEntity.class, metadata);
4043
}
4144

4245
}

modules/redis/src/main/java/com/loopers/cache/CacheKeyGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private String generateSortString(Sort sort) {
135135
}
136136

137137
/**
138-
* 일간 랭킹 키 생성: ranking:all:2025-12-23
138+
* 일간 랭킹 키 생성: ranking:all:20251223
139139
*/
140140
public String generateDailyRankingKey(LocalDate date) {
141141
return new StringJoiner(DELIMITER)

modules/redis/src/main/java/com/loopers/cache/dto/CachePayloads.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.loopers.cache.dto;
22

3+
import java.math.BigDecimal;
4+
import java.util.Objects;
5+
36
import lombok.Getter;
47

58
/**
@@ -47,7 +50,7 @@ public java.time.LocalDate getEventDate() {
4750
}
4851

4952
/**
50-
* 조회 이벤트 생성 생성
53+
* 조회 이벤트 생성
5154
*/
5255
public static RankingScore forProductView(Long productId, long occurredAt) {
5356
return new RankingScore(productId, EventType.PRODUCT_VIEW, 1.0, occurredAt);
@@ -63,7 +66,8 @@ public static RankingScore forLikeAction(Long productId, long occurredAt) {
6366
/**
6467
* 주문 이벤트 생성 메소드 (가격 * 수량 기반, 로그 정규화)
6568
*/
66-
public static RankingScore forPaymentSuccess(Long productId, java.math.BigDecimal totalPrice, long occurredAt) {
69+
public static RankingScore forPaymentSuccess(Long productId, BigDecimal totalPrice, long occurredAt) {
70+
Objects.requireNonNull(totalPrice);
6771
// 로그 정규화 적용하여 극값 방지
6872
// Math.log(x + 1)을 사용하여 0원일 때도 안전하게 처리
6973
double normalizedScore = Math.log(totalPrice.doubleValue() + 1);

0 commit comments

Comments
 (0)