Skip to content

Commit

Permalink
Merge pull request #113 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 5b68321 + 48a42c3 commit cd1f935
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,32 @@ public class ChallengeController {

// ์ฐธ์—ฌ ์ค‘์ธ ์ฑŒ๋ฆฐ์ง€ ๋ชฉ๋ก ์กฐํšŒ
@GetMapping
public BaseResponse<List<GetChallengesRes>> getMyChallenges() throws BaseException {
public BaseResponse<List<GetChallengesRes>> getMyChallenges() {
return challengeService.getMyChallenges(authService.getUserIdx());
}

// [๊ด€๋ฆฌ์ž] ๊ด€๋ฆฌ์ž๊ฐ€ ์ƒ์„ฑํ•œ ์ฑŒ๋ฆฐ์ง€ ๋ชฉ๋ก ์กฐํšŒ
@GetMapping("/admin")
public BaseResponse<List<GetChallengesAdminRes>> getMyChallengesAdmin() throws BaseException {
public BaseResponse<List<GetChallengesAdminRes>> getMyChallengesAdmin() {
return challengeService.getMyChallengesAdmin(authService.getUserIdx());
}

// [๊ด€๋ฆฌ์ž] ์ฑŒ๋ฆฐ์ง€ ์ƒ์„ธ ์กฐํšŒ
@GetMapping("/admin/{challengeIdx}")
public BaseResponse<List<GetChallengeAdminRes>> getMyChallengeAdmin(@PathVariable(value = "challengeIdx") Long challengeIdx) throws BaseException {
public BaseResponse<List<GetChallengeAdminRes>> getMyChallengeAdmin(@PathVariable(value = "challengeIdx") Long challengeIdx) {
return challengeService.getMyChallengeAdmin(authService.getUserIdx(), challengeIdx);
}

// ์ฑŒ๋ฆฐ์ง€ ์ธ์ฆ์ฝ”๋“œ ๋ฐœ๊ธ‰
@PostMapping("/attendance/{challengeIdx}")
public BaseResponse<GetAttendanceCodeReq> getAttendanceCode(@PathVariable(value = "challengeIdx") Long challengeIdx) {
return new BaseResponse<>(challengeService.getAttendanceCode(challengeIdx));

}

// ์ฑŒ๋ฆฐ์ง€ ์ธ์ฆ
//TODO : PathVariable๋กœ ๋ณ€๊ฒฝ
@PostMapping("/attendance")
public BaseResponse<String> attendChallenge(@RequestBody AttendChallengeReq attendChallengeReq) throws BaseException {
public BaseResponse<String> attendChallenge(@RequestBody AttendChallengeReq attendChallengeReq) {
challengeService.attendChallenge(attendChallengeReq);
return new BaseResponse<>(SUCCESS);
}
Expand All @@ -65,14 +64,14 @@ public BaseResponse<ChallengeDetailResponse> getChallengeDetail(@PathVariable Lo

// ์ƒˆ๋กœ์šด ์ฑŒ๋ฆฐ์ง€ ์ฐธ์—ฌ
@PostMapping("/participation")
public BaseResponse<String> participateChallenge(@RequestBody PostChallengeReq postChallengeReq) throws BaseException {
public BaseResponse<String> participateChallenge(@RequestBody PostChallengeReq postChallengeReq) {
challengeService.participateChallenge(postChallengeReq);
return new BaseResponse<>(SUCCESS);
}

// ์ฑŒ๋ฆฐ์ง€ ๊ฒ€์ƒ‰
@GetMapping("/search")
public BaseResponse<List<SearchChallengeRes>> getChallenges(@RequestParam(value = "searchWord", defaultValue = "", required = false) String searchWord)throws BaseException {
public BaseResponse<List<SearchChallengeRes>> getChallenges(@RequestParam(value = "searchWord", defaultValue = "", required = false) String searchWord) throws BaseException {
return new BaseResponse<>(challengeService.getChallenges(searchWord));
}

Expand Down
16 changes: 11 additions & 5 deletions src/main/java/ollie/wecare/challenge/service/ChallengeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,17 @@ public void participateChallenge(PostChallengeReq postChallengeReq) throws BaseE
* */
public List<SearchChallengeRes> getChallenges(String searchWord) {
User user = userService.getUserWithValidation();
List<Challenge> challenges = challengeRepository.findByNameContainingAndParticipantsNotContaining(searchWord, user);
return challenges.stream()
.distinct()
.map(SearchChallengeRes::fromChallenge)
.toList();
if (searchWord.equals("")) {
return challengeRepository.findAll().stream()
.map(SearchChallengeRes::fromChallenge)
.toList();
} else {
List<Challenge> challenges = challengeRepository.findByNameContainingAndParticipantsNotContaining(searchWord, user);
return challenges.stream()
.distinct()
.map(SearchChallengeRes::fromChallenge)
.toList();
}
}

// ์ฑŒ๋ฆฐ์ง€ ์ƒ์„ธ ์กฐํšŒ
Expand Down

0 comments on commit cd1f935

Please sign in to comment.