Skip to content

Commit

Permalink
feat: video 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
comom87 committed Nov 9, 2023
2 parents d2e72e5 + 1fc6cdd commit 0c7ea23
Show file tree
Hide file tree
Showing 16 changed files with 601 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public class CustomUserDetailService implements UserDetailsService {

@Override
public CustomUserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
User user = accountJPARepository.findByEmail(email)
.orElseThrow(() -> new UserNotExistException(ErrorCode.NOT_EXIST_USER));
User user = accountJPARepository.findByEmail(email).orElse(null);
return new CustomUserDetails(user);
}
}
1 change: 1 addition & 0 deletions src/main/java/com/example/demo/config/utils/BaseTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public abstract class BaseTime {
@Column(nullable = false)
private LocalDateTime createdAt;

@CreatedDate
@LastModifiedDate
private LocalDateTime updatedAt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MentoringBoard extends BaseTime {
@ManyToOne(fetch = FetchType.LAZY)
private User writer;

@Column(nullable = false)
@Column(length = 100, nullable = false)
private String title;

@Column(length = 300)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import lombok.Getter;
import lombok.Setter;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

public class MentorPostRequest {

@Getter
@Setter
public static class CreateMentorPostDTO {
@NotNull
@Size(max = 100, message = "100자를 초과하면 안됩니다.")
private String title;

@Size(max = 300, message = "300자를 초과하면 안됩니다.")
private String content;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@ public class MentorPostService {
//mentorPost생성
@Transactional
public void createMentorPost(MentorPostRequest.CreateMentorPostDTO createMentorPostDTO, User writer) {
if ( writer.getRole() == Role.MENTEE ) {
throw new Exception401("해당 사용자는 멘티입니다.");
}

//글자수 확인
if(createMentorPostDTO.getContent().length() > 300){
throw new Exception404("글자수가 300자를 넘어갑니다.");
}
isMentor(writer);

MentoringBoard mentoringBoard = new MentoringBoard( writer, createMentorPostDTO.getTitle(), createMentorPostDTO.getContent());

Expand Down Expand Up @@ -98,11 +91,6 @@ public void updateMentorPost(MentorPostRequest.CreateMentorPostDTO createMentorP
MentoringBoard mentoringBoard = mentorPostJPARepository.findById(id).
orElseThrow(() -> new Exception404("해당 글이 존재하지 않습니다."));

//글자수 확인
if(createMentorPostDTO.getContent().length() > 300){
throw new Exception404("글자수가 300자를 넘어갑니다.");
}

try {
mentoringBoard.update(createMentorPostDTO.getTitle(), createMentorPostDTO.getContent());
} catch (Exception e) {
Expand All @@ -111,7 +99,6 @@ public void updateMentorPost(MentorPostRequest.CreateMentorPostDTO createMentorP
}

public void deleteMentorPost(int id, User writer) {

isMentor(writer);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

import com.example.demo.config.security.CustomUserDetails;
import com.example.demo.config.utils.ApiResponseBuilder;
<<<<<<< HEAD:src/main/java/com/example/demo/video/controller/VideoRestController.java
import com.example.demo.video.service.VideoService;
import com.example.demo.video.dto.VideoRequest;
import com.example.demo.video.dto.VideoResponse;
=======
import com.example.demo.user.User;
import io.swagger.annotations.Api;
>>>>>>> 1fc6cdd0c8cccffc40ec26b1ac967c45ff9e3fe4:src/main/java/com/example/demo/video/VideoRestController.java
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -32,12 +37,12 @@ public class VideoRestController {

@GetMapping("/videos")
@Operation(summary = "전체 영상 요청중 category로 필터링")
public ResponseEntity<?> getCategoryFilterVideo(@RequestParam(value = "category", required = false) String category) {
List<VideoResponse.VideoPageResponseDTO> responseDTOs = videoService.findAllVideo(category);
public ResponseEntity<?> getCategoryFilterVideo(@RequestParam(value = "category", required = false) String category, @RequestParam(value = "page", defaultValue = "0") int page); {
List<VideoResponse.VideoPageResponseDTO> responseDTOs = videoService.findAllVideo(category, page);
return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.success(responseDTOs));
}

@GetMapping("/videos/interest")
@GetMapping("/videos/interests")
@Operation(summary = "유저의 흥미있는 영상 요청")
public ResponseEntity<?> getUserCategoryVideo(@AuthenticationPrincipal CustomUserDetails userDetails){
List<VideoResponse.VideoAllResponseDTO> responseDTOs = videoService.findUserCategory(userDetails.getUser().getId());
Expand All @@ -46,15 +51,15 @@ public ResponseEntity<?> getUserCategoryVideo(@AuthenticationPrincipal CustomUse

@GetMapping("/videos/{id}")
@Operation(summary = "영상 개인페이지 요청")
public ResponseEntity<?> getVideoId(@PathVariable int id, @AuthenticationPrincipal CustomUserDetails userDetails) {
public ResponseEntity<?> getVideo(@PathVariable int id, @AuthenticationPrincipal CustomUserDetails userDetails) {
VideoResponse.VideoResponseDTO responseDTO = videoService.findVideo(id, userDetails);
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO));
}

@GetMapping("/videos/history")
@GetMapping("/videos/histories")
@Operation(summary = "영상 시청기록 요청")
public ResponseEntity<?> getVideoHistory(@RequestParam(value = "page", defaultValue = "0") Integer page, @AuthenticationPrincipal CustomUserDetails userDetails) {
List<VideoResponse.VideoAllResponseDTO> responseDTO = videoService.findHistoryVideo(page, userDetails.getUser().getId());
public ResponseEntity<?> getVideoHistoryList(@RequestParam(value = "page", defaultValue = "0") Integer page, @AuthenticationPrincipal CustomUserDetails userDetails) {
List<VideoResponse.VideoHistoryDTO> responseDTO = videoService.findVideoHistoryList(page, userDetails);
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO));
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/example/demo/video/domain/VideoHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.bytebuddy.asm.Advice;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.time.LocalDateTime;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -35,6 +37,7 @@ public class VideoHistory extends BaseTime {
public VideoHistory(User user, Video video) {
this.user = user;
this.video = video;
this.
}

}
17 changes: 17 additions & 0 deletions src/main/java/com/example/demo/video/dto/VideoRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,31 @@ public class VideoRequest {
@Getter
@Setter
public static class VideoDTO {
@NotNull
private String videoUrl;

@NotNull
private String videoTitleKorean;

@NotNull
private String videoTitleEng;

@NotNull
private String VideoIntroduction;

@NotNull
private String videoStartTime;

@NotNull
private String videoEndTime;

@NotNull
private String videoThumbnailUrl;

@NotNull
private List<String> categoryList;

@NotNull
private List<VideoSubtitleDTO> videoSubtitleDTOList;

@Getter
Expand Down
60 changes: 32 additions & 28 deletions src/main/java/com/example/demo/video/dto/VideoResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.demo.video.domain.VideoInterest;
import com.example.demo.video.domain.VideoSubtitle;
import com.example.demo.video.domain.Video;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -11,46 +12,32 @@
import java.util.stream.IntStream;

public class VideoResponse {
private static int recommendVideoNum = 3;
@Getter
@Setter
public static class VideoPageResponseDTO{
private int page;
private List<VideoAllResponseDTO> videoAllResponseDTO;
private boolean last;

public VideoPageResponseDTO(int page, List<VideoAllResponseDTO> videoAllResponseDTO, boolean last){
this.page = page;
this.videoAllResponseDTO = videoAllResponseDTO;
this.last = last;
}
}


@Getter
@Setter
public static class VideoAllResponseDTO {
private int videoID;
public static class VideoHistoryDTO {
private int id;
private String videoUrl;
private String videoTitleKorean;
private String videoTitleEng;
private String interests;
private long views;
private String videoThumbnailUrl;
private String videoIntroduction;
private String videoStartTime;
private String videoEndTime;
private long viewCount;
private String videoThumbnailUrl;
private List<String> categoryList;

public VideoAllResponseDTO(Video video, VideoInterest videoInterest)
{
this.videoID = video.getId();
public VideoHistoryDTO(Video video, List<VideoInterest> videoInterestList) {
this.videoUrl = video.getVideoUrl();
this.videoTitleKorean = video.getVideoTitleKorean();
this.videoTitleKorean = video.getVideoTitleEng();
this.videoTitleEng = video.getVideoTitleEng();
this.interests = videoInterest.getInterest().getCategory();
this.views = video.getViews();
this.videoThumbnailUrl = video.getVideoThumbnailUrl();
this.videoIntroduction = video.getVideoIntroduction();
this.videoStartTime = video.getVideoStartTime();
this.videoEndTime = video.getVideoEndTime();
this.viewCount = video.getViewCount();
this.videoThumbnailUrl = video.getVideoThumbnailUrl();
this.categoryList = videoInterestList.stream()
.map(videoInterest -> videoInterest.getInterest().getCategory())
.collect(Collectors.toList());
}
}

Expand All @@ -65,6 +52,7 @@ public static class VideoResponseDTO {
private String endTime;
private List<SubtitleDTO> subtitles;
private List<RelatedVideoDTO> recommendVideos;

public VideoResponseDTO(Video video, VideoInterest videoInterest, List<VideoSubtitle> videoSubtitles, List<Video> recommendVideos, List<VideoInterest> recommendInterest)
{
this.videoID = video.getId();
Expand Down Expand Up @@ -125,5 +113,21 @@ public RelatedVideoDTO(Video video, VideoInterest videoInterest){
}


// private static int recommendVideoNum = 3;
// @Getter
// @Setter
// public static class VideoPageResponseDTO{
// private int page;
// private List<VideoAllResponseDTO> videoAllResponseDTO;
// private boolean last;
//
// public VideoPageResponseDTO(int page, List<VideoAllResponseDTO> videoAllResponseDTO, boolean last){
// this.page = page;
// this.videoAllResponseDTO = videoAllResponseDTO;
// this.last = last;
// }
// }



}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.example.demo.video.repository;

import com.example.demo.user.domain.User;
import com.example.demo.video.domain.Video;
import com.example.demo.video.domain.VideoHistory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface VideoHistoryJPARepository extends JpaRepository<VideoHistory, Integer> {
@Query("select vh from VideoHistory vh where vh.user.id = :id order by vh.createdAt desc")
Page<VideoHistory> findHistoryVideo(int id, Pageable pageable);
@Query("select vh.video from VideoHistory vh where vh.user.id = :id order by vh.updatedAt desc")
Page<Video> findAllByUserId(int id, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface VideoInterestJPARepository extends JpaRepository<VideoInterest, Integer> {
@Query("select vi from VideoInterest vi where vi.video.id = :video")
VideoInterest findVideoInterestByVideoId(@Param("video") int video);
// @Query("select vi from VideoInterest vi where vi.video.id = :id")
// VideoInterest findVideoInterestByVideoId(@Param("id") int id);

@Query(value = "select vi.video from VideoInterest vi where vi.interest.category = :category")
Page<Video> findByCategory(@Param("category") String category, Pageable pageable);

@Query("select vi from VideoInterest vi where vi.video.id = :id")
List<VideoInterest> findVideoInterestByVideoId(@Param("id") int id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.util.List;

public interface SubtitleJPARepository extends JpaRepository<VideoSubtitle, Integer> {
public interface VideoSubtitleJPARepository extends JpaRepository<VideoSubtitle, Integer> {
@Query("select m from VideoSubtitle m where m.video.id = :video")
List<VideoSubtitle> findSubtitleByVideoId(@Param("video") int video);
}
Loading

0 comments on commit 0c7ea23

Please sign in to comment.