From 4ac2ccbe4889f9730071772a2b11ddec16ccad70 Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Thu, 26 Oct 2023 23:16:27 +0900 Subject: [PATCH 01/24] =?UTF-8?q?feat=20:=20initialize=20and=20usercategor?= =?UTF-8?q?y=20video=20response=20dto=20restcontroller=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=A0=20=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EB=B0=8F=20restcontroller=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/video/VideoJPARepostiory.java | 7 +++++ .../com/example/demo/video/VideoResponse.java | 4 +++ .../demo/video/VideoRestController.java | 27 +++++++++++++++++++ .../com/example/demo/video/VideoService.java | 12 +++++++++ 4 files changed, 50 insertions(+) create mode 100644 src/main/java/com/example/demo/video/VideoJPARepostiory.java create mode 100644 src/main/java/com/example/demo/video/VideoResponse.java create mode 100644 src/main/java/com/example/demo/video/VideoRestController.java create mode 100644 src/main/java/com/example/demo/video/VideoService.java diff --git a/src/main/java/com/example/demo/video/VideoJPARepostiory.java b/src/main/java/com/example/demo/video/VideoJPARepostiory.java new file mode 100644 index 00000000..2da192ef --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoJPARepostiory.java @@ -0,0 +1,7 @@ +package com.example.demo.video; + +import com.example.demo.user.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface VideoJPARepostiory extends JpaRepository { +} diff --git a/src/main/java/com/example/demo/video/VideoResponse.java b/src/main/java/com/example/demo/video/VideoResponse.java new file mode 100644 index 00000000..f79b730e --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoResponse.java @@ -0,0 +1,4 @@ +package com.example.demo.video; + +public class VideoResponse { +} diff --git a/src/main/java/com/example/demo/video/VideoRestController.java b/src/main/java/com/example/demo/video/VideoRestController.java new file mode 100644 index 00000000..cb4e880f --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoRestController.java @@ -0,0 +1,27 @@ +package com.example.demo.video; + +import com.example.demo.config.auth.CustomUserDetails; +import com.example.demo.config.utils.ApiUtils; +import io.swagger.annotations.Api; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Api(tags = "Video API") +@RequiredArgsConstructor +@RestController +public class VideoRestController { + + private final VideoService videoService; + + @GetMapping("/videos/main") + public ResponseEntity getUserCategoryVideo(@RequestParam(value = "page", defaultValue = "0") Integer page, @AuthenticationPrincipal CustomUserDetails userDetails) { + List responseDTOs = videoService.findUserCategoryVideo(page); + return ResponseEntity.ok(ApiUtils.success(responseDTOs)); + } +} diff --git a/src/main/java/com/example/demo/video/VideoService.java b/src/main/java/com/example/demo/video/VideoService.java new file mode 100644 index 00000000..e7af806c --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoService.java @@ -0,0 +1,12 @@ +package com.example.demo.video; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +@RequiredArgsConstructor +@Service +public class VideoService { + +} From 0b02c4253b3708bde4114ab28b4f240482b5487d Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Thu, 26 Oct 2023 23:36:14 +0900 Subject: [PATCH 02/24] feat : usercategoryVideoResponseDTO videoresponse --- .../java/com/example/demo/video/Video.java | 10 +++++-- .../com/example/demo/video/VideoResponse.java | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/demo/video/Video.java b/src/main/java/com/example/demo/video/Video.java index bdf88b93..e96598d2 100644 --- a/src/main/java/com/example/demo/video/Video.java +++ b/src/main/java/com/example/demo/video/Video.java @@ -22,7 +22,10 @@ public class Video extends BaseTime { private String videoUrl; @Column - private String videoInfo; + private String videoInfoKorean; + + @Column + private String videoInfoEng; @Column private String videoStartTime; @@ -31,9 +34,10 @@ public class Video extends BaseTime { private String videoEndTime; @Builder - public Video(String videoUrl, String videoInfo, String videoStartTime, String videoEndTime) { + public Video(String videoUrl, String videoInfoKorean, String videoInfoEng, String videoStartTime, String videoEndTime) { this.videoUrl = videoUrl; - this.videoInfo = videoInfo; + this.videoInfoKorean = videoInfoKorean; + this.videoInfoEng = videoInfoEng; this.videoStartTime = videoStartTime; this.videoEndTime = videoEndTime; } diff --git a/src/main/java/com/example/demo/video/VideoResponse.java b/src/main/java/com/example/demo/video/VideoResponse.java index f79b730e..8a99dcd2 100644 --- a/src/main/java/com/example/demo/video/VideoResponse.java +++ b/src/main/java/com/example/demo/video/VideoResponse.java @@ -1,4 +1,32 @@ package com.example.demo.video; +import com.example.demo.mentoring.MentorPostResponse; +import com.example.demo.user.userInterest.UserInterest; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; +import java.util.stream.Collectors; + public class VideoResponse { + @Getter + @Setter + public class UserCategoryVideoResponseDTO { + private int videoID; + private String videoUrl; + private String videoInfoKorean; + private String videoInfoEng; + private List interests; + + public UserCategoryVideoResponseDTO(Video video, List videoInterests) + { + this.videoID = video.getId(); + this.videoUrl = video.getVideoUrl(); + this.videoInfoKorean = video.getVideoInfoKorean(); + this.videoInfoEng = video.getVideoInfoEng(); + this.interests = videoInterests.stream() + .map(videoInterest -> videoInterest.getInterest().getCategory()) + .collect(Collectors.toList()); + } + } } From 1c9af4acec2b3f55f0726adfc5be623ccecf7fd8 Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Fri, 3 Nov 2023 17:28:16 +0900 Subject: [PATCH 03/24] =?UTF-8?q?feat=20:=20video=20find=20all=20service?= =?UTF-8?q?=20video=20=ED=8E=98=EC=9D=B4=EC=A7=80=EB=B3=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/demo/video/Subtitle.java | 2 +- .../demo/video/SubtitleJPARepository.java | 12 +++++++ .../java/com/example/demo/video/Video.java | 2 +- .../com/example/demo/video/VideoInterest.java | 2 +- .../video/VideoInterestJPARepository.java | 12 +++++++ .../demo/video/VideoJPARepostiory.java | 3 +- .../com/example/demo/video/VideoResponse.java | 6 ++-- .../demo/video/VideoRestController.java | 2 +- .../com/example/demo/video/VideoService.java | 36 +++++++++++++++++++ 9 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/example/demo/video/SubtitleJPARepository.java create mode 100644 src/main/java/com/example/demo/video/VideoInterestJPARepository.java diff --git a/src/main/java/com/example/demo/video/Subtitle.java b/src/main/java/com/example/demo/video/Subtitle.java index b2107b85..9fc06413 100644 --- a/src/main/java/com/example/demo/video/Subtitle.java +++ b/src/main/java/com/example/demo/video/Subtitle.java @@ -12,7 +12,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "subtitle_tb") +@Table(name = "subtitles") public class Subtitle extends BaseTime { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id diff --git a/src/main/java/com/example/demo/video/SubtitleJPARepository.java b/src/main/java/com/example/demo/video/SubtitleJPARepository.java new file mode 100644 index 00000000..4a12d9d2 --- /dev/null +++ b/src/main/java/com/example/demo/video/SubtitleJPARepository.java @@ -0,0 +1,12 @@ +package com.example.demo.video; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.Optional; + +public interface SubtitleJPARepository extends JpaRepository { + @Query("select m from Subtitle m where m.video.id = :video") + Optional findSubtitleByVideoId(@Param("video") int video); +} diff --git a/src/main/java/com/example/demo/video/Video.java b/src/main/java/com/example/demo/video/Video.java index e96598d2..20af093b 100644 --- a/src/main/java/com/example/demo/video/Video.java +++ b/src/main/java/com/example/demo/video/Video.java @@ -12,7 +12,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "video_tb") +@Table(name = "videos") public class Video extends BaseTime { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id diff --git a/src/main/java/com/example/demo/video/VideoInterest.java b/src/main/java/com/example/demo/video/VideoInterest.java index 11a58b0f..1bbf4842 100644 --- a/src/main/java/com/example/demo/video/VideoInterest.java +++ b/src/main/java/com/example/demo/video/VideoInterest.java @@ -13,7 +13,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "videoInterest_tb") +@Table(name = "video_interests") public class VideoInterest extends BaseTime { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id diff --git a/src/main/java/com/example/demo/video/VideoInterestJPARepository.java b/src/main/java/com/example/demo/video/VideoInterestJPARepository.java new file mode 100644 index 00000000..34d41250 --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoInterestJPARepository.java @@ -0,0 +1,12 @@ +package com.example.demo.video; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; + +public interface VideoInterestJPARepository extends JpaRepository { + @Query("select m from VideoInterest m where m.video.id = :video") + List findVideoInterestByVideoId(@Param("video") int video); +} diff --git a/src/main/java/com/example/demo/video/VideoJPARepostiory.java b/src/main/java/com/example/demo/video/VideoJPARepostiory.java index 2da192ef..8d72b874 100644 --- a/src/main/java/com/example/demo/video/VideoJPARepostiory.java +++ b/src/main/java/com/example/demo/video/VideoJPARepostiory.java @@ -1,7 +1,6 @@ package com.example.demo.video; -import com.example.demo.user.User; import org.springframework.data.jpa.repository.JpaRepository; -public interface VideoJPARepostiory extends JpaRepository { +public interface VideoJPARepostiory extends JpaRepository { } diff --git a/src/main/java/com/example/demo/video/VideoResponse.java b/src/main/java/com/example/demo/video/VideoResponse.java index 8a99dcd2..885826fa 100644 --- a/src/main/java/com/example/demo/video/VideoResponse.java +++ b/src/main/java/com/example/demo/video/VideoResponse.java @@ -11,14 +11,15 @@ public class VideoResponse { @Getter @Setter - public class UserCategoryVideoResponseDTO { + public static class VideoResponseDTO { private int videoID; private String videoUrl; private String videoInfoKorean; private String videoInfoEng; private List interests; + private Subtitle subtitle; - public UserCategoryVideoResponseDTO(Video video, List videoInterests) + public VideoResponseDTO(Video video, List videoInterests, Subtitle subtitle) { this.videoID = video.getId(); this.videoUrl = video.getVideoUrl(); @@ -27,6 +28,7 @@ public UserCategoryVideoResponseDTO(Video video, List videoIntere this.interests = videoInterests.stream() .map(videoInterest -> videoInterest.getInterest().getCategory()) .collect(Collectors.toList()); + this.subtitle = subtitle; } } } diff --git a/src/main/java/com/example/demo/video/VideoRestController.java b/src/main/java/com/example/demo/video/VideoRestController.java index cb4e880f..89c90780 100644 --- a/src/main/java/com/example/demo/video/VideoRestController.java +++ b/src/main/java/com/example/demo/video/VideoRestController.java @@ -21,7 +21,7 @@ public class VideoRestController { @GetMapping("/videos/main") public ResponseEntity getUserCategoryVideo(@RequestParam(value = "page", defaultValue = "0") Integer page, @AuthenticationPrincipal CustomUserDetails userDetails) { - List responseDTOs = videoService.findUserCategoryVideo(page); + List responseDTOs = videoService.findUserCategoryVideo(page); return ResponseEntity.ok(ApiUtils.success(responseDTOs)); } } diff --git a/src/main/java/com/example/demo/video/VideoService.java b/src/main/java/com/example/demo/video/VideoService.java index e7af806c..4a5bd975 100644 --- a/src/main/java/com/example/demo/video/VideoService.java +++ b/src/main/java/com/example/demo/video/VideoService.java @@ -1,12 +1,48 @@ package com.example.demo.video; +import com.example.demo.config.errors.exception.Exception404; +import com.example.demo.mentoring.MentorPostResponse; +import com.example.demo.user.userInterest.UserInterest; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.stream.Collectors; + @Transactional @RequiredArgsConstructor @Service public class VideoService { + private final VideoJPARepostiory videoJPARepostiory; + private final VideoInterestJPARepository videoInterestJPARepository; + private final SubtitleJPARepository subtitleJPARepository; + + public List findAllVideo(Integer page) { + Pageable pageable = PageRequest.of(page,4); + + Page