Skip to content

Commit

Permalink
Merge pull request #39 from KNU-HAEDAL/refactor/naming
Browse files Browse the repository at this point in the history
[Refactor]: 모델 엔터티 -> 레코드로 변경
  • Loading branch information
bayy1216 authored Jul 4, 2024
2 parents 17b1639 + 31481d3 commit 7816365
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ public static Info from(
ChallengeGroupModel.Detail challengeGroupDetail
){
return Info.builder()
.id(challengeGroupDetail.getId())
.title(challengeGroupDetail.getTitle())
.content(challengeGroupDetail.getContent())
.participantCount(challengeGroupDetail.getCumulativeCount())
.id(challengeGroupDetail.id())
.title(challengeGroupDetail.title())
.content(challengeGroupDetail.content())
.participantCount(challengeGroupDetail.cumulativeCount())
.startDate(challengeGroupDetail.getMinStartDate())
.endDate(challengeGroupDetail.getMaxEndDate())
.category(challengeGroupDetail.getCategory())
.category(challengeGroupDetail.category())
.build();
}
public static Info from(
ChallengeGroupModel.Info challengeGroupInfo
){
return Info.builder()
.id(challengeGroupInfo.getId())
.title(challengeGroupInfo.getTitle())
.content(challengeGroupInfo.getContent())
.participantCount(challengeGroupInfo.getCumulativeCount())
.id(challengeGroupInfo.id())
.title(challengeGroupInfo.title())
.content(challengeGroupInfo.content())
.participantCount(challengeGroupInfo.cumulativeCount())
.startDate(challengeGroupInfo.getMinStartDate())
.endDate(challengeGroupInfo.getMaxEndDate())
.category(challengeGroupInfo.getCategory())
.category(challengeGroupInfo.category())
.build();
}

