Skip to content

Commit

Permalink
feat(challenge): 챌린지 3일 기록에 연속진행일수 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
wwingyou committed Jan 28, 2025
1 parent 676b91b commit 3b4db0e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
23 changes: 13 additions & 10 deletions src/main/java/com/goolbitg/api/service/ChallengeServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,20 @@ public ChallengeStatDto getChallengeStat(Long challengeId) {
public ChallengeTrippleDto getChallengeTripple(Long challengeId) {
String userId = AuthUtil.getLoginUserId();
LocalDate date = getToday();
ChallengeRecordId id = new ChallengeRecordId(challengeId, userId, date);
Optional<ChallengeRecord> result = challengeRecordRepository.findById(id);
if (result.isEmpty()) {
throw ChallengeException.challengeRecordNotExist(challengeId);
}
ChallengeRecordId recordId = new ChallengeRecordId(challengeId, userId, date);
ChallengeRecord currentRecord = challengeRecordRepository.findById(recordId)
.orElseThrow(() -> ChallengeException.challengeNotExist(challengeId));
ChallengeStatId statId = new ChallengeStatId(challengeId, userId);
ChallengeStat stat = challengeStatRepository.findById(statId).get();

List<ChallengeRecord> records = new ArrayList<>();
ChallengeRecord currentRecord = result.get();
date = date.minusDays(currentRecord.getLocation());
for (int i = 0; i < 3; i++) {
id = new ChallengeRecordId(challengeId, userId, date);
records.add(challengeRecordRepository.findById(id).get());
recordId = new ChallengeRecordId(challengeId, userId, date);
records.add(challengeRecordRepository.findById(recordId).get());
date = date.plusDays(1);
}
return getChallengeTrippleDto(challengeId, records, currentRecord);
return getChallengeTrippleDto(challengeId, records, currentRecord, stat);
}


Expand Down Expand Up @@ -297,9 +296,13 @@ private ChallengeStatDto getChallengeStatDto(ChallengeStat stat) {
return dto;
}

private ChallengeTrippleDto getChallengeTrippleDto(Long challengeId, List<ChallengeRecord> records, ChallengeRecord currentRecord) {
private ChallengeTrippleDto getChallengeTrippleDto(Long challengeId, List<ChallengeRecord> records, ChallengeRecord currentRecord, ChallengeStat stat) {
ChallengeTrippleDto dto = new ChallengeTrippleDto();
dto.setChallengeId(challengeId);
if (currentRecord.getStatus() == ChallengeRecordStatus.WAIT)
dto.setDuration(stat.getContinueCount() + 1);
else
dto.setDuration(stat.getContinueCount());
dto.setCheck1(records.get(0).getStatus());
dto.setCheck2(records.get(1).getStatus());
dto.setCheck3(records.get(2).getStatus());
Expand Down
13 changes: 9 additions & 4 deletions src/main/resources/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,8 @@ paths:
description: >
오늘 도전중인 3일치 챌린지 정보를 가져옵니다.<br><br>
`location` 필드는 오늘 챌린지 기록이 3일중 몇번째인지 나타내는 수입니다.<br>
0, 1, 2가 가능합니다.
1, 2, 3이 가능합니다.<br><br>
`duratoin`은 오늘이 며칠째 도전일인지를 나타냅니다.
tags:
- Challenge
parameters:
Expand Down Expand Up @@ -1547,6 +1548,10 @@ components:
type: integer
format: int64
example: 1
duration:
type: integer
example: 7
description: 오늘이 몇 번째 연속 도전중일인지 나타내는 수
check1:
$ref: '#/components/schemas/ChallengeRecordStatus'
check2:
Expand All @@ -1555,9 +1560,9 @@ components:
$ref: '#/components/schemas/ChallengeRecordStatus'
location:
type: integer
minimum: 0
maximum: 2
description: 오늘 날짜가 몇 번째인지 나타내는 수 (0~2)
minimum: 1
maximum: 3
description: 오늘 날짜가 몇 번째인지 나타내는 수 (1~3)
ChallengeStatDto:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ void get_challenge_tripple() throws Exception {
mockMvc.perform(get("/challengeTripple/{challengeId}", challengeId))
.andExpect(status().isOk())
.andExpect(jsonPath("$.challengeId").value(challengeId))
.andExpect(jsonPath("$.duration").value(2))
.andExpect(jsonPath("$.check1").value("SUCCESS"))
.andExpect(jsonPath("$.check2").value("WAIT"))
.andExpect(jsonPath("$.check3").value("WAIT"))
Expand Down

0 comments on commit 3b4db0e

Please sign in to comment.