diff --git a/src/main/java/com/example/demo/video/Video.java b/src/main/java/com/example/demo/video/Video.java index 61b1bf18..945325fa 100644 --- a/src/main/java/com/example/demo/video/Video.java +++ b/src/main/java/com/example/demo/video/Video.java @@ -5,10 +5,12 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; import javax.persistence.*; +import javax.validation.constraints.NotNull; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -36,7 +38,8 @@ public class Video extends BaseTime { @Column private String videoEndTime; - @Column + @Column(nullable = false) + @ColumnDefault("0") private long views; @Column @@ -52,4 +55,8 @@ public Video(String videoUrl, String videoTitleKorean, String videoTitleEng, Str this.views = views; this.videoThumbnailUrl = videoThumbnailUrl; } + + public void addView(){ + this.views += 1; + } } diff --git a/src/main/java/com/example/demo/video/VideoJPARepository.java b/src/main/java/com/example/demo/video/VideoJPARepository.java index 536592bd..f7a56be4 100644 --- a/src/main/java/com/example/demo/video/VideoJPARepository.java +++ b/src/main/java/com/example/demo/video/VideoJPARepository.java @@ -16,12 +16,12 @@ public interface VideoJPARepository extends JpaRepository { @Query(value = "SELECT * FROM videos v " + "INNER JOIN video_interests vi ON v.id = vi.video_id " + - "INNER JOIN interest_tb i ON vi.interest_id = i.id " + + "INNER JOIN interests i ON vi.interest_id = i.id " + "WHERE i.category IN :userInterests " + "ORDER BY RAND()", // MySQL에서 랜덤 정렬 countQuery = "SELECT COUNT(*) FROM videos v " + "INNER JOIN video_interests vi ON v.id = vi.video_id " + - "INNER JOIN interest_tb i ON vi.interest_id = i.id " + + "INNER JOIN interests i ON vi.interest_id = i.id " + "WHERE i.category IN :userInterests", // 페이징을 위한 count 쿼리 nativeQuery = true) Page