Expand All @@ -72,26 +72,26 @@ public record Detail(
public static Detail from(
ChallengeGroupModel.Detail challengeGroupDetail
){
List<ChallengeModel> challenges = challengeGroupDetail
.getChallenges();
List<ChallengeModel.Main> challenges = challengeGroupDetail
.challenges();

Integer maxDifficulty = challenges.stream()
.map(ChallengeModel::getDifficulty)
.map(ChallengeModel.Main::difficulty)
.max(Integer::compareTo)
.orElse(0);


return Detail.builder()
.id(challengeGroupDetail.getId())
.title(challengeGroupDetail.getTitle())
.content(challengeGroupDetail.getContent())
.participantCount(challengeGroupDetail.getCumulativeCount())
.id(challengeGroupDetail.id())
.title(challengeGroupDetail.title())
.content(challengeGroupDetail.content())
.participantCount(challengeGroupDetail.cumulativeCount())
.startDate(challengeGroupDetail.getMinStartDate())
.endDate(challengeGroupDetail.getMaxEndDate())
.category(challengeGroupDetail.getCategory())
.guide(challengeGroupDetail.getGuide())
.category(challengeGroupDetail.category())
.guide(challengeGroupDetail.guide())
.maxDifficulty(maxDifficulty)
.imageUrls(challengeGroupDetail.getImageUrls())
.imageUrls(challengeGroupDetail.imageUrls())
.challenges(challenges.stream()
.map(Challenge::from)
.toList())
Expand All @@ -112,16 +112,16 @@ public record Challenge(
Integer dayCount
) {
public static Challenge from(
ChallengeModel challenge
ChallengeModel.Main challenge
){
return Challenge.builder()
.id(challenge.getId())
.participantCount(challenge.getRequiredCount())
.difficulty(challenge.getDifficulty())
.onceExp(challenge.getOnceExp())
.successExp(challenge.getSuccessExp())
.dayType(challenge.getDayType())
.dayCount(challenge.getRequiredCount())
.id(challenge.id())
.participantCount(challenge.requiredCount())
.difficulty(challenge.difficulty())
.onceExp(challenge.onceExp())
.successExp(challenge.successExp())
.dayType(challenge.dayType())
.dayCount(challenge.requiredCount())
.build();
}

Expand Down Expand Up @@ -163,10 +163,10 @@ public record Ranking(
public static Ranking from(
ChallengeGroupModel.Ranking model
){
var user = UserRes.User.from(model.getUser());
var user = UserRes.User.from(model.user());
return Ranking.builder()
.ranking(model.getRank())
.acquiredPoint(model.getAccumulatedPoint())
.ranking(model.rank())
.acquiredPoint(model.accumulatedPoint())
.user(user)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public record UserInfo(
TierInfo tierInfo
) {
public static UserInfo from(UserModel userModel) {
var tierInfo = TierInfo.from(userModel.getExp());
var tierInfo = TierInfo.from(userModel.exp());
return UserInfo.builder()
.id(userModel.getId())
.nickname(userModel.getNickname())
.profileImageUrl(userModel.getProfileImageUrl())
.email(userModel.getEmail())
.id(userModel.id())
.nickname(userModel.nickname())
.profileImageUrl(userModel.profileImageUrl())
.email(userModel.email())
.tierInfo(tierInfo)
.build();
}
Expand All @@ -36,11 +36,11 @@ public record User(
TierInfo tierInfo
) {
public static User from(UserModel userModel) {
var tierInfo = TierInfo.from(userModel.getExp());
var tierInfo = TierInfo.from(userModel.exp());
return User.builder()
.id(userModel.getId())
.nickname(userModel.getNickname())
.profileImageUrl(userModel.getProfileImageUrl())
.id(userModel.id())
.nickname(userModel.nickname())
.profileImageUrl(userModel.profileImageUrl())
.tierInfo(tierInfo)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,52 @@
import java.util.List;

public class ChallengeGroupModel {
@Builder
@Getter
public static class Main {
private Long id;
private ChallengeCategory category;
private String title;
private String content;
private Integer cumulativeCount;

public record Main(
Long id,
ChallengeCategory category,
String title,
String content,
Integer cumulativeCount
) {
public static Main from(ChallengeGroup challengeGroup) {
return Main.builder()
.id(challengeGroup.getId())
.category(challengeGroup.getCategory())
.title(challengeGroup.getTitle())
.content(challengeGroup.getContent())
.cumulativeCount(challengeGroup.getCumulativeCount())
.build();
return new Main(
challengeGroup.getId(),
challengeGroup.getCategory(),
challengeGroup.getTitle(),
challengeGroup.getContent(),
challengeGroup.getCumulativeCount()
);
}
}

@Getter
@Builder
public static class Info {
private Long id;
private ChallengeCategory category;
private String title;
private String content;
private String guide;
private Integer cumulativeCount;
private List<ChallengeModel> challenges;

public record Info(
Long id,
ChallengeCategory category,
String title,
String content,
String guide,
Integer cumulativeCount,
List<ChallengeModel.Main> challenges
) {
public LocalDate getMinStartDate() {
return challenges.stream()
.map(ChallengeModel::getStartDate)
.map(ChallengeModel.Main::startDate)
.min(LocalDate::compareTo)
.orElse(LocalDate.now());
}

public LocalDate getMaxEndDate() {
return challenges.stream()
.map(ChallengeModel::getEndDate)
.map(ChallengeModel.Main::endDate)
.max(LocalDate::compareTo)
.orElse(LocalDate.now());
}

public static Info from(ChallengeGroup challengeGroup) {
var challenges = challengeGroup.getChallenges().stream()
.map(ChallengeModel::from)
.map(ChallengeModel.Main::from)
.toList();
return Info.builder()
.id(challengeGroup.getId())
Expand All @@ -71,36 +69,34 @@ public static Info from(ChallengeGroup challengeGroup) {
}
}


@Getter
@Builder
public static class Detail {
private Long id;
private ChallengeCategory category;
private String title;
private String content;
private String guide;
private Integer cumulativeCount;
private List<String> imageUrls;
private List<ChallengeModel> challenges;

public record Detail(
Long id,
ChallengeCategory category,
String title,
String content,
String guide,
Integer cumulativeCount,
List<String> imageUrls,
List<ChallengeModel.Main> challenges
) {
public LocalDate getMinStartDate() {
return challenges.stream()
.map(ChallengeModel::getStartDate)
.min(LocalDate::compareTo)
.orElse(LocalDate.now());
.map(ChallengeModel.Main::startDate)
.min(LocalDate::compareTo)
.orElse(LocalDate.now());
}

public LocalDate getMaxEndDate() {
return challenges.stream()
.map(ChallengeModel::getEndDate)
.max(LocalDate::compareTo)
.orElse(LocalDate.now());
.map(ChallengeModel.Main::endDate)
.max(LocalDate::compareTo)
.orElse(LocalDate.now());
}

public static Detail from(ChallengeGroup challengeGroup, List<ChallengeGroupImage> challengeGroupImages) {
var challenges = challengeGroup.getChallenges().stream()
.map(ChallengeModel::from)
.map(ChallengeModel.Main::from)
.toList();
var imageUrls = challengeGroupImages.stream()
.map(ChallengeGroupImage::getImageUrl)
Expand All @@ -118,12 +114,12 @@ public static Detail from(ChallengeGroup challengeGroup, List<ChallengeGroupImag
}
}

@Getter
@Builder
public static class Ranking {
private UserModel user;
private Integer rank;
private Integer accumulatedPoint;
public record Ranking(
UserModel user,
Integer rank,
Integer accumulatedPoint
) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,33 @@
@Builder
public class ChallengeModel {

private Long id;
private Integer requiredCount;
private DayType dayType;
private Integer onceExp;
private Integer successExp;
private Integer difficulty;
private LocalDate startDate;
private LocalDate endDate;

public static ChallengeModel from(Challenge challenge) {
return ChallengeModel.builder()
.id(challenge.getId())
.requiredCount(challenge.getRequiredCount())
.dayType(challenge.getDayType())
.onceExp(challenge.getOnceExp())
.successExp(challenge.getSuccessExp())
.difficulty(challenge.getDifficulty())
.startDate(challenge.getStartDate())
.endDate(challenge.getEndDate())
.build();

@Builder
public record Main(
Long id,
Integer requiredCount,
DayType dayType,
Integer onceExp,
Integer successExp,
Integer difficulty,
LocalDate startDate,
LocalDate endDate
) {
public static Main from(Challenge challenge) {
return Main.builder()
.id(challenge.getId())
.requiredCount(challenge.getRequiredCount())
.dayType(challenge.getDayType())
.onceExp(challenge.getOnceExp())
.successExp(challenge.getSuccessExp())
.difficulty(challenge.getDifficulty())
.startDate(challenge.getStartDate())
.endDate(challenge.getEndDate())
.build();
}
}


@Builder
public record ChallengeVerificationResult(Integer totalCount, Integer successCount,
Integer obtainExp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class UserModel {
private Long id;
private String email;
private String nickname;
private String profileImageUrl;
private Integer exp;

public record UserModel(
Long id,
String email,
String nickname,
String profileImageUrl,
Integer exp
) {
public static UserModel from(User user) {
return UserModel.builder()
.id(user.getId())
Expand Down

0 comments on commit 7816365

Please sign in to comment.