diff --git a/purithm/src/main/java/com/example/purithm/domain/filter/dto/response/DatedFilterDto.java b/purithm/src/main/java/com/example/purithm/domain/filter/dto/response/DatedFilterDto.java index 6dfecc3..4a7585e 100644 --- a/purithm/src/main/java/com/example/purithm/domain/filter/dto/response/DatedFilterDto.java +++ b/purithm/src/main/java/com/example/purithm/domain/filter/dto/response/DatedFilterDto.java @@ -2,6 +2,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -60,6 +61,7 @@ public static List groupByDate(List filterLog groupedFilters.add(groupedFilter); } + Collections.sort(groupedFilters, (s1, s2) -> s1.getDate().compareTo(s2.getDate())); return groupedFilters; } } diff --git a/purithm/src/main/java/com/example/purithm/domain/filter/dto/response/DatedStampDto.java b/purithm/src/main/java/com/example/purithm/domain/filter/dto/response/DatedStampDto.java index 22275dd..ed66629 100644 --- a/purithm/src/main/java/com/example/purithm/domain/filter/dto/response/DatedStampDto.java +++ b/purithm/src/main/java/com/example/purithm/domain/filter/dto/response/DatedStampDto.java @@ -2,6 +2,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -61,6 +62,7 @@ public static List groupByDate(List stampDtos) { groupedStamps.add(groupedStamp); } + Collections.sort(groupedStamps, (s1, s2) -> s1.getDate().compareTo(s2.getDate())); return groupedStamps; } } diff --git a/purithm/src/main/java/com/example/purithm/domain/filter/entity/Membership.java b/purithm/src/main/java/com/example/purithm/domain/filter/entity/Membership.java index 390e213..a11e754 100644 --- a/purithm/src/main/java/com/example/purithm/domain/filter/entity/Membership.java +++ b/purithm/src/main/java/com/example/purithm/domain/filter/entity/Membership.java @@ -3,5 +3,15 @@ public enum Membership { BASIC, PREMIUM, - PREMIUM_PLUS + PREMIUM_PLUS; + + public static Membership checkMembership(int numOfReviews) { + if (numOfReviews >= 8) { + return PREMIUM_PLUS; + } + if (numOfReviews >= 4) { + return PREMIUM; + } + return BASIC; + } } diff --git a/purithm/src/main/java/com/example/purithm/domain/review/service/ReviewService.java b/purithm/src/main/java/com/example/purithm/domain/review/service/ReviewService.java index 650f42c..9c96b2c 100644 --- a/purithm/src/main/java/com/example/purithm/domain/review/service/ReviewService.java +++ b/purithm/src/main/java/com/example/purithm/domain/review/service/ReviewService.java @@ -73,13 +73,8 @@ public CreatedReviewDto writeReview(Long id, ReviewRequestDto request) { private void upgradeMembership(User user) { int numOfReviews = reviewRepository.countAllByUser(user); - if (numOfReviews == 16) { - user.upgradeToPremiumPlus(); - userRepository.save(user); - } else if (numOfReviews == 8) { - user.upgradeToPremium(); - userRepository.save(user); - } + user.updateMembership(numOfReviews); + userRepository.save(user); } public List getFeeds(OS os, String sortedBy, Long userId) { diff --git a/purithm/src/main/java/com/example/purithm/domain/user/entity/User.java b/purithm/src/main/java/com/example/purithm/domain/user/entity/User.java index eb8ad2b..dbebe46 100644 --- a/purithm/src/main/java/com/example/purithm/domain/user/entity/User.java +++ b/purithm/src/main/java/com/example/purithm/domain/user/entity/User.java @@ -62,12 +62,11 @@ public class User { public void agreeToTerms() { this.terms = true; } - public void upgradeToPremium() { - this.membership = Membership.PREMIUM; - } - public void upgradeToPremiumPlus() { - this.membership = Membership.PREMIUM_PLUS; + + public void updateMembership(int numOfReviews) { + this.membership = Membership.checkMembership(numOfReviews); } + public void updateProfile(UserInfoRequestDto userInfo) { this.profile = userInfo.profile(); this.username = userInfo.name();