Skip to content

Commit

Permalink
Merge pull request #47 from NOzigak/feature/recruitt
Browse files Browse the repository at this point in the history
feat:ranking 기능
  • Loading branch information
1224kang authored Jul 13, 2024
2 parents eaba24b + 4dedc69 commit ebba3c0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
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());
}

}

0 comments on commit ebba3c0

Please sign in to comment.