Skip to content

Commit

Permalink
Feat: 챌린지 목록 조회 리파지토리 추가(업데이트를 위한 조건 값까지 함께 조회) (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
hee9841 authored Dec 7, 2024
1 parent 9ffea72 commit d9dab57
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ public interface ChallengeRepository {

List<Challenge> findAllIsNotDefeatYesterday();

List<ChallengeWithCondition> findAllActiveChallengesWithConditions();

Optional<ChallengeWithCondition> findChallengeWithConditionsByChallengeId(long challengeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public List<Challenge> findAllIsNotDefeatYesterday() {
return jooqChallengeRepository.findAllIsNotDefeatYesterday();
}

@Override
public List<ChallengeWithCondition> findAllActiveChallengesWithConditions() {
return jooqChallengeRepository.findAllActiveChallengesWithConditions();
}

@Override
public Optional<ChallengeWithCondition> findChallengeWithConditionsByChallengeId(long challengeId) {
return Optional.ofNullable(jooqChallengeRepository.findChallengeWithConditionsBy(challengeId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ public ChallengeWithCondition findChallengeWithConditionsBy(long challengeId) {
.fetchOne(new ChallengeWithConditionMapper());
}

public List<ChallengeWithCondition> findAllActiveChallengesWithConditions() {
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,
CHALLENGE_GOAL_CONDITION.COMPARISON_TYPE,
CHALLENGE_GOAL_CONDITION.GOAL_VALUE)
.from(CHALLENGE_GOAL_CONDITION)
.where(CHALLENGE_GOAL_CONDITION.CHALLENGE_ID.eq(CHALLENGE.ID)))
.convertFrom(r -> r.map(record -> new ChallengeCondition(
record.get(CHALLENGE_GOAL_CONDITION.GOAL_TYPE, GoalMetricType.class),
record.get(CHALLENGE_GOAL_CONDITION.COMPARISON_TYPE, ComparisonType.class),
record.get(CHALLENGE_GOAL_CONDITION.GOAL_VALUE, Integer.class))))
.as("conditions"))
.from(CHALLENGE)
.where(CHALLENGE.IS_ACTIVE.eq(true))
.fetch(new ChallengeWithConditionMapper());
}

private static class ChallengeMapper implements RecordMapper<Record, Challenge> {

@Override
Expand Down

0 comments on commit d9dab57

Please sign in to comment.