Skip to content

Commit

Permalink
[Feat]: Service에 getMyRanking 제작
Browse files Browse the repository at this point in the history
  • Loading branch information
momnpa333 committed Oct 7, 2024
1 parent e5bc8dc commit 5290a36
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@RequiredArgsConstructor
@Service
public class UserService {

private final UserReader userReader;
private final UserChallengeReader userChallengeReader;

Expand All @@ -30,8 +31,8 @@ public UserModel.Main getUserModel(Long id) {
public List<UserModel.Main> getManagerAndAdmin() {
List<User> users = userReader.getManagerAndAdmin();
return users.stream()
.map(UserModel.Main::from)
.toList();
.map(UserModel.Main::from)
.toList();
}

/**
Expand All @@ -46,15 +47,23 @@ public void updateUser(Long id, UserCommand.Update userUpdate) {

@Transactional(readOnly = true)
public Page<UserModel.Main> getUserPagingByRanking(Pageable pageable) {
Page<User> users = userReader.getUserPagingByRanking(pageable);
Page<User> users = userReader.getUserPagingByRanking(pageable);
return users.map(UserModel.Main::from);
}

@Transactional(readOnly = true)
public UserModel.Streak getUserStreak(Long id, LocalDate startDate, LocalDate endDate){
List<DayCountType> userStreaks = userChallengeReader.countAllByUserIdAndDate(id, startDate, endDate);
public UserModel.Streak getUserStreak(Long id, LocalDate startDate, LocalDate endDate) {
List<DayCountType> userStreaks = userChallengeReader.countAllByUserIdAndDate(id, startDate,
endDate);
Map<LocalDate, Integer> map = userStreaks.stream()
.collect(Collectors.toMap(DayCountType::getDate, DayCountType::getCount));
.collect(Collectors.toMap(DayCountType::getDate, DayCountType::getCount));
return UserModel.Streak.from(map, startDate, endDate);
}

@Transactional(readOnly = true)
public UserModel.MyRanking getMyRanking(Long id) {
User user = userReader.getById(id);
Integer rank = userReader.getRanking(user.getExp());
return UserModel.MyRanking.from(user, rank);
}
}

0 comments on commit 5290a36

Please sign in to comment.