Skip to content

Commit

Permalink
feat : category filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmjys954646 committed Nov 5, 2023
1 parent d750b8b commit a8c3ffe
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/example/demo/video/VideoHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Where(clause = "deleted_at IS NULL")
@SQLDelete(sql = "UPDATE videohistories SET deleted_at = CURRENT_TIMESTAMP, is_deleted = TRUE where id = ?")
@Table(name = "videohistories")
@SQLDelete(sql = "UPDATE video_histories SET deleted_at = CURRENT_TIMESTAMP, is_deleted = TRUE where id = ?")
@Table(name = "video_histories")
public class VideoHistory extends BaseTime {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/example/demo/video/VideoJPARepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public interface VideoJPARepository extends JpaRepository<Video, Integer> {
Page<Video> findByVideoCategory(@Param("userInterests") List<String> userInterests, Pageable pageable);


@Query(value = "select v from Video v inner join VideoInterest vi on v.id = vi.video.id where vi.interest.id = :categoryId")
Page<Video> findByCategoryId(@Param("categoryId") int id, Pageable pageable);
}
4 changes: 2 additions & 2 deletions src/main/java/com/example/demo/video/VideoRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public ResponseEntity<?> getUserCategoryVideo(@AuthenticationPrincipal CustomUse
}

@GetMapping("/videos/main")
public ResponseEntity<?> getCategoryFilterVideo() {
List<VideoResponse.VideoPageResponseDTO> responseDTOs = videoService.findAllVideo();
public ResponseEntity<?> getCategoryFilterVideo(@RequestParam(value = "category", defaultValue = "0") int id) {
List<VideoResponse.VideoPageResponseDTO> responseDTOs = videoService.findAllVideo(id);
return ResponseEntity.ok(ApiUtils.success(responseDTOs));
}

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/example/demo/video/VideoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ public class VideoService {
private final int MAINVIDEONUM = 4;
private final int HISTORYVIDEONUM = 5;

public List<VideoResponse.VideoPageResponseDTO> findAllVideo() {
public List<VideoResponse.VideoPageResponseDTO> findAllVideo(int categoryId) {
Pageable pageable = PageRequest.of(0 ,MAINVIDEOTOTAL);
Page<Video> pageContent = videoJPARepository.findAll(pageable);

Page<Video> pageContent;
if(categoryId == 0)
pageContent = videoJPARepository.findAll(pageable);
else
pageContent = videoJPARepository.findByCategoryId(categoryId, pageable);


if(pageContent.getTotalPages() == 0){
throw new Exception404("해당 영상들이 존재하지 않습니다");
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/com/example/demo/VideoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void save() {
@Test
@Order(2)
void findAllTest() throws Exception{
List<VideoResponse.VideoPageResponseDTO> videoFind = videoService.findAllVideo();
List<VideoResponse.VideoPageResponseDTO> videoFind = videoService.findAllVideo(0);
}

@Test
Expand All @@ -296,8 +296,6 @@ void findTest() throws Exception{
VideoResponse.VideoResponseDTO videoFind = videoService.findVideo(1);
org.assertj.core.api.Assertions.assertThat(1)
.isEqualTo(videoFind.getVideoID());
Assertions.assertThat("첫번째 비디오")
.isEqualTo(videoFind.getVideoTitleKorean());
Assertions.assertThat("asdfasdf")
.isEqualTo(videoFind.getSubtitles().get(0).getKorSubtitleContent());
}
Expand All @@ -320,7 +318,7 @@ void findUserCategoryTest() throws Exception{
@Test
@Order(2)
void findOmTest() throws Exception {
VideoResponse.VideoResponseDTO videoFind = videoService.findVideo(1);
List<VideoResponse.VideoPageResponseDTO> videoFind = videoService.findAllVideo(1);

String responseBody = om.writeValueAsString(videoFind);

Expand Down

0 comments on commit a8c3ffe

Please sign in to comment.