-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from syyling/feat/7
[feat] 랭킹 생성하는 기능 추가
- Loading branch information
Showing
7 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...main/java/com/mookive/mookive_backend/ranking/applicaiton/dto/request/RankingRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/mookive/mookive_backend/ranking/applicaiton/mapper/RankingMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...in/java/com/mookive/mookive_backend/ranking/applicaiton/service/RankingCreateService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<RankingRequest.RankingCreateRequest> 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); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/mookive/mookive_backend/ranking/domain/entity/Ranking.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/mookive/mookive_backend/ranking/domain/respository/RankingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Ranking, Long> { | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/mookive/mookive_backend/ranking/domain/service/RankingSaveService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/mookive/mookive_backend/ranking/presentation/RankingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<RankingRequest.RankingCreateRequest> rankingCreateRequestList) { | ||
rankingCreateService.createRank(rankingCreateRequestList); | ||
} | ||
} |