From d77da0302d9f9520af1032e4bdb6589b933a3238 Mon Sep 17 00:00:00 2001 From: seo-young Date: Thu, 7 Mar 2024 16:19:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=20=EB=9E=AD=ED=82=B9=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8,=20repository=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ranking/domain/entity/Ranking.java | 35 +++++++++++++++++++ .../domain/respository/RankingRepository.java | 7 ++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/java/com/mookive/mookive_backend/ranking/domain/entity/Ranking.java create mode 100644 src/main/java/com/mookive/mookive_backend/ranking/domain/respository/RankingRepository.java diff --git a/src/main/java/com/mookive/mookive_backend/ranking/domain/entity/Ranking.java b/src/main/java/com/mookive/mookive_backend/ranking/domain/entity/Ranking.java new file mode 100644 index 0000000..fecb857 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/ranking/domain/entity/Ranking.java @@ -0,0 +1,35 @@ +package com.mookive.mookive_backend.ranking.domain.entity; + +import com.mookive.mookive_backend.movie.domain.entity.Movie; +import com.mookive.mookive_backend.user.domain.entity.User; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Ranking { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne + @JoinColumn(name = "movie_id") + private Movie movie; + + @ManyToOne + @JoinColumn(name = "user_id") + private User user; + + private int rankingNumber; + + @Builder + public Ranking(Movie movie, User user, int rankingNumber) { + this.movie = movie; + this.user = user; + this.rankingNumber = rankingNumber; + } +} diff --git a/src/main/java/com/mookive/mookive_backend/ranking/domain/respository/RankingRepository.java b/src/main/java/com/mookive/mookive_backend/ranking/domain/respository/RankingRepository.java new file mode 100644 index 0000000..3567330 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/ranking/domain/respository/RankingRepository.java @@ -0,0 +1,7 @@ +package com.mookive.mookive_backend.ranking.domain.respository; + +import com.mookive.mookive_backend.ranking.domain.entity.Ranking; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RankingRepository extends JpaRepository { +} From 9ca5dc7f8810e8558a5063e30f563d71b920d92e Mon Sep 17 00:00:00 2001 From: seo-young Date: Thu, 7 Mar 2024 16:19:32 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[feat]=20=EB=9E=AD=ED=82=B9=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/RankingRequest.java | 24 +++++++++++++ .../applicaiton/mapper/RankingMapper.java | 16 +++++++++ .../service/RankingCreateService.java | 36 +++++++++++++++++++ .../domain/service/RankingSaveService.java | 17 +++++++++ .../presentation/RankingController.java | 22 ++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 src/main/java/com/mookive/mookive_backend/ranking/applicaiton/dto/request/RankingRequest.java create mode 100644 src/main/java/com/mookive/mookive_backend/ranking/applicaiton/mapper/RankingMapper.java create mode 100644 src/main/java/com/mookive/mookive_backend/ranking/applicaiton/service/RankingCreateService.java create mode 100644 src/main/java/com/mookive/mookive_backend/ranking/domain/service/RankingSaveService.java create mode 100644 src/main/java/com/mookive/mookive_backend/ranking/presentation/RankingController.java diff --git a/src/main/java/com/mookive/mookive_backend/ranking/applicaiton/dto/request/RankingRequest.java b/src/main/java/com/mookive/mookive_backend/ranking/applicaiton/dto/request/RankingRequest.java new file mode 100644 index 0000000..8a077cd --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/ranking/applicaiton/dto/request/RankingRequest.java @@ -0,0 +1,24 @@ +package com.mookive.mookive_backend.ranking.applicaiton.dto.request; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +public class RankingRequest { + + @Getter + @NoArgsConstructor + public static class RankingCreateRequest { + + private Long userId; + private Long movieId; + private int rankingNumber; + + @Builder + public RankingCreateRequest(Long userId, Long movieId, int rankingNumber) { + this.userId = userId; + this.movieId = movieId; + this.rankingNumber = rankingNumber; + } + } +} diff --git a/src/main/java/com/mookive/mookive_backend/ranking/applicaiton/mapper/RankingMapper.java b/src/main/java/com/mookive/mookive_backend/ranking/applicaiton/mapper/RankingMapper.java new file mode 100644 index 0000000..039ff9d --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/ranking/applicaiton/mapper/RankingMapper.java @@ -0,0 +1,16 @@ +package com.mookive.mookive_backend.ranking.applicaiton.mapper; + +import com.mookive.mookive_backend.movie.domain.entity.Movie; +import com.mookive.mookive_backend.ranking.domain.entity.Ranking; +import com.mookive.mookive_backend.user.domain.entity.User; + +public class RankingMapper { + + public static Ranking mapToRanking(Movie movie, User user, int rankingNumber) { + return Ranking.builder() + .movie(movie) + .user(user) + .rankingNumber(rankingNumber) + .build(); + } +} diff --git a/src/main/java/com/mookive/mookive_backend/ranking/applicaiton/service/RankingCreateService.java b/src/main/java/com/mookive/mookive_backend/ranking/applicaiton/service/RankingCreateService.java new file mode 100644 index 0000000..d1728fc --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/ranking/applicaiton/service/RankingCreateService.java @@ -0,0 +1,36 @@ +package com.mookive.mookive_backend.ranking.applicaiton.service; + +import com.mookive.mookive_backend.movie.domain.entity.Movie; +import com.mookive.mookive_backend.movie.domain.service.MovieQueryService; +import com.mookive.mookive_backend.ranking.applicaiton.dto.request.RankingRequest; +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.RankingSaveService; +import com.mookive.mookive_backend.user.domain.entity.User; +import com.mookive.mookive_backend.user.domain.service.UserQueryService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class RankingCreateService { + + private final RankingSaveService rankSaveService; + private final MovieQueryService movieQueryService; + private final UserQueryService userQueryService; + + public void createRank(List rankCreateRequestList) { + + for(RankingRequest.RankingCreateRequest rankingCreateRequest : rankCreateRequestList) { + Long movieId = rankingCreateRequest.getMovieId(); + Movie movie = movieQueryService.findById(movieId); + Long userId = rankingCreateRequest.getUserId(); + User user = userQueryService.findById(userId); + int rankingNumber = rankingCreateRequest.getRankingNumber(); + Ranking ranking = RankingMapper.mapToRanking(movie, user, rankingNumber); + rankSaveService.saveRanking(ranking); + } + } +} diff --git a/src/main/java/com/mookive/mookive_backend/ranking/domain/service/RankingSaveService.java b/src/main/java/com/mookive/mookive_backend/ranking/domain/service/RankingSaveService.java new file mode 100644 index 0000000..df24773 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/ranking/domain/service/RankingSaveService.java @@ -0,0 +1,17 @@ +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; + +@Service +@RequiredArgsConstructor +public class RankingSaveService { + + private final RankingRepository rankingRepository; + + public void saveRanking(Ranking ranking) { + rankingRepository.save(ranking); + } +} diff --git a/src/main/java/com/mookive/mookive_backend/ranking/presentation/RankingController.java b/src/main/java/com/mookive/mookive_backend/ranking/presentation/RankingController.java new file mode 100644 index 0000000..e1247b0 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/ranking/presentation/RankingController.java @@ -0,0 +1,22 @@ +package com.mookive.mookive_backend.ranking.presentation; + +import com.mookive.mookive_backend.ranking.applicaiton.dto.request.RankingRequest; +import com.mookive.mookive_backend.ranking.applicaiton.service.RankingCreateService; +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 java.util.List; + +@RestController +@RequiredArgsConstructor +public class RankingController { + + private final RankingCreateService rankingCreateService; + + @PostMapping("/ranking") + public void createRank(@RequestBody List rankingCreateRequestList) { + rankingCreateService.createRank(rankingCreateRequestList); + } +}