Skip to content

Commit

Permalink
fix: 홈 - 전체 챌린지 조회 api url 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
daeunkwak committed Aug 26, 2023
1 parent 9e81688 commit 96ef6dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private String getImageUrlByType(String type, Challenge challenge) {

@Tag(name = "home", description = "홈(둘러보기) API")
@Operation(summary = "전체 챌린지 리스트 조회 api", description = "- {filter} - latest: 최신순, participate: 참여순, like: 좋아요순")
@GetMapping("/{filter}")
@GetMapping("/list/{filter}")
public ResponseEntity<List<ChallengeResponseDto>> getChallengeList(HttpServletRequest httpServletRequest,
@PathVariable("filter") String filter) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@
import com.cmc.member.Member;
import com.cmc.participate.Participate;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional
@RequiredArgsConstructor
@Slf4j
public class ChallengeService {

private final ChallengeRepository challengeRepository;
Expand Down Expand Up @@ -129,6 +133,7 @@ public List<ChallengeResponseVo> getChallengeList(String filter) {
break;
case "participate":
challengeResponseVos = challengeRepository.getChallengeByParticipate();
List<ChallengeResponseVo> sortedList = sortChallengeResponseList(challengeResponseVos); // 정렬
break;
case "like":
challengeResponseVos = challengeRepository.getChallengeByLike();
Expand All @@ -137,6 +142,16 @@ public List<ChallengeResponseVo> getChallengeList(String filter) {
return challengeResponseVos;
}

private static List<ChallengeResponseVo> sortChallengeResponseList(List<ChallengeResponseVo> list) {
Collections.sort(list, new Comparator<ChallengeResponseVo>() {
@Override
public int compare(ChallengeResponseVo cr1, ChallengeResponseVo cr2) {
return cr2.getParticipateNum().compareTo(cr1.getParticipateNum());
}
});
return list;
}

// 내 챌린지 - 진행중인 챌린지
public List<Challenge> getMyOngoingChallenge(Long memberId) {

Expand Down

0 comments on commit 96ef6dc

Please sign in to comment.