From 9ffea72a329f278b35a82337e1435e6d07f82b8b Mon Sep 17 00:00:00 2001 From: sungHeeLee <70899677+hee9841@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:32:28 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20Challenge=20=ED=85=8C=EC=9D=B4=EB=B8=94?= =?UTF-8?q?=EC=97=90=20isActive=20=EC=BB=AC=EB=9F=BC=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20(#315)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Feat: Challenge 테이블에 isActive 컬럼 추가 * Fix: Challenge 테이블에 isActive 컬럼 추가로 테스트 코드 수정 --- .../dnd/runus/domain/challenge/Challenge.java | 12 +++++++++--- .../JooqChallengeAchievementRepository.java | 2 ++ .../challenge/JooqChallengeRepository.java | 6 ++++++ .../jpa/challenge/entity/ChallengeEntity.java | 6 +++++- .../V5.0.14__add_challenge_is_active.sql | 5 +++++ .../challenge/ChallengeServiceTest.java | 18 +++++++++--------- .../running/RunningRecordServiceTest.java | 6 +++--- ...chievementPercentageRepositoryImplTest.java | 2 +- ...ChallengeAchievementRepositoryImplTest.java | 2 +- 9 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 src/main/resources/db/migration/V5.0.14__add_challenge_is_active.sql diff --git a/src/main/java/com/dnd/runus/domain/challenge/Challenge.java b/src/main/java/com/dnd/runus/domain/challenge/Challenge.java index 3b704a51..52c0aa89 100644 --- a/src/main/java/com/dnd/runus/domain/challenge/Challenge.java +++ b/src/main/java/com/dnd/runus/domain/challenge/Challenge.java @@ -3,10 +3,16 @@ import static com.dnd.runus.global.constant.MetricsConversionFactor.SECONDS_PER_HOUR; import static com.dnd.runus.global.constant.MetricsConversionFactor.SECONDS_PER_MINUTE; -public record Challenge(long challengeId, String name, int expectedTime, String imageUrl, ChallengeType challengeType) { +public record Challenge( + long challengeId, + String name, + int expectedTime, + String imageUrl, + boolean isActive, + ChallengeType challengeType) { - public Challenge(long challengeId, String name, String imageUrl, ChallengeType challengeType) { - this(challengeId, name, 0, imageUrl, challengeType); + public Challenge(long challengeId, String name, String imageUrl, boolean isActive, ChallengeType challengeType) { + this(challengeId, name, 0, imageUrl, isActive, challengeType); } public boolean isDefeatYesterdayChallenge() { diff --git a/src/main/java/com/dnd/runus/infrastructure/persistence/jooq/challenge/JooqChallengeAchievementRepository.java b/src/main/java/com/dnd/runus/infrastructure/persistence/jooq/challenge/JooqChallengeAchievementRepository.java index 231e202d..0df0c8cc 100644 --- a/src/main/java/com/dnd/runus/infrastructure/persistence/jooq/challenge/JooqChallengeAchievementRepository.java +++ b/src/main/java/com/dnd/runus/infrastructure/persistence/jooq/challenge/JooqChallengeAchievementRepository.java @@ -23,6 +23,7 @@ public ChallengeAchievement.Status findStatusByRunningRecordId(long runningRecor CHALLENGE.NAME, CHALLENGE.EXPECTED_TIME, CHALLENGE.IMAGE_URL, + CHALLENGE.IS_ACTIVE, CHALLENGE.CHALLENGE_TYPE) .from(CHALLENGE_ACHIEVEMENT) .join(CHALLENGE) @@ -35,6 +36,7 @@ public ChallengeAchievement.Status findStatusByRunningRecordId(long runningRecor record.get(CHALLENGE.NAME, String.class), record.get(CHALLENGE.EXPECTED_TIME, Integer.class), record.get(CHALLENGE.IMAGE_URL, String.class), + record.get(CHALLENGE.IS_ACTIVE, Boolean.class), ChallengeType.valueOf(record.get(CHALLENGE.CHALLENGE_TYPE, String.class))), record.get(CHALLENGE_ACHIEVEMENT.SUCCESS_STATUS))); } diff --git a/src/main/java/com/dnd/runus/infrastructure/persistence/jooq/challenge/JooqChallengeRepository.java b/src/main/java/com/dnd/runus/infrastructure/persistence/jooq/challenge/JooqChallengeRepository.java index 4cd34dba..55ca0bb1 100644 --- a/src/main/java/com/dnd/runus/infrastructure/persistence/jooq/challenge/JooqChallengeRepository.java +++ b/src/main/java/com/dnd/runus/infrastructure/persistence/jooq/challenge/JooqChallengeRepository.java @@ -31,6 +31,7 @@ public List findAllIsNotDefeatYesterday() { CHALLENGE.NAME, CHALLENGE.EXPECTED_TIME, CHALLENGE.IMAGE_URL, + CHALLENGE.IS_ACTIVE, CHALLENGE.CHALLENGE_TYPE) .from(CHALLENGE) .where(CHALLENGE.CHALLENGE_TYPE.ne(ChallengeType.DEFEAT_YESTERDAY.toString())) @@ -41,7 +42,9 @@ public ChallengeWithCondition findChallengeWithConditionsBy(long challengeId) { return dsl.select( CHALLENGE.ID, CHALLENGE.NAME, + CHALLENGE.EXPECTED_TIME, CHALLENGE.IMAGE_URL, + CHALLENGE.IS_ACTIVE, CHALLENGE.CHALLENGE_TYPE, multiset(select( CHALLENGE_GOAL_CONDITION.GOAL_TYPE, @@ -68,6 +71,7 @@ public Challenge map(Record record) { record.get(CHALLENGE.NAME, String.class), record.get(CHALLENGE.EXPECTED_TIME, int.class), record.get(CHALLENGE.IMAGE_URL, String.class), + record.get(CHALLENGE.IS_ACTIVE, Boolean.class), record.get(CHALLENGE.CHALLENGE_TYPE, ChallengeType.class)); } } @@ -87,7 +91,9 @@ public ChallengeWithCondition map(Record record) { new Challenge( record.get(CHALLENGE.ID, long.class), record.get(CHALLENGE.NAME, String.class), + record.get(CHALLENGE.EXPECTED_TIME, int.class), record.get(CHALLENGE.IMAGE_URL, String.class), + record.get(CHALLENGE.IS_ACTIVE, Boolean.class), record.get(CHALLENGE.CHALLENGE_TYPE, ChallengeType.class)), challengeConditions); } diff --git a/src/main/java/com/dnd/runus/infrastructure/persistence/jpa/challenge/entity/ChallengeEntity.java b/src/main/java/com/dnd/runus/infrastructure/persistence/jpa/challenge/entity/ChallengeEntity.java index 8816b3ed..4b199cf7 100644 --- a/src/main/java/com/dnd/runus/infrastructure/persistence/jpa/challenge/entity/ChallengeEntity.java +++ b/src/main/java/com/dnd/runus/infrastructure/persistence/jpa/challenge/entity/ChallengeEntity.java @@ -37,17 +37,21 @@ public class ChallengeEntity { @NotNull private String imageUrl; + @NotNull + private Boolean isActive; + public static ChallengeEntity from(Challenge challenge) { return ChallengeEntity.builder() .id(challenge.challengeId() == 0 ? null : challenge.challengeId()) .name(challenge.name()) .expectedTime(challenge.expectedTime()) + .isActive(challenge.isActive()) .challengeType(challenge.challengeType()) .imageUrl(challenge.imageUrl()) .build(); } public Challenge toDomain() { - return new Challenge(id, name, expectedTime, imageUrl, challengeType); + return new Challenge(id, name, expectedTime, imageUrl, isActive, challengeType); } } diff --git a/src/main/resources/db/migration/V5.0.14__add_challenge_is_active.sql b/src/main/resources/db/migration/V5.0.14__add_challenge_is_active.sql new file mode 100644 index 00000000..119d886e --- /dev/null +++ b/src/main/resources/db/migration/V5.0.14__add_challenge_is_active.sql @@ -0,0 +1,5 @@ +ALTER TABLE challenge + ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT TRUE; + +UPDATE challenge +SET is_active = TRUE; diff --git a/src/test/java/com/dnd/runus/application/challenge/ChallengeServiceTest.java b/src/test/java/com/dnd/runus/application/challenge/ChallengeServiceTest.java index 80b4c88b..20d5328e 100644 --- a/src/test/java/com/dnd/runus/application/challenge/ChallengeServiceTest.java +++ b/src/test/java/com/dnd/runus/application/challenge/ChallengeServiceTest.java @@ -54,12 +54,12 @@ void getChallengesWithYesterdayRecords() { given(challengeRepository.findAllChallenges()) .willReturn(List.of( - new Challenge(1L, "어제보다 1km더 뛰기", "imageUrl", ChallengeType.DEFEAT_YESTERDAY), - new Challenge(2L, "어제보다 5분 더 뛰기", "imageUrl", ChallengeType.DEFEAT_YESTERDAY), - new Challenge(3L, "어제보다 평균 페이스 10초 빠르게", "imageUrl", ChallengeType.DEFEAT_YESTERDAY), - new Challenge(4L, "오늘 5km 뛰기", "imageUrl", ChallengeType.TODAY), - new Challenge(5L, "오늘 30분 뛰기", "imageUrl", ChallengeType.TODAY), - new Challenge(6L, "1km 6분안에 뛰기", "imageUrl", ChallengeType.DISTANCE_IN_TIME))); + new Challenge(1L, "어제보다 1km더 뛰기", "imageUrl", true, ChallengeType.DEFEAT_YESTERDAY), + new Challenge(2L, "어제보다 5분 더 뛰기", "imageUrl", true, ChallengeType.DEFEAT_YESTERDAY), + new Challenge(3L, "어제보다 평균 페이스 10초 빠르게", "imageUrl", true, ChallengeType.DEFEAT_YESTERDAY), + new Challenge(4L, "오늘 5km 뛰기", "imageUrl", true, ChallengeType.TODAY), + new Challenge(5L, "오늘 30분 뛰기", "imageUrl", true, ChallengeType.TODAY), + new Challenge(6L, "1km 6분안에 뛰기", "imageUrl", true, ChallengeType.DISTANCE_IN_TIME))); // when List challenges = challengeService.getChallenges(member.memberId()); @@ -78,9 +78,9 @@ void getChallengesWithoutYesterdayRecords() { given(challengeRepository.findAllIsNotDefeatYesterday()) .willReturn(List.of( - new Challenge(4L, "오늘 5km 뛰기", "imageUrl", ChallengeType.TODAY), - new Challenge(5L, "오늘 30분 뛰기", "imageUrl", ChallengeType.TODAY), - new Challenge(6L, "1km 6분안에 뛰기", "imageUrl", ChallengeType.DISTANCE_IN_TIME))); + new Challenge(4L, "오늘 5km 뛰기", "imageUrl", true, ChallengeType.TODAY), + new Challenge(5L, "오늘 30분 뛰기", "imageUrl", true, ChallengeType.TODAY), + new Challenge(6L, "1km 6분안에 뛰기", "imageUrl", true, ChallengeType.DISTANCE_IN_TIME))); // when List challenges = challengeService.getChallenges(member.memberId()); diff --git a/src/test/java/com/dnd/runus/application/running/RunningRecordServiceTest.java b/src/test/java/com/dnd/runus/application/running/RunningRecordServiceTest.java index 96c8c891..2a8e18fa 100644 --- a/src/test/java/com/dnd/runus/application/running/RunningRecordServiceTest.java +++ b/src/test/java/com/dnd/runus/application/running/RunningRecordServiceTest.java @@ -165,8 +165,8 @@ void getRunningRecord_challenge() { "end location", RunningEmoji.VERY_GOOD); - ChallengeAchievement.Status challengeAchievementStatus = - new ChallengeAchievement.Status(1L, new Challenge(1L, "challenge", "image", ChallengeType.TODAY), true); + ChallengeAchievement.Status challengeAchievementStatus = new ChallengeAchievement.Status( + 1L, new Challenge(1L, "challenge", "image", true, ChallengeType.TODAY), true); given(runningRecordRepository.findById(runningRecordId)).willReturn(Optional.of(runningRecord)); given(challengeAchievementRepository.findByRunningRecordId(runningRecordId)) @@ -204,7 +204,7 @@ void addRunningRecord_challenge() { RunningRecord expected = createRunningRecord(request, member); ChallengeWithCondition challengeWithCondition = new ChallengeWithCondition( - new Challenge(1L, "challenge", "image", ChallengeType.TODAY), + new Challenge(1L, "challenge", "image", true, ChallengeType.TODAY), List.of(new ChallengeCondition( GoalMetricType.DISTANCE, ComparisonType.GREATER_THAN_OR_EQUAL_TO, 10_000))); ChallengeAchievement challengeAchievement = diff --git a/src/test/java/com/dnd/runus/infrastructure/persistence/domain/challenge/ChallengeAchievementPercentageRepositoryImplTest.java b/src/test/java/com/dnd/runus/infrastructure/persistence/domain/challenge/ChallengeAchievementPercentageRepositoryImplTest.java index 1da1a139..ce7767eb 100644 --- a/src/test/java/com/dnd/runus/infrastructure/persistence/domain/challenge/ChallengeAchievementPercentageRepositoryImplTest.java +++ b/src/test/java/com/dnd/runus/infrastructure/persistence/domain/challenge/ChallengeAchievementPercentageRepositoryImplTest.java @@ -75,7 +75,7 @@ void setUp() { RunningEmoji.SOSO))); } - Challenge challenge = new Challenge(1, "name", 60, "imageUrl", ChallengeType.DEFEAT_YESTERDAY); + Challenge challenge = new Challenge(1, "name", 60, "imageUrl", true, ChallengeType.DEFEAT_YESTERDAY); savedChallengeAchievements = new ArrayList<>(); for (int i = 0; i < 2; i++) { diff --git a/src/test/java/com/dnd/runus/infrastructure/persistence/domain/challenge/ChallengeAchievementRepositoryImplTest.java b/src/test/java/com/dnd/runus/infrastructure/persistence/domain/challenge/ChallengeAchievementRepositoryImplTest.java index 2f403975..e2e193bd 100644 --- a/src/test/java/com/dnd/runus/infrastructure/persistence/domain/challenge/ChallengeAchievementRepositoryImplTest.java +++ b/src/test/java/com/dnd/runus/infrastructure/persistence/domain/challenge/ChallengeAchievementRepositoryImplTest.java @@ -72,7 +72,7 @@ void setUp() { for (int i = 0; i < 2; i++) { savedRunningRecords.add(runningRecordRepository.save(runningRecord)); } - challenge = new Challenge(0, "name", 60, "imageUrl", ChallengeType.DEFEAT_YESTERDAY); + challenge = new Challenge(0, "name", 60, "imageUrl", true, ChallengeType.DEFEAT_YESTERDAY); } @DisplayName("ChallengeAchievement 저장시, 성공여부가 true인지 확인")