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

feat:ranking 기능 #47

Merged
merged 1 commit into from
Jul 13, 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
@@ -1,8 +1,6 @@
package hamsung.hamsung_project.controller;

import hamsung.hamsung_project.dto.MyStudyDto;
import hamsung.hamsung_project.dto.ResultDto;
import hamsung.hamsung_project.dto.StudyDto;
import hamsung.hamsung_project.dto.*;
import hamsung.hamsung_project.entity.Study;
import hamsung.hamsung_project.service.StudyService;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -66,4 +64,13 @@ public ResponseEntity<?> showMyStudy(@PathVariable Long userId){
}
return ResponseEntity.status(HttpStatus.OK).body(target);
}


//스터디 랭킹(스터디 전체 조회)
@GetMapping("/study/ranking")
public ResponseEntity<List<StudyRankingDto>> showRanking(){
List<StudyRankingDto> rankingList=studyService.showRanking();
return ResponseEntity.status(HttpStatus.OK).body(rankingList);
}

}
20 changes: 20 additions & 0 deletions src/main/java/hamsung/hamsung_project/dto/StudyRankingDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package hamsung.hamsung_project.dto;


import hamsung.hamsung_project.entity.Study;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@AllArgsConstructor
public class StudyRankingDto {
private Long id;
private String title;
private Integer score;


}
20 changes: 18 additions & 2 deletions src/main/java/hamsung/hamsung_project/service/StudyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hamsung.hamsung_project.dto.MyStudyDto;
import hamsung.hamsung_project.dto.RecruitsRequestsDto;
import hamsung.hamsung_project.dto.StudyDto;
import hamsung.hamsung_project.dto.StudyRankingDto;
import hamsung.hamsung_project.entity.Recruit;
import hamsung.hamsung_project.entity.Study;
import hamsung.hamsung_project.repository.RecruitsRepository;
Expand All @@ -16,6 +17,7 @@
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class StudyService {
Expand Down Expand Up @@ -105,7 +107,21 @@ else if(target==null){
return studyDtoList;
}



//스터디 랭킹(스터디 전체 조회)
@Transactional
public List<StudyRankingDto> showRanking(){
List<Study> studyList=studyRepository.findAll();
// List<StudyRankingDto> ranking=new ArrayList<>();

return studyList.stream()
.sorted((m1,m2)->Integer.compare(m2.getScore(),m1.getScore()))
.limit(10)
.map(study->new StudyRankingDto(
study.getId(),
study.getTitle(),
study.getScore()
))
.collect(Collectors.toList());
}

}
Loading