Skip to content
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 @@ -18,7 +18,8 @@
@RequiredArgsConstructor
public enum CherryLevel {

LEVEL_1(1, "몽롱체리"), // 0-24%
LEVEL_0(0, "몽롱체리"), // completedCount == 0
LEVEL_1(1, "몽롱체리"), // 1개 이상, 0-24%
LEVEL_2(2, "뽀득체리"), // 25-49%
LEVEL_3(3, "팡팡체리"), // 50-74%
LEVEL_4(4, "꾸꾸체리"); // 75-100%
Expand All @@ -34,6 +35,7 @@ public enum CherryLevel {
* 레벨 숫자로 CherryLevel 찾기
*
* @param level 체리 레벨 (1-4)
* 데모용으로 현재 (0-4)
* @return 해당하는 CherryLevel enum
* @throws ChallengeException 존재하지 않는 레벨인 경우
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public enum ChallengeErrorCode implements ErrorType {
DUPLICATE_ROUTINE_IDS("CH009", "중복된 루틴 ID가 포함되어 있습니다", 400),
CHALLENGE_NOT_ACTIVE("CH010", "비활성 챌린지에는 루틴을 추가할 수 없습니다", 400),
CUSTOM_ROUTINE_LIMIT_EXCEEDED("CH011", "최대로 추가할 수 있는 루틴은 20개입니다", 400),
INVALID_CHERRY_LEVEL("CH012", "유효하지 않은 체리 레벨입니다 (1-4)", 400);
INVALID_CHERRY_LEVEL("CH012", "유효하지 않은 체리 레벨입니다 (0-4)", 400);

private final String code;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public class DemoChallengeStatistics extends BaseTimeEntity {
private Integer totalRoutineCount;

@Column(nullable = false, name = "cherry_level")
private Integer cherryLevel = 1;
private Integer cherryLevel = 0;

@Builder
private DemoChallengeStatistics(DemoChallenge demoChallenge, Integer totalRoutineCount) {
this.demoChallenge = demoChallenge;
this.completedCount = 0;
this.totalRoutineCount = totalRoutineCount;
this.cherryLevel = 1;
this.cherryLevel = 0;
}

/**
Expand Down Expand Up @@ -86,10 +86,15 @@ public int getProgressPercentage() {

/**
* 완료 진행률 기반 체리 레벨 계산
* - 레벨 0: completedCount == 0 (몽롱체리)
* - 레벨 1: 1개 이상, 0% ~ 24.99%
* - 레벨 2: 25% ~ 49.99%
* - 레벨 3: 50% ~ 74.99%
* - 레벨 4: 75% ~ 100%
*/
public int calculateCherryLevel() {
if (totalRoutineCount == 0) {
return 1;
if (completedCount == 0) {
return 0;
}

double progressPercentage = getProgressPercentage();
Expand All @@ -110,7 +115,7 @@ public int calculateCherryLevel() {
* 현재 레벨 구간 내에서의 진척도 계산 (0-100%)
*/
public double getProgressToNextLevel() {
if (totalRoutineCount == 0) {
if (totalRoutineCount == 0 || completedCount == 0) {
return 0.0;
}

Expand All @@ -130,11 +135,12 @@ public double getProgressToNextLevel() {

/**
* 다음 레벨까지 남은 루틴 개수 계산
* 레벨 0, 1일 때는 레벨 2(25%)까지 남은 개수 반환
* 레벨 4일 때는 100%까지 남은 루틴 개수를 반환
*/
public int getRemainingRoutinesToNextLevel() {
double nextThreshold = switch (cherryLevel) {
case 1 -> LEVEL_2_THRESHOLD;
case 0, 1 -> LEVEL_2_THRESHOLD;
case 2 -> LEVEL_3_THRESHOLD;
case 3 -> LEVEL_4_THRESHOLD;
default -> 100.0;
Expand Down