Skip to content

Commit

Permalink
Feat: Challenge 테이블에 isActive 컬럼 추가 (#315)
Browse files Browse the repository at this point in the history
* Feat: Challenge 테이블에 isActive 컬럼 추가

* Fix: Challenge 테이블에 isActive 컬럼 추가로 테스트 코드 수정
  • Loading branch information
hee9841 authored Dec 4, 2024
1 parent e26dae1 commit 9ffea72
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 18 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/dnd/runus/domain/challenge/Challenge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public List<Challenge> 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()))
Expand All @@ -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,
Expand All @@ -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));
}
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE challenge
ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT TRUE;

UPDATE challenge
SET is_active = TRUE;
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChallengesResponse> challenges = challengeService.getChallenges(member.memberId());
Expand All @@ -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<ChallengesResponse> challenges = challengeService.getChallenges(member.memberId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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인지 확인")
Expand Down

0 comments on commit 9ffea72

Please sign in to comment.