diff --git a/src/main/java/com/gdg/kkia/member/entity/Member.java b/src/main/java/com/gdg/kkia/member/entity/Member.java index 6502eae..aed89a7 100644 --- a/src/main/java/com/gdg/kkia/member/entity/Member.java +++ b/src/main/java/com/gdg/kkia/member/entity/Member.java @@ -1,7 +1,9 @@ package com.gdg.kkia.member.entity; import com.gdg.kkia.common.exception.BadRequestException; +import com.gdg.kkia.pet.dto.PointAndPointLogType; import com.gdg.kkia.pet.entity.Pet; +import com.gdg.kkia.point.entity.PointLog; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import lombok.*; @@ -43,16 +45,32 @@ public void earnPoint(int point) { this.point += point; } - public int consumePoint(Pet.GrowthButton growthButton) { + public PointAndPointLogType consumePoint(Pet.GrowthButton growthButton) { int pointToConsume = pointToConsume(growthButton); if (this.point - pointToConsume < 0) { throw new BadRequestException("보유 포인트보다 많은 포인트를 소비할 수 없습니다."); } this.point -= pointToConsume; - return pointToConsume; + PointLog.Type pointLogType = convertGrowthButtonToPointLogType(growthButton); + return new PointAndPointLogType(pointToConsume, pointLogType); } private int pointToConsume(Pet.GrowthButton growthButton) { return convertByGrowthButton(growthButton, NORMAL_BUTTON_PRICE, PREMIUM_BUTTON_PRICE, SUPER_BUTTON_PRICE); } + + private PointLog.Type convertGrowthButtonToPointLogType(Pet.GrowthButton growthButton) { + switch (growthButton) { + case WATER -> { + return PointLog.Type.GROWTH_WATER; + } + case SUN -> { + return PointLog.Type.GROWTH_SUN; + } + case NUTRIENT -> { + return PointLog.Type.GROWTH_NUTRIENT; + } + default -> throw new BadRequestException("팻 성장 버튼 이름이 올바르지 않습니다."); + } + } } diff --git a/src/main/java/com/gdg/kkia/pet/dto/PointAndPointLogType.java b/src/main/java/com/gdg/kkia/pet/dto/PointAndPointLogType.java new file mode 100644 index 0000000..b9e6c66 --- /dev/null +++ b/src/main/java/com/gdg/kkia/pet/dto/PointAndPointLogType.java @@ -0,0 +1,9 @@ +package com.gdg.kkia.pet.dto; + +import com.gdg.kkia.point.entity.PointLog; + +public record PointAndPointLogType( + int point, + PointLog.Type pointLogType +) { +} diff --git a/src/main/java/com/gdg/kkia/pet/entity/Pet.java b/src/main/java/com/gdg/kkia/pet/entity/Pet.java index 24b41e1..880d30a 100644 --- a/src/main/java/com/gdg/kkia/pet/entity/Pet.java +++ b/src/main/java/com/gdg/kkia/pet/entity/Pet.java @@ -20,9 +20,9 @@ public class Pet { private final int INITIAL_EXPERIENCE = 0; private final int MAX_LEVEL = 3; private final int MAX_EXPERIENCE = 100; - private final int NORMAL_PLUS = 1; - private final int PREMIUM_PLUS = 12; - private final int SUPER_PLUS = 30; + private final int WATER_PLUS = 1; + private final int SUN_PLUS = 12; + private final int NUTRIENT_PLUS = 30; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -49,16 +49,16 @@ public Pet(String name, Member member) { isMaxGrowth = false; } - public static int convertByGrowthButton(GrowthButton growthButton, int normalPlus, int premiumPlus, int superPlus) { + public static int convertByGrowthButton(GrowthButton growthButton, int waterPlus, int sunPlus, int nutrientPlus) { switch (growthButton) { - case NORMAL -> { - return normalPlus; + case WATER -> { + return waterPlus; } - case PREMIUM -> { - return premiumPlus; + case SUN -> { + return sunPlus; } - case SUPER -> { - return superPlus; + case NUTRIENT -> { + return nutrientPlus; } default -> { throw new BadRequestException("성장버튼 타입이 올바르지 않습니다."); @@ -97,13 +97,13 @@ private void levelUP() { } private int experienceToEarn(GrowthButton growthButton) { - return convertByGrowthButton(growthButton, NORMAL_PLUS, PREMIUM_PLUS, SUPER_PLUS); + return convertByGrowthButton(growthButton, WATER_PLUS, SUN_PLUS, NUTRIENT_PLUS); } public enum GrowthButton { - NORMAL, - PREMIUM, - SUPER + WATER, + SUN, + NUTRIENT } } diff --git a/src/main/java/com/gdg/kkia/point/entity/PointLog.java b/src/main/java/com/gdg/kkia/point/entity/PointLog.java index c69b73a..b7de010 100644 --- a/src/main/java/com/gdg/kkia/point/entity/PointLog.java +++ b/src/main/java/com/gdg/kkia/point/entity/PointLog.java @@ -63,7 +63,9 @@ public enum Type { ATTENDANCE_DAY_5_OR_MORE, DAILY_RESPONSE, DIARY, - PET_GROWTH, + GROWTH_WATER, + GROWTH_SUN, + GROWTH_NUTRIENT, CHAT_BOT } diff --git a/src/main/java/com/gdg/kkia/point/service/PointLogService.java b/src/main/java/com/gdg/kkia/point/service/PointLogService.java index 33168a2..c42e356 100644 --- a/src/main/java/com/gdg/kkia/point/service/PointLogService.java +++ b/src/main/java/com/gdg/kkia/point/service/PointLogService.java @@ -4,6 +4,7 @@ import com.gdg.kkia.common.exception.NotFoundException; import com.gdg.kkia.member.entity.Member; import com.gdg.kkia.member.repository.MemberRepository; +import com.gdg.kkia.pet.dto.PointAndPointLogType; import com.gdg.kkia.pet.entity.Pet; import com.gdg.kkia.point.dto.PointLogResponse; import com.gdg.kkia.point.dto.PointResponse; @@ -159,8 +160,8 @@ public void consumePointAndWriteLog(Member member, Pet.GrowthButton growthButton if (isMaxGrowth) { throw new BadRequestException("최고레벨입니다."); } - int point = member.consumePoint(growthButton); - PointLog newPointLog = new PointLog(PointLog.Type.PET_GROWTH, PointLog.Status.CONSUMED, member, point); + PointAndPointLogType pointAndButtonType = member.consumePoint(growthButton); + PointLog newPointLog = new PointLog(pointAndButtonType.pointLogType(), PointLog.Status.CONSUMED, member, pointAndButtonType.point()); pointLogRepository.save(newPointLog); } }