Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[develop] 챌린지 검색 API 수정 #92

Merged
merged 7 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ollie.wecare.challenge.service.ChallengeService;
import ollie.wecare.common.base.BaseException;
import ollie.wecare.common.base.BaseResponse;
import ollie.wecare.user.service.AuthService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -21,75 +22,51 @@
public class ChallengeController {

private final ChallengeService challengeService;
private final AuthService authService;

/*
* 참여 중인 챌린지 조회
* */
// 참여 중인 챌린지 목록 조회
@GetMapping
@ResponseBody
public BaseResponse<List<GetChallengesRes>> getMyChallenges() throws BaseException {
return new BaseResponse<>(challengeService.getMyChallenges());
return challengeService.getMyChallenges(authService.getUserIdx());
}

/*
* 챌린지 인증코드 발급
* */
// 챌린지 인증코드 발급
@PostMapping("/attendance/{challengeIdx}")
@ResponseBody
public BaseResponse<GetAttendanceCodeReq> getAttendanceCode(@PathVariable(value = "challengeIdx") Long challengeIdx) {
return new BaseResponse<>(challengeService.getAttendanceCode(challengeIdx));

}


/*
* 챌린지 인증
* */
// 챌린지 인증
//TODO : PathVariable로 변경
@PostMapping("/attendance")
@ResponseBody
public BaseResponse<String> attendChallenge(@RequestBody AttendChallengeReq attendChallengeReq) throws BaseException {
challengeService.attendChallenge(attendChallengeReq);
return new BaseResponse<>(SUCCESS);
}

/*
* 챌린지 참여 현황 조회(월별)
* */
// 챌린지 상세 조회
@GetMapping("/attendance/{challengeIdx}")
@ResponseBody
public BaseResponse<List<GetAttendanceRes>> getAttendance(@PathVariable("challengeIdx") Long challengeIdx,
@RequestParam(value = "year", required = false, defaultValue = "0") Long year,
@RequestParam(value = "month", required = false, defaultValue = "0") Long month) {
return new BaseResponse<>(challengeService.getAttendance(challengeIdx, year, month));
public BaseResponse<ChallengeDetailResponse> getChallengeDetail(@PathVariable Long challengeIdx) {
return challengeService.getChallengeDetail(authService.getUserIdx(), challengeIdx);
}

/*
* 새로운 챌린지 참여
* */
// 새로운 챌린지 참여
@PostMapping("/participation")
@ResponseBody
public BaseResponse<String> participateChallenge(@RequestBody PostChallengeReq postChallengeReq) throws BaseException {
challengeService.participateChallenge(postChallengeReq);
return new BaseResponse<>(SUCCESS);

}

/*
* 챌린지 검색
* */
// 챌린지 검색
@GetMapping("/search")
@ResponseBody
public BaseResponse<List<GetChallengesRes>> getChallenges(@RequestParam(value = "searchWord", defaultValue = "", required = false) String searchWord)throws BaseException {
return new BaseResponse<>(challengeService.getChallenges(searchWord));
}

/*
* 챌린지 광고 조회
* */
@GetMapping("/ads")
@ResponseBody
public BaseResponse<GetChallengeAdsRes> getChallengeAds() {
return new BaseResponse<>(challengeService.getChallengeAds());
}
// // 챌린지 광고 조회
// @GetMapping("/ads")
// public BaseResponse<GetChallengeAdsRes> getChallengeAds() {
// return new BaseResponse<>(challengeService.getChallengeAds());
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ollie.wecare.challenge.dto;

import ollie.wecare.program.dto.DateDto;

import java.util.List;

public record ChallengeDetailResponse(String name,
Integer participantsCount,
List<DateDto> attendanceList,
Integer totalAchievementRate,
Integer myAchievementRate) {
}
33 changes: 0 additions & 33 deletions src/main/java/ollie/wecare/challenge/dto/GetAttendanceRes.java

This file was deleted.

13 changes: 6 additions & 7 deletions src/main/java/ollie/wecare/challenge/dto/GetChallengesRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,26 @@ public class GetChallengesRes {

private String name;

private Long participantsNum;
private Integer participantsCount;

private String location;

private String schedule;

private Long attendanceRate;
private Integer myAttendanceRate;

private Long totalAttendanceRate;
private Integer totalAttendanceRate;

public static GetChallengesRes fromChallenge(Challenge challenge, Long userParticipationNum) {
public static GetChallengesRes fromChallenge(Challenge challenge, Integer myAttendanceRate) {

return GetChallengesRes.builder()
.challengeIdx(challenge.getChallengeIdx())
.name(challenge.getName())
.participantsNum((long) challenge.getParticipants().size())
.participantsCount(challenge.getParticipants().size())
.location(challenge.getProgram().getLocation())
.schedule(challenge.getProgram().getSchedule())
.attendanceRate(Math.round((double)userParticipationNum/challenge.getTotalNum()) * 100)
.myAttendanceRate(myAttendanceRate)
.totalAttendanceRate(challenge.getAttendanceRate()).build();

}

}
6 changes: 2 additions & 4 deletions src/main/java/ollie/wecare/challenge/entity/Challenge.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public void updateAttendanceCode(String attendanceCode) {
@OneToMany(fetch = FetchType.LAZY)
private List<User> participants;

private Long totalNum;

private Long attendanceRate;

private Integer totalNum;

private Integer attendanceRate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import ollie.wecare.user.entity.User;
import org.hibernate.annotations.DynamicInsert;

import java.time.LocalDateTime;
@Entity
@Getter
@Builder
Expand All @@ -30,10 +29,4 @@ public class ChallengeAttendance extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "challenge_idx")
private Challenge challenge;

//TODO : createdDate로 대체해서 사용하는 것 고려해보기
private LocalDateTime attendanceDate;



}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package ollie.wecare.challenge.repository;

import ollie.wecare.challenge.entity.Challenge;
import ollie.wecare.challenge.entity.ChallengeAttendance;
import ollie.wecare.user.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface ChallengeAttendanceRepository extends JpaRepository<ChallengeAttendance, Long> {
List<ChallengeAttendance> findByUser_UserIdx(Long userIdx);
List<ChallengeAttendance> findByUser_UserIdxAndChallenge_ChallengeIdx(Long userIdx, Long challengeIdx);
List<ChallengeAttendance> findByUser_UserIdxAndChallenge_ChallengeIdxAndAttendanceDateBetweenOrderByAttendanceDate(Long userIdx, Long challengeIdx, LocalDateTime start, LocalDateTime last);
List<ChallengeAttendance> findByUserAndChallenge_ChallengeIdx(User user, Long challengeIdx);
List<ChallengeAttendance> findByUserAndChallengeOrderByCreatedDate(User user, Challenge challenge);
Integer countByUserAndChallenge(User user, Challenge challenge);
List<ChallengeAttendance> findByUserAndStatusEquals(User user, String status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public interface ChallengeRepository extends JpaRepository<Challenge, Long> {
Page<Challenge> findMostParticipatedChallenge(Pageable pageable);

Optional<Challenge> findTop1ByOrderByCreatedDateDesc();

Optional<Challenge> findByChallengeIdxAndStatusEquals(Long challengeIdx, String status);
}
Loading
Loading