Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/#86 #91

Merged
merged 7 commits into from
Sep 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,33 @@ public record Info(
ChallengeCategory category

) {

public static Info from(
ChallengeGroupModel.Detail challengeGroupDetail
){
) {
return Info.builder()
.id(challengeGroupDetail.id())
.title(challengeGroupDetail.title())
.content(challengeGroupDetail.content())
.participantCount(challengeGroupDetail.cumulativeCount())
.startDate(challengeGroupDetail.getMinStartDate())
.endDate(challengeGroupDetail.getMaxEndDate())
.category(challengeGroupDetail.category())
.build();
.id(challengeGroupDetail.id())
.title(challengeGroupDetail.title())
.content(challengeGroupDetail.content())
.participantCount(challengeGroupDetail.cumulativeCount())
.startDate(challengeGroupDetail.joinStartDate())
.endDate(challengeGroupDetail.joinEndDate())
.category(challengeGroupDetail.category())
.build();
}

public static Info from(
ChallengeGroupModel.Info challengeGroupInfo
){
ChallengeGroupModel.Info challengeGroupInfo
) {
return Info.builder()
.id(challengeGroupInfo.id())
.title(challengeGroupInfo.title())
.content(challengeGroupInfo.content())
.participantCount(challengeGroupInfo.cumulativeCount())
.startDate(challengeGroupInfo.getMinStartDate())
.endDate(challengeGroupInfo.getMaxEndDate())
.category(challengeGroupInfo.category())
.build();
.id(challengeGroupInfo.id())
.title(challengeGroupInfo.title())
.content(challengeGroupInfo.content())
.participantCount(challengeGroupInfo.cumulativeCount())
.startDate(challengeGroupInfo.joinStartDate())
.endDate(challengeGroupInfo.joinEndDate())
.category(challengeGroupInfo.category())
.build();
}

}
Expand All @@ -69,9 +71,10 @@ public record Detail(
List<String> imageUrls,
List<Challenge> challenges
) {

public static Detail from(
ChallengeGroupModel.Detail challengeGroupDetail
){
ChallengeGroupModel.Detail challengeGroupDetail
) {
List<ChallengeModel.Main> challenges = challengeGroupDetail
.challenges();

Expand All @@ -80,14 +83,13 @@ public static Detail from(
.max(Integer::compareTo)
.orElse(0);


return Detail.builder()
.id(challengeGroupDetail.id())
.title(challengeGroupDetail.title())
.content(challengeGroupDetail.content())
.participantCount(challengeGroupDetail.cumulativeCount())
.startDate(challengeGroupDetail.getMinStartDate())
.endDate(challengeGroupDetail.getMaxEndDate())
.startDate(challengeGroupDetail.joinStartDate())
.endDate(challengeGroupDetail.joinEndDate())
.category(challengeGroupDetail.category())
.guide(challengeGroupDetail.guide())
.maxDifficulty(maxDifficulty)
Expand All @@ -103,49 +105,46 @@ public static Detail from(
@Builder
public record Challenge(
Long id,
Integer participantCount,

Integer difficulty,
Integer onceExp,
Integer successExp,
Integer dayCount
Integer count
) {

public static Challenge from(
ChallengeModel.Main challenge
){
) {
return Challenge.builder()
.id(challenge.id())
.participantCount(challenge.requiredCount())
.difficulty(challenge.difficulty())
.onceExp(challenge.onceExp())
.successExp(challenge.successExp())
.dayCount(challenge.requiredCount())
.count(challenge.requiredCount())
.build();
}

}




@Builder
public record RankingPagingResponse(
List<ChallengeGroupRes.Ranking> data,
Integer totalPage,
ChallengeGroupRes.Ranking myRanking //null์ด๋ฉด ๋žญํ‚น์ด ์—†๋Š” ๊ฒƒ
List<ChallengeGroupRes.Ranking> data,
Integer totalPage,
ChallengeGroupRes.Ranking myRanking //null์ด๋ฉด ๋žญํ‚น์ด ์—†๋Š” ๊ฒƒ
) {

public static RankingPagingResponse from(
Page<ChallengeGroupRankingModel.Main> rankingPage,
ChallengeGroupRankingModel.Main myRanking
){
Page<ChallengeGroupRankingModel.Main> rankingPage,
ChallengeGroupRankingModel.Main myRanking
) {
var data = rankingPage.getContent().stream()
.map(ChallengeGroupRes.Ranking::from)
.toList();
return RankingPagingResponse.builder()
.data(data)
.totalPage(rankingPage.getTotalPages())
.myRanking(ChallengeGroupRes.Ranking.from(myRanking))
.build();
.data(data)
.totalPage(rankingPage.getTotalPages())
.myRanking(ChallengeGroupRes.Ranking.from(myRanking))
.build();
}

}
Expand All @@ -158,15 +157,16 @@ public record Ranking(
Integer acquiredPoint,
UserRes.User user
) {

public static Ranking from(
ChallengeGroupRankingModel.Main model
){
ChallengeGroupRankingModel.Main model
) {
var user = UserRes.User.from(model.user());
return Ranking.builder()
.ranking(model.rank())
.acquiredPoint(model.accumulatedPoint())
.user(user)
.build();
.ranking(model.rank())
.acquiredPoint(model.accumulatedPoint())
.user(user)
.build();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,108 +11,91 @@
public class ChallengeGroupModel {

public record Main(
Long id,
ChallengeCategory category,
String title,
String content,
Integer cumulativeCount
Long id,
ChallengeCategory category,
String title,
String content,
Integer cumulativeCount
) {

public static Main from(ChallengeGroup challengeGroup) {
return new Main(
challengeGroup.getId(),
challengeGroup.getCategory(),
challengeGroup.getTitle(),
challengeGroup.getContent(),
challengeGroup.getCumulativeCount()
challengeGroup.getId(),
challengeGroup.getCategory(),
challengeGroup.getTitle(),
challengeGroup.getContent(),
challengeGroup.getCumulativeCount()
);
}
}

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

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

public static Info from(ChallengeGroup challengeGroup) {
var challenges = challengeGroup.getChallenges().stream()
.map(ChallengeModel.Main::from)
.toList();
.map(ChallengeModel.Main::from)
.toList();
return Info.builder()
.id(challengeGroup.getId())
.category(challengeGroup.getCategory())
.title(challengeGroup.getTitle())
.content(challengeGroup.getContent())
.guide(challengeGroup.getGuide())
.cumulativeCount(challengeGroup.getCumulativeCount())
.challenges(challenges)
.build();
.id(challengeGroup.getId())
.category(challengeGroup.getCategory())
.title(challengeGroup.getTitle())
.content(challengeGroup.getContent())
.guide(challengeGroup.getGuide())
.cumulativeCount(challengeGroup.getCumulativeCount())
.joinStartDate(challengeGroup.getJoinStartDate())
.joinEndDate(challengeGroup.getJoinEndDate())
.challenges(challenges)
.build();
}
}

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

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

public static Detail from(ChallengeGroup challengeGroup, List<ChallengeGroupImage> challengeGroupImages) {
public static Detail from(ChallengeGroup challengeGroup,
List<ChallengeGroupImage> challengeGroupImages) {
var challenges = challengeGroup.getChallenges().stream()
.map(ChallengeModel.Main::from)
.toList();
.map(ChallengeModel.Main::from)
.toList();
var imageUrls = challengeGroupImages.stream()
.map(ChallengeGroupImage::getImageUrl)
.toList();
.map(ChallengeGroupImage::getImageUrl)
.toList();
return Detail.builder()
.id(challengeGroup.getId())
.category(challengeGroup.getCategory())
.title(challengeGroup.getTitle())
.content(challengeGroup.getContent())
.guide(challengeGroup.getGuide())
.cumulativeCount(challengeGroup.getCumulativeCount())
.imageUrls(imageUrls)
.challenges(challenges)
.build();
.id(challengeGroup.getId())
.category(challengeGroup.getCategory())
.title(challengeGroup.getTitle())
.content(challengeGroup.getContent())
.guide(challengeGroup.getGuide())
.joinStartDate(challengeGroup.getJoinStartDate())
.joinEndDate(challengeGroup.getJoinEndDate())
.cumulativeCount(challengeGroup.getCumulativeCount())
.imageUrls(imageUrls)
.challenges(challenges)
.build();
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ public record Main(
Integer onceExp,
Integer successExp,
Integer difficulty,
LocalDate startDate,
LocalDate endDate
Integer activePeriod
) {

public static Main from(Challenge challenge) {
return Main.builder()
.id(challenge.getId())
.requiredCount(challenge.getRequiredCount())
.onceExp(challenge.getOnceExp())
.successExp(challenge.getSuccessExp())
.difficulty(challenge.getDifficulty())
.activePeriod(challenge.getActivePeriod())
.build();
}
}
Expand Down Expand Up @@ -57,6 +58,4 @@ public static ChallengeVerificationResult from(Integer totalCount, Integer succe
}




}
Loading