-
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: 나의 기록 조회 V2 작업(퍼센테이지 값 추가) (#299)
* Refactor: MemberService의 리턴 dto를 버전 별 공통으로 사용할 수 있게 변경 - MyProfileResponseV1를 추가 - 응답 형식 확인 테스트 코드는 컨트롤러 테스트에 추가 예정 * Feat: 나의 기록의 레벨 퍼센테이지 작업으로 V2 API 추가
- Loading branch information
Showing
7 changed files
with
114 additions
and
40 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
15 changes: 5 additions & 10 deletions
15
src/main/java/com/dnd/runus/presentation/v1/member/dto/response/MyProfileResponse.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 |
---|---|---|
@@ -1,17 +1,12 @@ | ||
package com.dnd.runus.presentation.v1.member.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public record MyProfileResponse( | ||
@Schema(description = "현재 프로필 이미지") | ||
String profileImageUrl, | ||
@Schema(description = "현재 레벨 이름") | ||
String currentLevelName, | ||
@Schema(description = "지금까지 달린 거리") | ||
String currentKm, | ||
@Schema(description = "다음 레벨 이름") | ||
String nextLevelName, | ||
@Schema(description = "다음 레벨까지 남은 거리") | ||
String nextLevelKm | ||
long currentLevel, | ||
int currentExpMeter, | ||
long nextLevel, | ||
int nextLevelStartExpMeter, | ||
int nextLevelEndExpMeter | ||
) { | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/dnd/runus/presentation/v1/member/dto/response/MyProfileResponseV1.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,29 @@ | ||
package com.dnd.runus.presentation.v1.member.dto.response; | ||
|
||
import com.dnd.runus.domain.level.Level; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public record MyProfileResponseV1( | ||
@Schema(description = "현재 프로필 이미지") | ||
String profileImageUrl, | ||
@Schema(description = "현재 레벨 이름") | ||
String currentLevelName, | ||
@Schema(description = "지금까지 달린 거리") | ||
String currentKm, | ||
@Schema(description = "다음 레벨 이름") | ||
String nextLevelName, | ||
@Schema(description = "다음 레벨까지 남은 거리") | ||
String nextLevelKm | ||
) { | ||
|
||
public static MyProfileResponseV1 from(MyProfileResponse myProfileResponse) { | ||
return new MyProfileResponseV1( | ||
myProfileResponse.profileImageUrl(), | ||
Level.formatLevelName(myProfileResponse.currentLevel()), | ||
Level.formatExp(myProfileResponse.currentExpMeter()), | ||
Level.formatLevelName(myProfileResponse.nextLevel()), | ||
Level.formatExp(myProfileResponse.nextLevelEndExpMeter() | ||
- myProfileResponse.currentExpMeter()) | ||
); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/dnd/runus/presentation/v2/member/MemberProfileControllerV2.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,32 @@ | ||
package com.dnd.runus.presentation.v2.member; | ||
|
||
import com.dnd.runus.application.member.MemberService; | ||
import com.dnd.runus.presentation.annotation.MemberId; | ||
import com.dnd.runus.presentation.v1.member.dto.response.MyProfileResponse; | ||
import com.dnd.runus.presentation.v2.member.dto.response.MyProfileResponseV2; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("api/v2/members/profiles") | ||
public class MemberProfileControllerV2 { | ||
private final MemberService memberService; | ||
|
||
@GetMapping("me") | ||
@ResponseStatus(HttpStatus.OK) | ||
public MyProfileResponseV2 getMyProfile(@MemberId long memberId) { | ||
MyProfileResponse myProfile = memberService.getMyProfile(memberId); | ||
|
||
// 퍼센테이지 | ||
double leftNextLevelKm = myProfile.nextLevelEndExpMeter() - myProfile.currentExpMeter(); | ||
double divisor = myProfile.nextLevelEndExpMeter() - myProfile.nextLevelStartExpMeter(); | ||
double percentage = 1 - (leftNextLevelKm / divisor); | ||
|
||
return MyProfileResponseV2.of(myProfile, percentage); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/dnd/runus/presentation/v2/member/dto/response/MyProfileResponseV2.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,36 @@ | ||
package com.dnd.runus.presentation.v2.member.dto.response; | ||
|
||
|
||
import com.dnd.runus.domain.level.Level; | ||
import com.dnd.runus.presentation.v1.member.dto.response.MyProfileResponse; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public record MyProfileResponseV2 ( | ||
@Schema(description = "현재 프로필 이미지") | ||
String profileImageUrl, | ||
@Schema(description = "현재 레벨 이름") | ||
String currentLevelName, | ||
@Schema(description = "지금까지 달린 거리") | ||
String currentKm, | ||
@Schema(description = "다음 레벨 이름") | ||
String nextLevelName, | ||
@Schema(description = "다음 레벨까지 남은 거리") | ||
String nextLevelKm, | ||
@Schema(description = "퍼센테이지값", example = "0.728") | ||
double percentage | ||
|
||
) { | ||
|
||
public static MyProfileResponseV2 of(MyProfileResponse myProfileResponse, double percentage) { | ||
return new MyProfileResponseV2( | ||
myProfileResponse.profileImageUrl(), | ||
Level.formatLevelName(myProfileResponse.currentLevel()), | ||
Level.formatExp(myProfileResponse.currentExpMeter()), | ||
Level.formatLevelName(myProfileResponse.nextLevel()), | ||
Level.formatExp(myProfileResponse.nextLevelEndExpMeter() | ||
- myProfileResponse.currentExpMeter()), | ||
percentage | ||
); | ||
} | ||
|
||
} |
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