Skip to content

Commit

Permalink
Merge pull request #117 from team-Ollie/develop
Browse files Browse the repository at this point in the history
[develop] ์ฑŒ๋ฆฐ์ง€ ๋ชฉ๋ก ์กฐํšŒ ์‹œ ํƒœ๊ทธ ์ œ์™ธํ•˜๋„๋ก ์ˆ˜์ •
  • Loading branch information
JoongHyun-Kim authored Jul 2, 2024
2 parents f3e372d + e6fedb9 commit 500dc10
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
24 changes: 1 addition & 23 deletions src/main/java/ollie/wecare/challenge/dto/GetChallengesRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,18 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import ollie.wecare.challenge.entity.Challenge;
import ollie.wecare.common.enums.TagEnum;
import ollie.wecare.program.entity.Program;
import ollie.wecare.program.entity.Tag;

@Data
@AllArgsConstructor
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class GetChallengesRes {

private Long challengeIdx;

private String name;

private Integer participantsCount;

private String location;

private String schedule;

private String locatedPlace;

private Integer myAttendanceRate;

private Integer totalAttendanceRate;

public static GetChallengesRes fromChallenge(Challenge challenge, Integer myAttendanceRate) {
Expand All @@ -37,19 +25,9 @@ public static GetChallengesRes fromChallenge(Challenge challenge, Integer myAtte
.challengeIdx(challenge.getChallengeIdx())
.name(challenge.getName())
.participantsCount(challenge.getParticipants().size())
.location(getLocationTag(challenge.getProgram()) != null ? getLocationTag(challenge.getProgram()).getTagName() : null)
.schedule(challenge.getProgram().getSchedule())
.myAttendanceRate(myAttendanceRate)
.locatedPlace(challenge.getProgram().getLocatedPlace())
.totalAttendanceRate(challenge.getAttendanceRate()).build();
}

private static TagEnum getLocationTag(Program program) {
return program.getTags().stream()
.map(Tag::getName)
.filter(tagEnum -> tagEnum.getParent() == TagEnum.LOCATION)
.findFirst()
.orElse(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,17 @@ public class ChallengeService {
private final ChallengeAttendanceRepository challengeAttendanceRepository;
private final UserRepository userRepository;
private final ChallengeRepository challengeRepository;

private final UserService userService;

// ์ฐธ์—ฌ์ค‘์ธ ์ฑŒ๋ฆฐ์ง€ ๋ชฉ๋ก ์กฐํšŒ
public BaseResponse<List<GetChallengesRes>> getMyChallenges(Long userIdx) throws BaseException {
public BaseResponse<List<GetChallengesRes>> getMyChallenges(Long userIdx) {
User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
if(user.getRole().equals(Role.Challenger)){
if (user.getRole().equals(Role.Challenger)){
return new BaseResponse<>(challengeRepository.findByParticipantsContaining(user).stream()
.map(challenge -> GetChallengesRes.fromChallenge(challenge, calculateMyAchievementRate(user, challenge)))
.distinct()
.toList());
}
else { // ๊ด€๋ฆฌ์ž
} else { // ๊ด€๋ฆฌ์ž
return new BaseResponse<>(challengeRepository.findByAdmin(user).stream()
.map(challenge -> GetChallengesRes.fromChallenge(challenge, calculateMyAchievementRate(user, challenge)))
.distinct()
Expand All @@ -55,7 +53,7 @@ public BaseResponse<List<GetChallengesRes>> getMyChallenges(Long userIdx) throws

}

public BaseResponse<List<GetChallengesAdminRes>> getMyChallengesAdmin(Long userIdx) throws BaseException {
public BaseResponse<List<GetChallengesAdminRes>> getMyChallengesAdmin(Long userIdx) {
User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
if(user.getRole().equals(Role.Admin)){
return new BaseResponse<>(challengeRepository.findByAdmin(user).stream()
Expand Down

0 comments on commit 500dc10

Please sign in to comment.