Skip to content

Commit

Permalink
[Feat]: UserRes에 MyRankingInfo 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
momnpa333 committed Oct 7, 2024
1 parent e3007f2 commit e5bc8dc
Showing 1 changed file with 68 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,84 +9,114 @@
import java.util.List;

public class UserRes {

@Builder
public record UserMyInfo(
Long id,
String nickname,
String profileImageUrl,
String email,
TierInfo tierInfo,
Role role
Long id,
String nickname,
String profileImageUrl,
String email,
TierInfo tierInfo,
Role role
) {

public static UserMyInfo from(UserModel.Main userMain) {
var tierInfo = TierInfo.from(userMain.exp());
return UserMyInfo.builder()
.id(userMain.id())
.nickname(userMain.nickname())
.profileImageUrl(userMain.profileImageUrl())
.email(userMain.email())
.tierInfo(tierInfo)
.role(userMain.role())
.build();
.id(userMain.id())
.nickname(userMain.nickname())
.profileImageUrl(userMain.profileImageUrl())
.email(userMain.email())
.tierInfo(tierInfo)
.role(userMain.role())
.build();
}
}

@Builder
public record User(
Long id,
String nickname,
String profileImageUrl,
TierInfo tierInfo
Long id,
String nickname,
String profileImageUrl,
TierInfo tierInfo
) {

public static User from(UserModel.Main userMain) {
var tierInfo = TierInfo.from(userMain.exp());
return User.builder()
.id(userMain.id())
.nickname(userMain.nickname())
.profileImageUrl(userMain.profileImageUrl())
.tierInfo(tierInfo)
.build();
.id(userMain.id())
.nickname(userMain.nickname())
.profileImageUrl(userMain.profileImageUrl())
.tierInfo(tierInfo)
.build();
}
}

@Builder
public record TierInfo(
String tier,
Integer totalExp,
Integer currentExp
String tier,
Integer totalExp,
Integer currentExp
) {

public static TierInfo from(Integer exp) {
var tier = TierSystem.getTier(exp);

return TierInfo.builder()
.tier(tier.getKorean())
.totalExp(tier.getEndExp() - tier.getStartExp()) // 티어 시작 경험치부터 끝 경험치까지
.currentExp(exp - tier.getStartExp()) // 현재 경험치 - 티어 시작 경험치
.build();
.tier(tier.getKorean())
.totalExp(tier.getEndExp() - tier.getStartExp()) // 티어 시작 경험치부터 끝 경험치까지
.currentExp(exp - tier.getStartExp()) // 현재 경험치 - 티어 시작 경험치
.build();
}
}

@Builder
public record Streak(
/** 여기서 Model의 DayCount를 사용해도 되는지 */
List<UserModel.DayCount> dayCounts
/** 여기서 Model의 DayCount를 사용해도 되는지 */
List<UserModel.DayCount> dayCounts
) {
public static Streak from(UserModel.Streak streak){

public static Streak from(UserModel.Streak streak) {
return Streak.builder()
.dayCounts(streak.dayCounts())
.build();
.dayCounts(streak.dayCounts())
.build();
}
}

/**
* 하루에 대한 스트릭 카운트
* 0인 것도 보낸다.
* 하루에 대한 스트릭 카운트 0인 것도 보낸다.
*/
@Builder
public record DayCount(
LocalDate date,
Integer count
LocalDate date,
Integer count
) {

}

@Builder
public record MyRankingInfo(
Long id,
String nickname,
String profileImageUrl,
String email,
TierInfo tierInfo,
Role role,
Integer rank
) {

public static MyRankingInfo from(UserModel.MyRanking myRanking) {
var tierInfo = TierInfo.from(myRanking.exp());
return MyRankingInfo.builder()
.id(myRanking.id())
.nickname(myRanking.nickname())
.profileImageUrl(myRanking.profileImageUrl())
.email(myRanking.email())
.tierInfo(tierInfo)
.rank(myRanking.rank())
.role(myRanking.role())
.build();
}
}

}

0 comments on commit e5bc8dc

Please sign in to comment.