From 31481d362b972cfb02196d7be1490fc31b52afd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=ED=99=8D=EC=84=9D?= <78216059+bayy1216@users.noreply.github.com> Date: Thu, 4 Jul 2024 20:58:31 +0900 Subject: [PATCH] =?UTF-8?q?[Refactor]:=20=EB=AA=A8=EB=8D=B8=20=EC=97=94?= =?UTF-8?q?=ED=84=B0=ED=8B=B0=20->=20=EB=A0=88=EC=BD=94=EB=93=9C=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../challengegroup/ChallengeGroupRes.java | 62 +++++------ .../zzansuni/controller/user/UserRes.java | 18 ++-- .../challengegroup/ChallengeGroupModel.java | 100 +++++++++--------- .../challenge/ChallengeModel.java | 45 ++++---- .../zzansuni/domain/user/UserModel.java | 15 ++- 5 files changed, 120 insertions(+), 120 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/ChallengeGroupRes.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/ChallengeGroupRes.java index 988daad..3b83ab4 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/ChallengeGroupRes.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/ChallengeGroupRes.java @@ -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(); } @@ -72,26 +72,26 @@ public record Detail( public static Detail from( ChallengeGroupModel.Detail challengeGroupDetail ){ - List challenges = challengeGroupDetail - .getChallenges(); + List 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()) @@ -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(); } @@ -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(); } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserRes.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserRes.java index 60ac767..687461e 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserRes.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserRes.java @@ -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(); } @@ -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(); } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/ChallengeGroupModel.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/ChallengeGroupModel.java index 3bf9d8d..6c55644 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/ChallengeGroupModel.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/ChallengeGroupModel.java @@ -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 challenges; - + public record Info( + Long id, + ChallengeCategory category, + String title, + String content, + String guide, + Integer cumulativeCount, + List 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()) @@ -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 imageUrls; - private List challenges; - + public record Detail( + Long id, + ChallengeCategory category, + String title, + String content, + String guide, + Integer cumulativeCount, + List imageUrls, + List 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 challengeGroupImages) { var challenges = challengeGroup.getChallenges().stream() - .map(ChallengeModel::from) + .map(ChallengeModel.Main::from) .toList(); var imageUrls = challengeGroupImages.stream() .map(ChallengeGroupImage::getImageUrl) @@ -118,12 +114,12 @@ public static Detail from(ChallengeGroup challengeGroup, List