Skip to content

Commit

Permalink
Refactor : Genre 타입 변경에 따른 코드 수정
Browse files Browse the repository at this point in the history
Related:#58
  • Loading branch information
hgh1472 committed Oct 3, 2024
1 parent 464d1e3 commit b984685
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,54 +1,58 @@
package core.application.movies.models.entities;

import core.application.movies.constant.Genre;
import lombok.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@ToString
public class CachedMovieEntity {
/**
* {@code 알파벳}-{@code 숫자} 형태 {@code (KMDB 영화 ID 형태)}
*/
private String movieId;
private String title;
private String posterUrl;
private Genre genre;
private String releaseDate;
private String plot;
private String runningTime;
private String actors;
private String director;
private Long dibCount;
private Long reviewCount;
private Long commentCount;
private Long sumOfRating;

public void incrementDibCount() {
this.dibCount++;
}

public void decrementDibCount() {
this.dibCount--;
}

public void incrementReviewCount() {
this.reviewCount++;
}

public void decrementReviewCount() {
this.reviewCount--;
}

public void isCommentedWithRating(int rating) {
this.commentCount++;
this.sumOfRating += rating;
}

public void deleteComment(int rating) {
this.commentCount--;
this.sumOfRating -= rating;
}
/**
* {@code 알파벳}-{@code 숫자} 형태 {@code (KMDB 영화 ID 형태)}
*/
private String movieId;
private String title;
private String posterUrl;
private String genre;
private String releaseDate;
private String plot;
private String runningTime;
private String actors;
private String director;
private Long dibCount;
private Long reviewCount;
private Long commentCount;
private Long sumOfRating;

public void incrementDibCount() {
this.dibCount++;
}

public void decrementDibCount() {
this.dibCount--;
}

public void incrementReviewCount() {
this.reviewCount++;
}

public void decrementReviewCount() {
this.reviewCount--;
}

public void isCommentedWithRating(int rating) {
this.commentCount++;
this.sumOfRating += rating;
}

public void deleteComment(int rating) {
this.commentCount--;
this.sumOfRating -= rating;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import core.application.movies.constant.Genre;
import core.application.movies.models.dto.CommentRespDTO;
import core.application.movies.models.entities.CachedMovieEntity;
import core.application.movies.models.entities.CommentEntity;
Expand Down Expand Up @@ -58,7 +57,7 @@ public void setUp() {
"test",
"testTitle",
"posterUrl",
Genre.ACTION,
"액션",
"2024-09-30",
"줄거리",
"122",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import core.application.movies.constant.Genre;
import core.application.movies.models.entities.CachedMovieEntity;
import core.application.movies.repositories.CachedMovieRepository;

Expand All @@ -30,7 +29,7 @@ public void save() {
"test",
"testTitle",
"posterUrl",
Genre.ACTION,
"액션",
"2024-09-30",
"줄거리",
"122",
Expand All @@ -55,7 +54,7 @@ public void update() {
"test",
"testTitle",
"posterUrl",
Genre.ACTION,
"액션",
"2024-09-30",
"줄거리",
"122",
Expand Down Expand Up @@ -84,7 +83,7 @@ public void order() {
"test" + i,
"testTitle",
"posterUrl",
Genre.ACTION,
"액션",
"2024-09-30",
"줄거리",
"122",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.springframework.transaction.annotation.Transactional;

import core.application.movies.constant.CommentSort;
import core.application.movies.constant.Genre;
import core.application.movies.models.dto.CommentRespDTO;
import core.application.movies.models.dto.CommentWriteReqDTO;
import core.application.movies.models.entities.CachedMovieEntity;
Expand Down Expand Up @@ -62,7 +61,7 @@ public void setUp() {
"test",
"testTitle",
"posterUrl",
Genre.ACTION,
"액션",
"2024-09-30",
"줄거리",
"122",
Expand All @@ -77,7 +76,7 @@ public void setUp() {
@Test
@DisplayName("한줄평을 작성한다.")
public void writeComment() {
// GIVEN
// GIVEN
CommentWriteReqDTO writeReqDTO = new CommentWriteReqDTO("한줄평 내용입니다.", 10);
UserEntity writer = users.get(0);

Expand All @@ -94,7 +93,7 @@ public void writeComment() {
@Test
@DisplayName("영화의 한줄평을 최신순으로 불러온다.")
public void getLatestComments() throws InterruptedException {
// GIVEN
// GIVEN
for (int i = 0; i < 10; i++) {
CommentWriteReqDTO writeReqDTO = new CommentWriteReqDTO(i + "번째 한줄평", 10);
CommentRespDTO commentRespDTO = commentService.writeCommentOnMovie(writeReqDTO, users.get(i).getUserId(),
Expand Down Expand Up @@ -166,7 +165,7 @@ public void getMostDislikedComments() {
@Test
@DisplayName("한줄평에 좋아요을 누른다.")
public void likeComment() {
// GIVEN
// GIVEN
CommentWriteReqDTO writeReqDTO = new CommentWriteReqDTO("한줄평입니다.", 10);
UserEntity writer = users.get(0);
CommentRespDTO commentRespDTO = commentService.writeCommentOnMovie(writeReqDTO, writer.getUserId(), movieId);
Expand All @@ -183,7 +182,7 @@ public void likeComment() {
@Test
@DisplayName("좋아요를 취소한다.")
public void cancelLikeComment() {
// GIVEN
// GIVEN
CommentWriteReqDTO writeReqDTO = new CommentWriteReqDTO("한줄평입니다.", 10);
UserEntity writer = users.get(0);
CommentRespDTO commentRespDTO = commentService.writeCommentOnMovie(writeReqDTO, writer.getUserId(),
Expand All @@ -193,7 +192,7 @@ public void cancelLikeComment() {
// WHEN
commentService.decrementCommentLike(commentRespDTO.getCommentId(), users.get(1).getUserId());

// THEN
// THEN
CommentEntity comment = commentRepository.findByCommentId(commentRespDTO.getCommentId()).orElseThrow();
assertThat(comment.getLike()).isEqualTo(0);
}
Expand Down Expand Up @@ -236,7 +235,7 @@ public void cancelDislikeComment() {
@Test
@DisplayName("한줄평 조회 시, 좋아요와 싫어요를 누른 항목은 표시된다.")
public void displayTest() {
// GIVEN
// GIVEN
Set<Long> reactionCommentIds = new HashSet<>();
UserEntity user = users.get(0);
for (int i = 0; i < 10; i++) {
Expand All @@ -250,7 +249,7 @@ public void displayTest() {
}
}

// WHEN
// WHEN
List<CommentRespDTO> comments = commentService.getComments(movieId, 0, CommentSort.LIKE, user.getUserId());

// THEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import core.application.movies.constant.Genre;
import core.application.movies.models.dto.MainPageMovieRespDTO;
import core.application.movies.models.dto.MainPageMoviesRespDTO;
import core.application.movies.models.entities.CachedMovieEntity;
import core.application.movies.repositories.CachedMovieRepository;
import lombok.extern.slf4j.Slf4j;

@SpringBootTest
@Transactional
@Slf4j
public class MovieServiceTest {
@Autowired
private MovieService movieService;
Expand All @@ -34,7 +31,7 @@ public void initTestData() {
String.valueOf(i),
String.valueOf(i),
"posterUrl",
Genre.ACTION,
"액션",
"2024-09-30",
"줄거리",
"122",
Expand Down

0 comments on commit b984685

Please sign in to comment.