-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
401 additions
and
1,310 deletions.
There are no files selected for viewing
55 changes: 40 additions & 15 deletions
55
src/main/java/org/sopt/app/application/rank/SoptampPartRankCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 8 additions & 49 deletions
57
src/main/java/org/sopt/app/application/rank/SoptampUserRankCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,23 @@ | ||
package org.sopt.app.application.rank; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.app.application.slack.SlackService; | ||
import org.sopt.app.application.soptamp.SoptampPointInfo.Main; | ||
import org.sopt.app.application.soptamp.SoptampPointInfo.Point; | ||
import org.sopt.app.application.soptamp.SoptampUserInfo; | ||
|
||
@RequiredArgsConstructor | ||
public class SoptampUserRankCalculator { | ||
|
||
private final List<SoptampUserInfo> soptampUsers; | ||
private final List<Main> ranking = new ArrayList<>(); | ||
private int rankPoint = 1; | ||
private final List<SoptampUserInfo> soptampUserInfos; | ||
|
||
public List<Main> calculateRanking(List<Point> soptampPointList) { | ||
soptampPointList.stream() | ||
.sorted(Comparator.comparing(Point::getPoints).reversed()) | ||
.forEach(point -> | ||
findSoptampUserInfo(point.getSoptampUserId()) | ||
.ifPresentOrElse( | ||
user -> addUserToRanking(user, point.getPoints()), | ||
() -> SlackService.sendSlackMessage( | ||
"Warning", | ||
"soptamp_point에 해당하지 않는 soptamp_user가 확인되었습니다.\n" | ||
+ "soptampPointId: " + point.getId() + "\n" | ||
+ "soptampUserId: " + point.getSoptampUserId() | ||
) | ||
)); | ||
return ranking; | ||
} | ||
|
||
private void addUserToRanking(SoptampUserInfo user, Long userPoint) { | ||
ranking.add(Main.builder() | ||
.rank(getCurrentRankPointAndIncrement()) | ||
.nickname(user.getNickname()) | ||
.profileMessage(user.getProfileMessage()) | ||
.point(userPoint) | ||
.build()); | ||
} | ||
|
||
private Optional<SoptampUserInfo> findSoptampUserInfo(Long soptampUserId) { | ||
return soptampUsers.stream() | ||
.filter(user -> user.getId().equals(soptampUserId)) | ||
.findAny(); | ||
} | ||
|
||
private int getCurrentRankPointAndIncrement() { | ||
return rankPoint++; | ||
} | ||
|
||
@Deprecated | ||
public List<Main> calculateRank() { | ||
return soptampUsers.stream().sorted( | ||
Comparator.comparing(SoptampUserInfo::getTotalPoints).reversed()) | ||
.map(user -> Main.of(getCurrentRankPointAndIncrement(), user)) | ||
.collect(Collectors.toList()); | ||
AtomicInteger rankPoint = new AtomicInteger(1); | ||
|
||
return soptampUserInfos.stream() | ||
.sorted(Comparator.comparing(SoptampUserInfo::getTotalPoints).reversed()) | ||
.map(user -> Main.of(rankPoint.getAndIncrement(), user)) | ||
.toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 0 additions & 104 deletions
104
src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
src/main/java/org/sopt/app/application/soptamp/SoptampUserFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.sopt.app.application.soptamp; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.app.common.exception.BadRequestException; | ||
import org.sopt.app.common.response.ErrorCode; | ||
import org.sopt.app.domain.entity.soptamp.SoptampUser; | ||
import org.sopt.app.domain.enums.Part; | ||
import org.sopt.app.interfaces.postgres.SoptampUserRepository; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class SoptampUserFinder { | ||
|
||
private final SoptampUserRepository soptampUserRepository; | ||
|
||
@Value("${sopt.current.generation}") | ||
private Long currentGeneration; | ||
|
||
public List<SoptampUserInfo> findAllCurrentGenerationSoptampUsers() { | ||
return soptampUserRepository.findAllByGeneration(currentGeneration) | ||
.stream() | ||
.map(SoptampUserInfo::of) | ||
.toList(); | ||
} | ||
|
||
public List<SoptampUserInfo> findSoptampUserIdByPart(Part part) { | ||
return soptampUserRepository.findAllByNicknameStartingWithAndGeneration(part.getPartName(), currentGeneration) | ||
.stream() | ||
.map(SoptampUserInfo::of) | ||
.toList(); | ||
} | ||
|
||
public SoptampUserInfo findSoptampUserByNickname(String nickname) { | ||
return SoptampUserInfo.of( | ||
soptampUserRepository.findUserByNickname(nickname) | ||
.orElseThrow(() -> new BadRequestException(ErrorCode.USER_NOT_FOUND.getMessage())) | ||
); | ||
} | ||
|
||
public SoptampUserInfo findByNickname(String nickname) { | ||
SoptampUser soptampUser = soptampUserRepository.findUserByNickname(nickname) | ||
.orElseThrow(() -> new BadRequestException(ErrorCode.USER_NOT_FOUND.getMessage())); | ||
return SoptampUserInfo.of(soptampUser); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.