Skip to content

Commit

Permalink
Merge pull request #104 from team-Ollie/feature/4-getMyChallengesAdmin
Browse files Browse the repository at this point in the history
[feature/4-getMyChallengesAdmin] 관리자 챌린지 현황 조회 API
  • Loading branch information
Haeun-Y authored Jul 1, 2024
2 parents 4715a6a + b1b107d commit f71ccb6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public BaseResponse<List<GetChallengesAdminRes>> getMyChallengesAdmin() throws B
return challengeService.getMyChallengesAdmin(authService.getUserIdx());
}

// [관리자] 챌린지 상세 조회
@GetMapping("/admin/{challengeIdx}")
public BaseResponse<List<GetChallengeAdminRes>> getMyChallengeAdmin(@PathVariable(value = "challengeIdx") Long challengeIdx) throws BaseException {
return challengeService.getMyChallengeAdmin(authService.getUserIdx(), challengeIdx);
}

// 챌린지 인증코드 발급
@PostMapping("/attendance/{challengeIdx}")
public BaseResponse<GetAttendanceCodeReq> getAttendanceCode(@PathVariable(value = "challengeIdx") Long challengeIdx) {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/ollie/wecare/challenge/dto/GetChallengeAdminRes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ollie.wecare.challenge.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import ollie.wecare.user.entity.User;

@Data
@AllArgsConstructor
@Builder
@NoArgsConstructor
public class GetChallengeAdminRes {
String identifier;
Integer attendanceRate;

public static GetChallengeAdminRes fromParticipant(User user, Integer attendanceRate) {
return GetChallengeAdminRes.builder().identifier(user.getIdentifier()).attendanceRate(attendanceRate).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public BaseResponse<List<GetChallengesAdminRes>> getMyChallengesAdmin(Long userI

}

public BaseResponse<List<GetChallengeAdminRes>> getMyChallengeAdmin(Long userIdx, Long challengeIdx) {
Challenge challenge = challengeRepository.findById(challengeIdx).orElseThrow(()-> new BaseException(INVALID_CHALLENGE_IDX));
if(!challenge.getAdmin().getUserIdx().equals(userIdx)) throw new BaseException(INVALID_ROLE);
return new BaseResponse<>(challenge.getParticipants().stream().map(participant -> GetChallengeAdminRes
.fromParticipant(participant, challengeAttendanceRepository.countByUserAndChallenge(participant, challenge))).toList());

}

/*
* 챌린지 인증코드 발급
* */
Expand Down

0 comments on commit f71ccb6

Please sign in to comment.