Skip to content

Commit

Permalink
Merge pull request #16 from syyling/feat/11
Browse files Browse the repository at this point in the history
[feat] 랭킹 조회 기능 추가
  • Loading branch information
syyling authored Mar 18, 2024
2 parents ffe19a8 + 6c05730 commit 70308d6
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mookive.mookive_backend.ranking.applicaiton.dto.response;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

public class RankingResponse {

@Getter
@NoArgsConstructor
public static class RankingInfoResponse {

private int rankingNumber;
private String poster;
private String title;

@Builder
public RankingInfoResponse(int rankingNumber, String poster, String title) {
this.rankingNumber = rankingNumber;
this.poster = poster;
this.title = title;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mookive.mookive_backend.ranking.applicaiton.mapper;

import com.mookive.mookive_backend.movie.domain.entity.Movie;
import com.mookive.mookive_backend.ranking.applicaiton.dto.response.RankingResponse;
import com.mookive.mookive_backend.ranking.domain.entity.Ranking;
import com.mookive.mookive_backend.user.domain.entity.User;

Expand All @@ -13,4 +14,12 @@ public static Ranking mapToRanking(Movie movie, User user, int rankingNumber) {
.rankingNumber(rankingNumber)
.build();
}

public static RankingResponse.RankingInfoResponse mapToRankingInfoResponse(Ranking ranking) {
return RankingResponse.RankingInfoResponse.builder()
.rankingNumber(ranking.getRankingNumber())
.poster(ranking.getMovie().getPoster())
.title(ranking.getMovie().getTitle())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class RankingCreateService {
private final MovieQueryService movieQueryService;
private final UserQueryService userQueryService;

public void createRank(List<RankingRequest.RankingCreateRequest> rankCreateRequestList) {
public void createRanking(List<RankingRequest.RankingCreateRequest> rankCreateRequestList) {

for(RankingRequest.RankingCreateRequest rankingCreateRequest : rankCreateRequestList) {
Long movieId = rankingCreateRequest.getMovieId();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.mookive.mookive_backend.ranking.applicaiton.service;

import com.mookive.mookive_backend.ranking.applicaiton.dto.response.RankingResponse;
import com.mookive.mookive_backend.ranking.applicaiton.mapper.RankingMapper;
import com.mookive.mookive_backend.ranking.domain.entity.Ranking;
import com.mookive.mookive_backend.ranking.domain.service.RankingQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

@Service
@RequiredArgsConstructor
public class RankingGetService {

private final RankingQueryService rankingQueryService;

public List<RankingResponse.RankingInfoResponse> getRanking(Long userId) {
List<Ranking> rankingList = rankingQueryService.findByUserId(userId);
Collections.sort(rankingList, new Comparator<Ranking>() {
@Override
public int compare(Ranking o1, Ranking o2) {
return o1.getRankingNumber()-o2.getRankingNumber();
}
});

List<RankingResponse.RankingInfoResponse> rankingInfoResponseList = rankingList.stream().map(ranking -> {
RankingResponse.RankingInfoResponse rankingInfoResponse = RankingMapper.mapToRankingInfoResponse(ranking);
return rankingInfoResponse;
}).collect(Collectors.toList());

return rankingInfoResponseList;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
import com.mookive.mookive_backend.ranking.domain.entity.Ranking;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface RankingRepository extends JpaRepository<Ranking, Long> {

List<Ranking> findByUserId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mookive.mookive_backend.ranking.domain.service;

import com.mookive.mookive_backend.ranking.domain.entity.Ranking;
import com.mookive.mookive_backend.ranking.domain.respository.RankingRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class RankingQueryService {

private final RankingRepository rankingRepository;

public List<Ranking> findByUserId(Long userId) {
return rankingRepository.findByUserId(userId);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.mookive.mookive_backend.ranking.presentation;

import com.mookive.mookive_backend.ranking.applicaiton.dto.request.RankingRequest;
import com.mookive.mookive_backend.ranking.applicaiton.dto.response.RankingResponse;
import com.mookive.mookive_backend.ranking.applicaiton.service.RankingCreateService;
import com.mookive.mookive_backend.ranking.applicaiton.service.RankingGetService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

Expand All @@ -14,9 +14,15 @@
public class RankingController {

private final RankingCreateService rankingCreateService;
private final RankingGetService rankingGetService;

@PostMapping("/ranking")
public void createRank(@RequestBody List<RankingRequest.RankingCreateRequest> rankingCreateRequestList) {
rankingCreateService.createRank(rankingCreateRequestList);
public void createRanking(@RequestBody List<RankingRequest.RankingCreateRequest> rankingCreateRequestList) {
rankingCreateService.createRanking(rankingCreateRequestList);
}

@GetMapping("/ranking/{userId}")
public List<RankingResponse.RankingInfoResponse> getRanking(@PathVariable Long userId) {
return rankingGetService.getRanking(userId);
}
}

0 comments on commit 70308d6

Please sign in to comment.