-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: running record id로 러닝 기록 조회 api 추가 (#226)
- Loading branch information
Showing
4 changed files
with
160 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...n/java/com/dnd/runus/presentation/v1/running/dto/response/RunningRecordQueryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.dnd.runus.presentation.v1.running.dto.response; | ||
|
||
import com.dnd.runus.domain.challenge.achievement.ChallengeAchievement; | ||
import com.dnd.runus.domain.goalAchievement.GoalAchievement; | ||
import com.dnd.runus.domain.running.RunningRecord; | ||
import com.dnd.runus.global.constant.RunningEmoji; | ||
import com.dnd.runus.presentation.v1.running.dto.ChallengeDto; | ||
import com.dnd.runus.presentation.v1.running.dto.GoalResultDto; | ||
import com.dnd.runus.presentation.v1.running.dto.RunningRecordMetricsDto; | ||
import com.dnd.runus.presentation.v1.running.dto.request.RunningAchievementMode; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record RunningRecordQueryResponse( | ||
long runningRecordId, | ||
@Schema(description = "러닝 시작 시간") | ||
LocalDateTime startAt, | ||
@Schema(description = "러닝 종료 시간") | ||
LocalDateTime endAt, | ||
@NotNull | ||
@Schema(description = "감정 표현, very-good: 최고, good: 좋음, soso: 보통, bad: 나쁨, very-bad: 최악") | ||
RunningEmoji emotion, | ||
@NotNull | ||
@Schema(description = "달성 모드, normal: 일반(목표 설정 X), challenge: 챌린지, goal: 목표") | ||
RunningAchievementMode achievementMode, | ||
@Schema(description = "챌린지 정보, achievementMode가 challenge인 경우에만 값이 존재합니다.") | ||
ChallengeDto challenge, | ||
@Schema(description = "목표 결과 정보, achievementMode가 goal인 경우에만 값이 존재합니다.") | ||
GoalResultDto goal, | ||
@NotNull | ||
RunningRecordMetricsDto runningData | ||
) { | ||
public static RunningRecordQueryResponse from(RunningRecord runningRecord) { | ||
return buildResponse(runningRecord, null, null, RunningAchievementMode.NORMAL); | ||
} | ||
|
||
public static RunningRecordQueryResponse of(RunningRecord runningRecord, ChallengeAchievement achievement) { | ||
return buildResponse(runningRecord, | ||
new ChallengeDto( | ||
achievement.challenge().challengeId(), | ||
achievement.challenge().name(), | ||
achievement.description(), | ||
achievement.challenge().imageUrl(), | ||
achievement.isSuccess() | ||
), | ||
null, | ||
RunningAchievementMode.CHALLENGE | ||
); | ||
} | ||
|
||
public static RunningRecordQueryResponse of(RunningRecord runningRecord, GoalAchievement achievement) { | ||
return buildResponse(runningRecord, | ||
null, | ||
new GoalResultDto( | ||
achievement.getTitle(), | ||
achievement.getDescription(), | ||
achievement.getIconUrl(), | ||
achievement.isAchieved() | ||
), | ||
RunningAchievementMode.GOAL | ||
); | ||
} | ||
|
||
private static RunningRecordQueryResponse buildResponse(RunningRecord runningRecord, ChallengeDto challenge, GoalResultDto goal, RunningAchievementMode achievementMode) { | ||
return new RunningRecordQueryResponse( | ||
runningRecord.runningId(), | ||
runningRecord.startAt().toLocalDateTime(), | ||
runningRecord.endAt().toLocalDateTime(), | ||
runningRecord.emoji(), | ||
achievementMode, | ||
challenge, | ||
goal, | ||
new RunningRecordMetricsDto( | ||
runningRecord.averagePace(), | ||
runningRecord.duration(), | ||
runningRecord.distanceMeter(), | ||
runningRecord.calorie() | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters