Skip to content

Commit

Permalink
Refactor: summary 관련 메서드 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhacandy authored Jul 21, 2024
2 parents f1532a4 + 7d7130f commit f23a248
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,30 @@ public Response<VideoSummaryStatusResponse> getSummarizeStatus(@PathVariable(nam
public Response<VideoSummaryDto> getSummaryByVideoSummaryId(@PathVariable(name = "videoSummaryId")
@Parameter(name = "videoSummaryId", description = "영상 요약 상태에서 응답받은 videoSummaryId", example = "3")
Long videoSummaryId,
@AuthenticationPrincipal Long userId
) {
@AuthenticationPrincipal Long userId) {
log.info("summary requested videoSummaryId = {}", videoSummaryId);
return Response.createSuccess(videoSummaryService.getSummaryByVideoSummaryId(videoSummaryId, userId));
}

@Operation(summary = "영상 요약 목록 조회", description = "categoryId로 영상 요약 목록 조회를 위한 메소드")
@ApiResponse(content = @Content(schema = @Schema(implementation = VideoSummaryListResponse.class)))
@GetMapping("/summaries")
@GetMapping("/summaries/list/{categoryId}")
@ResponseStatus(HttpStatus.OK)
public Response<VideoSummaryListResponse> getAllSummariesByCategoryId(@Parameter(required = true) @RequestParam Long categoryId) {
public Response<VideoSummaryListResponse> getAllSummariesByCategoryId(@PathVariable(name = "categoryId")
@Parameter(name = "categoryId", description = "영상 요약 목록을 조회하려는 categoryId", example = "1")
Long categoryId,
@AuthenticationPrincipal Long userId) {
log.info("get all summaries for categoryId = {}", categoryId);
return Response.createSuccess(videoSummaryService.getAllSummariesByCategoryId(categoryId));
return Response.createSuccess(videoSummaryService.getAllSummariesByCategoryId(categoryId, userId));
}

@Operation(summary = "검색 결과 조회", description = "제목 또는 내용에서 검색어를 포함하는 숏폼 조회를 위한 API")
@ApiResponse(content = @Content(schema = @Schema(implementation = Response.class)))
@GetMapping("/summaries/search")
public List<Long> getAllVideoIdsBySearchWord(@Parameter(name = "searchWord", description = "검색어" ) String searchWord){
public Response<List<Long>> getAllVideoIdsBySearchWord(@Parameter(name = "searchWord", description = "검색어" ) String searchWord){
List<Long> videoIds = videoSummaryService.getAllVideoIdsBySearchWord(searchWord);
log.info("검색어 '{}' 에 대한 모든 videoIds 조회 결과: {}", searchWord, videoIds);
return Response.createSuccess(videoIds).getData();
return Response.createSuccess(videoIds);
}

@Operation(summary = "숏폼 삭제", description = "사용자가 원하는 숏폼 삭제하는 메소드")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@

public interface VideoSummaryCategoryRepository extends JpaRepository<VideoSummaryCategory, Long> {

@Query("SELECT vsc FROM VideoSummaryCategory vsc WHERE vsc.category = :category AND vsc.videoSummary.isDeleted = false")
List<VideoSummaryCategory> findAllByCategory(Category category);
@Query("SELECT vsc " +
"FROM VideoSummaryCategory vsc " +
"WHERE vsc.category = :category " +
"AND vsc.category.user = :user " +
"AND vsc.videoSummary.isDeleted = false")
List<VideoSummaryCategory> findAllByCategory(Category category, User user);

@Query("select vsc " +
"from VideoSummaryCategory vsc " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ public VideoSummaryStatusResponse getStatus(String videoCode, Long userId) {
return VideoSummaryStatusResponse.from(statusCache);
}

public VideoSummaryListResponse getAllSummariesByCategoryId(Long categoryId) {
public VideoSummaryListResponse getAllSummariesByCategoryId(Long categoryId, Long userId) {
Category category = categoryRepository.getReferenceById(categoryId);
List<VideoSummaryResponse> videoSummaryResponseList = videoSummaryCategoryRepository.findAllByCategory(category).stream()
User user = userRepository.getReferenceById(userId);
List<VideoSummaryResponse> videoSummaryResponseList = videoSummaryCategoryRepository.findAllByCategory(category,user).stream()
.map(videoSummaryCategory -> new VideoSummaryResponse(videoSummaryCategory.getVideoSummary()))
.toList();
return new VideoSummaryListResponse(videoSummaryResponseList);
Expand Down

0 comments on commit f23a248

Please sign in to comment.