Skip to content

Commit

Permalink
feat : history add, view add
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmjys954646 committed Nov 5, 2023
1 parent f4e6f5b commit 72e3755
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
10 changes: 2 additions & 8 deletions src/main/java/com/example/demo/video/VideoRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public ResponseEntity<?> getCategoryFilterVideo(@RequestParam(value = "category"
}

@GetMapping("/videos/{id}")
public ResponseEntity<?> getVideoId(@PathVariable int id) {
VideoResponse.VideoResponseDTO responseDTO = videoService.findVideo(id);
public ResponseEntity<?> getVideoId(@PathVariable int id, @AuthenticationPrincipal CustomUserDetails userDetails) {
VideoResponse.VideoResponseDTO responseDTO = videoService.findVideo(id, userDetails.getUser());
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO));
}

Expand All @@ -42,10 +42,4 @@ public ResponseEntity<?> getVideoHistory(@RequestParam(value = "page", defaultVa
List<VideoResponse.VideoAllResponseDTO> responseDTO = videoService.findHistoryVideo(page, userDetails.getUser().getId());
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO));
}

@PostMapping("videos/view/{id}")
public ResponseEntity<?> postVideoView(@PathVariable int id){
videoService.addVideoView(id);
return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent());
}
}
16 changes: 9 additions & 7 deletions src/main/java/com/example/demo/video/VideoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.demo.config.errors.exception.Exception404;
import com.example.demo.interest.Interest;
import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import com.example.demo.user.userInterest.UserInterestJPARepository;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -73,10 +74,17 @@ public List<VideoResponse.VideoPageResponseDTO> findAllVideo(int categoryId) {
return videoPageResponseDTOS;
}

public VideoResponse.VideoResponseDTO findVideo(int id) {
public VideoResponse.VideoResponseDTO findVideo(int id, User user) {
Video video = videoJPARepository.findById(id)
.orElseThrow(() -> new Exception404("해당 영상이 존재하지 않습니다.\n" + "id : " + id));

video.addView();
if(user != null)
{
VideoHistory videoHistory = new VideoHistory(user, video);
videoHistoryJPARepository.save(videoHistory);
}

VideoInterest videoInterest = videoInterestJPARepository.findVideoInterestByVideoId(video.getId());
List<Subtitle> videoSubtitles = subtitleJPARepository.findSubtitleByVideoId(video.getId());

Expand Down Expand Up @@ -133,10 +141,4 @@ public List<VideoResponse.VideoAllResponseDTO> findUserCategory(int id) {
).collect(Collectors.toList());
return videoDTOList;
}

public void addVideoView(int id) {
Video video = videoJPARepository.findById(id)
.orElseThrow(() -> new Exception404("해당 영상이 존재하지 않습니다.\n" + "id : " + id));
video.addView();
}
}
34 changes: 16 additions & 18 deletions src/test/java/com/example/demo/VideoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,20 @@ void findAllTest() throws Exception{

@Test
@Order(2)
void findTest() throws Exception{
VideoResponse.VideoResponseDTO videoFind = videoService.findVideo(1);
org.assertj.core.api.Assertions.assertThat(1)
.isEqualTo(videoFind.getVideoID());
Assertions.assertThat("asdfasdf")
.isEqualTo(videoFind.getSubtitles().get(0).getKorSubtitleContent());
void HistoryTest() throws Exception{
User user2 = User.builder()
.email("[email protected]")
.password("asdf1234!")
.firstName("Jin")
.lastName("Seung")
.country("Korea")
.age(21)
.role(Role.MENTOR)
.phone("010-0000-0000")
.build();

userJPARepository.save(user2);
VideoResponse.VideoResponseDTO videoFind = videoService.findVideo(3,user2);
}

@Test
Expand All @@ -311,23 +319,13 @@ void findHistoryTest() throws Exception{
@Test
@Order(2)
void findUserCategoryTest() throws Exception{
//List<VideoResponse.VideoAllResponseDTO> findUserCategory = videoService.findUserCategory(1);

}

@Test
@Order(3)
void addView() throws Exception{
videoService.addVideoView(1);
VideoResponse.VideoResponseDTO videoFind = videoService.findVideo(1);
org.assertj.core.api.Assertions.assertThat(26)
.isEqualTo(videoFind.getViews());
List<VideoResponse.VideoAllResponseDTO> findUserCategory = videoService.findUserCategory(1);
}

@Test
@Order(3)
void findOmTest() throws Exception {
List<VideoResponse.VideoAllResponseDTO> videoFind = videoService.findUserCategory(1);
List<VideoResponse.VideoAllResponseDTO> videoFind = videoService.findHistoryVideo(0,2);

String responseBody = om.writeValueAsString(videoFind);

Expand Down

0 comments on commit 72e3755

Please sign in to comment.