From 18ad4f19deafca70f926d9276cbfeb95da10a49f Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Thu, 4 Apr 2024 02:15:38 +0900 Subject: [PATCH 01/14] =?UTF-8?q?Refactor:=20service=EC=97=90=20=EC=9E=88?= =?UTF-8?q?=EB=8D=98=20of=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/VideoSummaryService.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java index 4cbcf34..efd4fd8 100644 --- a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java +++ b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java @@ -60,17 +60,6 @@ public VideoSummaryInitiateResponse initiateSummarizing(VideoSummaryInitiateRequ return new VideoSummaryInitiateResponse(videoCode); } - private static VideoSummaryStatusCache of(VideoSummaryInitiateRequest summaryInitiateRequest, String videoCode, Long userId) { - return VideoSummaryStatusCache.builder() - .videoCode(videoCode) - .videoSummaryId(-1L) - .status("PROCESSING") - .userId(userId) - .isCategoryIncluded(summaryInitiateRequest.getIsCategoryIncluded()) - .categoryId(summaryInitiateRequest.getCategoryId()) - .build(); - } - public VideoSummaryDto getVideoSummaryById(Long videoSummaryId) { Optional videoSummary = videoSummaryRepository.findById(videoSummaryId); return VideoSummaryDto.from(videoSummary.get()); From e9b06ba356057c7036c51b57a268bb8b617ca1ab Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Thu, 4 Apr 2024 16:55:58 +0900 Subject: [PATCH 02/14] =?UTF-8?q?Docs:=20swagger=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduationproject/controller/VideoSummaryController.java | 2 +- .../domain/dto/video/VideoSummaryInitiateRequest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java b/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java index d057f1f..449f09d 100644 --- a/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java +++ b/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java @@ -25,7 +25,7 @@ public class VideoSummaryController { private final VideoSummaryService videoSummaryService; - @Operation(summary = "카테고리 미지정 영상 요약 요청", description = "영상 요약 요청을 위한 메소드") + @Operation(summary = "영상 요약 요청", description = "영상 요약 요청을 위한 메소드") @ApiResponse(content = @Content(schema = @Schema(implementation = VideoSummaryInitiateResponse.class))) @PostMapping("/summaries/initiate") @ResponseStatus(HttpStatus.ACCEPTED) diff --git a/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryInitiateRequest.java b/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryInitiateRequest.java index 6711f6a..83f30c5 100644 --- a/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryInitiateRequest.java +++ b/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryInitiateRequest.java @@ -14,7 +14,7 @@ public class VideoSummaryInitiateRequest { String url; @Schema(description = "카테고리 아이디", nullable = true, example = "1") Long categoryId; - @Schema(description = "(임시) 사용자가 카테고리를 지정했는지 여부", example = "true") + @Schema(description = "사용자가 카테고리를 지정했는지 여부", example = "true") Boolean isCategoryIncluded; - Long userId; + Long userId = 1L; } From 11b1ac63f88f184f29bf9f4a137c1bed5a57a6df Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Fri, 5 Apr 2024 00:43:20 +0900 Subject: [PATCH 03/14] =?UTF-8?q?Style:=20=EA=B3=B5=EB=B0=B1=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduationproject/controller/VideoSummaryController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java b/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java index 449f09d..681d4b8 100644 --- a/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java +++ b/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java @@ -55,4 +55,4 @@ public Response getSummaryByVideoSummaryId(@PathVariable(name = log.info("summary requested videoSummaryId = {}", videoSummaryId); return Response.createSuccess(videoSummaryService.getVideoSummaryById(videoSummaryId)); } -} +} \ No newline at end of file From 421839262c4d96749935181ed00b08f1269571c6 Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Sat, 6 Apr 2024 17:53:00 +0900 Subject: [PATCH 04/14] =?UTF-8?q?Refactor:=20=EC=98=81=EC=83=81=20?= =?UTF-8?q?=EC=9A=94=EC=95=BD=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=B6=88=EA=B0=80=20=EC=8B=9C=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hongik/graduationproject/exception/ErrorCode.java | 3 ++- .../hongik/graduationproject/service/VideoSummaryService.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java b/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java index bb6eb1a..07f83f0 100644 --- a/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java +++ b/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java @@ -9,7 +9,8 @@ public enum ErrorCode { INVALID_VIDEO_URL(HttpStatus.BAD_REQUEST, "유효하지 않은 영상 URL입니다."), ALREADY_REQUESTED_SUMMARIZING(HttpStatus.BAD_REQUEST, "사용자가 이미 해당 영상을 요약 요청했습니다. 잠시 후 다시 시도하세요"), - FAILED_TO_EXTRACT_EXTRACT_ID(HttpStatus.BAD_REQUEST, "영상의 고유 ID를 추출하는데 실패했습니다."); + FAILED_TO_EXTRACT_EXTRACT_ID(HttpStatus.BAD_REQUEST, "영상의 고유 ID를 추출하는데 실패했습니다."), + VIDEO_SUMMARY_NOT_FOUND(HttpStatus.NOT_FOUND,"영상 요약 정보를 찾을 수 없습니다"); private final HttpStatus httpStatus; private final String message; } diff --git a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java index efd4fd8..c5fafa6 100644 --- a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java +++ b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java @@ -61,8 +61,8 @@ public VideoSummaryInitiateResponse initiateSummarizing(VideoSummaryInitiateRequ } public VideoSummaryDto getVideoSummaryById(Long videoSummaryId) { - Optional videoSummary = videoSummaryRepository.findById(videoSummaryId); - return VideoSummaryDto.from(videoSummary.get()); + VideoSummary videoSummary = videoSummaryRepository.findById(videoSummaryId).orElseThrow(() -> new AppException(ErrorCode.VIDEO_SUMMARY_NOT_FOUND)); + return VideoSummaryDto.from(videoSummary); } @Transactional From a0bf5439fe7a3ceb219aad553946eae6364cf1b0 Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Mon, 8 Apr 2024 10:42:19 +0900 Subject: [PATCH 05/14] =?UTF-8?q?Refactor:=20VideoSummaryDto=EA=B0=80=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=EB=8F=84=20=EB=A6=AC?= =?UTF-8?q?=ED=84=B4=ED=95=98=EA=B2=8C=EB=81=94=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduationproject/domain/dto/video/VideoSummaryDto.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryDto.java b/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryDto.java index 86e709b..a3ccbdb 100644 --- a/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryDto.java +++ b/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryDto.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.hongik.graduationproject.domain.entity.VideoSummary; +import com.hongik.graduationproject.eum.MainCategory; import com.hongik.graduationproject.eum.Platform; import lombok.AllArgsConstructor; import lombok.Builder; @@ -27,6 +28,7 @@ public class VideoSummaryDto { String address; LocalDateTime createdAt; Platform platform; + String mainCategory; public static VideoSummaryDto from(VideoSummary videoSummary) { @@ -40,6 +42,7 @@ public static VideoSummaryDto from(VideoSummary videoSummary) { .address(videoSummary.getAddress()) .createdAt(videoSummary.getCreatedAt().minusHours(9)) .platform(videoSummary.getPlatform()) + .mainCategory(videoSummary.getGeneratedMainCategory().getName()) .build(); } From 0cde35c0aa05bab2941a7af2ee43af5cab4e6bb7 Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Mon, 8 Apr 2024 12:55:04 +0900 Subject: [PATCH 06/14] =?UTF-8?q?Feat:=20=EC=84=9C=EB=B8=8C=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EB=AA=A9=EB=A1=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CategoryController.java | 25 +++++++++++++++ .../dto/category/SubCategoryListRequest.java | 9 ++++++ .../dto/category/SubCategoryListResponse.java | 8 +++++ .../dto/category/SubCategoryResponse.java | 7 +++++ .../repository/CategoryRepository.java | 5 +++ .../repository/UserRepository.java | 2 +- .../service/CategoryService.java | 31 +++++++++++++++++++ 7 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hongik/graduationproject/controller/CategoryController.java create mode 100644 src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryListRequest.java create mode 100644 src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryListResponse.java create mode 100644 src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryResponse.java create mode 100644 src/main/java/com/hongik/graduationproject/service/CategoryService.java diff --git a/src/main/java/com/hongik/graduationproject/controller/CategoryController.java b/src/main/java/com/hongik/graduationproject/controller/CategoryController.java new file mode 100644 index 0000000..95d05de --- /dev/null +++ b/src/main/java/com/hongik/graduationproject/controller/CategoryController.java @@ -0,0 +1,25 @@ +package com.hongik.graduationproject.controller; + +import com.hongik.graduationproject.domain.dto.Response; +import com.hongik.graduationproject.domain.dto.category.SubCategoryListRequest; +import com.hongik.graduationproject.domain.dto.category.SubCategoryListResponse; +import com.hongik.graduationproject.eum.MainCategory; +import com.hongik.graduationproject.service.CategoryService; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api") +public class CategoryController { + private final CategoryService categoryService; + + @GetMapping("/categories") + public Response getSubCategoryList(@RequestParam MainCategory mainCategory) { + return Response.createSuccess(categoryService.getSubCategoryList(mainCategory)); + } +} diff --git a/src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryListRequest.java b/src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryListRequest.java new file mode 100644 index 0000000..6301c19 --- /dev/null +++ b/src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryListRequest.java @@ -0,0 +1,9 @@ +package com.hongik.graduationproject.domain.dto.category; + +import com.hongik.graduationproject.eum.MainCategory; +import lombok.Data; + +public record SubCategoryListRequest( + MainCategory mainCategory +) { +} diff --git a/src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryListResponse.java b/src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryListResponse.java new file mode 100644 index 0000000..9c14316 --- /dev/null +++ b/src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryListResponse.java @@ -0,0 +1,8 @@ +package com.hongik.graduationproject.domain.dto.category; + +import java.util.List; + +public record SubCategoryListResponse( + List subCategoryList +) { +} diff --git a/src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryResponse.java b/src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryResponse.java new file mode 100644 index 0000000..592962f --- /dev/null +++ b/src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryResponse.java @@ -0,0 +1,7 @@ +package com.hongik.graduationproject.domain.dto.category; + +public record SubCategoryResponse ( + String subCategory, + Long categoryId +){ +} diff --git a/src/main/java/com/hongik/graduationproject/repository/CategoryRepository.java b/src/main/java/com/hongik/graduationproject/repository/CategoryRepository.java index ed2ff74..538e847 100644 --- a/src/main/java/com/hongik/graduationproject/repository/CategoryRepository.java +++ b/src/main/java/com/hongik/graduationproject/repository/CategoryRepository.java @@ -1,13 +1,18 @@ package com.hongik.graduationproject.repository; import com.hongik.graduationproject.domain.entity.Category; +import com.hongik.graduationproject.domain.entity.User; import com.hongik.graduationproject.eum.MainCategory; +import jakarta.validation.constraints.Min; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import java.util.List; import java.util.Optional; public interface CategoryRepository extends JpaRepository { @Query("select c from Category c where c.user.id = :userId and c.mainCategory = :mainCategory and c.subCategory = '기타'") Optional findDefaultCategoryByUserIdAndMainCategory(Long userId, MainCategory mainCategory); + + List findAllByMainCategoryAndUser(MainCategory mainCategory, User user); } diff --git a/src/main/java/com/hongik/graduationproject/repository/UserRepository.java b/src/main/java/com/hongik/graduationproject/repository/UserRepository.java index 4be7cd6..cdef28c 100644 --- a/src/main/java/com/hongik/graduationproject/repository/UserRepository.java +++ b/src/main/java/com/hongik/graduationproject/repository/UserRepository.java @@ -6,7 +6,7 @@ import org.springframework.stereotype.Repository; @Repository -public interface UserRepository extends JpaRepository { +public interface UserRepository extends JpaRepository { public User findByEmail(String email); public User findByKakaoId(Long kakaoId); diff --git a/src/main/java/com/hongik/graduationproject/service/CategoryService.java b/src/main/java/com/hongik/graduationproject/service/CategoryService.java new file mode 100644 index 0000000..ce8364d --- /dev/null +++ b/src/main/java/com/hongik/graduationproject/service/CategoryService.java @@ -0,0 +1,31 @@ +package com.hongik.graduationproject.service; + +import com.hongik.graduationproject.domain.dto.category.SubCategoryListRequest; +import com.hongik.graduationproject.domain.dto.category.SubCategoryListResponse; +import com.hongik.graduationproject.domain.dto.category.SubCategoryResponse; +import com.hongik.graduationproject.domain.entity.User; +import com.hongik.graduationproject.eum.MainCategory; +import com.hongik.graduationproject.repository.CategoryRepository; +import com.hongik.graduationproject.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class CategoryService { + private final CategoryRepository categoryRepository; + private final UserRepository userRepository; + + public SubCategoryListResponse getSubCategoryList(MainCategory mainCategory) { + User user = userRepository.getReferenceById(1L); +// MainCategory mainCategory = subCategoryListRequest.mainCategory();/ + + List subCategoryList = categoryRepository.findAllByMainCategoryAndUser(mainCategory, user).stream() + .map(category -> new SubCategoryResponse(category.getSubCategory(), category.getId())) + .toList(); + return new SubCategoryListResponse(subCategoryList); + } +} From bf86e44d5944ddd6394531e50ffcafd54de96df6 Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Mon, 8 Apr 2024 12:57:52 +0900 Subject: [PATCH 07/14] =?UTF-8?q?Refactor:=20getSubCategoryList=EC=97=90?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=EC=BD=94=EB=93=9C=20=EB=AA=85=EC=8B=9C?= =?UTF-8?q?=ED=95=98=EA=B2=8C=EB=81=94=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduationproject/controller/CategoryController.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hongik/graduationproject/controller/CategoryController.java b/src/main/java/com/hongik/graduationproject/controller/CategoryController.java index 95d05de..cab406e 100644 --- a/src/main/java/com/hongik/graduationproject/controller/CategoryController.java +++ b/src/main/java/com/hongik/graduationproject/controller/CategoryController.java @@ -7,10 +7,8 @@ import com.hongik.graduationproject.service.CategoryService; import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @@ -18,6 +16,7 @@ public class CategoryController { private final CategoryService categoryService; + @ResponseStatus(HttpStatus.OK) @GetMapping("/categories") public Response getSubCategoryList(@RequestParam MainCategory mainCategory) { return Response.createSuccess(categoryService.getSubCategoryList(mainCategory)); From d889174b9052516920521c9e0e1f31cf7d26265e Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Mon, 8 Apr 2024 17:01:52 +0900 Subject: [PATCH 08/14] =?UTF-8?q?Feat:=20categoryId=EC=97=90=20=ED=95=B4?= =?UTF-8?q?=EB=8B=B9=ED=95=98=EB=8A=94=20=EC=98=81=EC=83=81=20=EC=9A=94?= =?UTF-8?q?=EC=95=BD=20=EB=AA=A9=EB=A1=9D=EC=9D=84=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=ED=95=98=EB=8A=94=20api=20=EA=B5=AC=ED=98=84=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/VideoSummaryController.java | 21 +++++++----- .../dto/video/VideoSummaryListResponse.java | 11 +++++++ .../dto/video/VideoSummaryResponse.java | 33 +++++++++++++++++++ .../VideoSummaryCategoryRepository.java | 4 +++ .../service/VideoSummaryService.java | 9 +++++ 5 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryListResponse.java create mode 100644 src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java diff --git a/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java b/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java index 681d4b8..ca88055 100644 --- a/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java +++ b/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java @@ -1,10 +1,7 @@ package com.hongik.graduationproject.controller; import com.hongik.graduationproject.domain.dto.Response; -import com.hongik.graduationproject.domain.dto.video.VideoSummaryDto; -import com.hongik.graduationproject.domain.dto.video.VideoSummaryInitiateRequest; -import com.hongik.graduationproject.domain.dto.video.VideoSummaryInitiateResponse; -import com.hongik.graduationproject.domain.dto.video.VideoSummaryStatusResponse; +import com.hongik.graduationproject.domain.dto.video.*; import com.hongik.graduationproject.service.VideoSummaryService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -39,8 +36,8 @@ public Response initiateSummarizing(@RequestBody V @GetMapping("/summaries/status/{videoCode}") @ResponseStatus(HttpStatus.OK) public Response getSummarizeStatus(@PathVariable(name = "videoCode") - @Parameter(name = "videoCode", description = "영상 요약 요청에서 응답받은 비디오 코드", example = "INSTAGRAM_C4kWXhEuQpD") - String videoCode) { + @Parameter(name = "videoCode", description = "영상 요약 요청에서 응답받은 비디오 코드", example = "INSTAGRAM_C4kWXhEuQpD") + String videoCode) { log.info("summarize status request videoCode = {}", videoCode); return Response.createSuccess(videoSummaryService.getStatus(videoCode)); } @@ -50,9 +47,17 @@ public Response getSummarizeStatus(@PathVariable(nam @GetMapping("/summaries/{videoSummaryId}") @ResponseStatus(HttpStatus.OK) public Response getSummaryByVideoSummaryId(@PathVariable(name = "videoSummaryId") - @Parameter(name = "videoSummaryId", description = "영상 요약 상태에서 응답받은 videoSummaryId", example = "3") - Long videoSummaryId) { + @Parameter(name = "videoSummaryId", description = "영상 요약 상태에서 응답받은 videoSummaryId", example = "3") + Long videoSummaryId) { log.info("summary requested videoSummaryId = {}", videoSummaryId); return Response.createSuccess(videoSummaryService.getVideoSummaryById(videoSummaryId)); } + + @GetMapping("/summaries") + @ResponseStatus(HttpStatus.OK) + public Response getAllSummariesByCategoryId(@RequestParam Long categoryId) { + return Response.createSuccess(videoSummaryService.getAllSummariesByCategoryId(categoryId)); + } + + } \ No newline at end of file diff --git a/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryListResponse.java b/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryListResponse.java new file mode 100644 index 0000000..95345ae --- /dev/null +++ b/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryListResponse.java @@ -0,0 +1,11 @@ +package com.hongik.graduationproject.domain.dto.video; + + +import com.hongik.graduationproject.domain.entity.VideoSummary; + +import java.util.List; + +public record VideoSummaryListResponse( + List videoSummaryList +) { +} diff --git a/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java b/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java new file mode 100644 index 0000000..8b03486 --- /dev/null +++ b/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java @@ -0,0 +1,33 @@ +package com.hongik.graduationproject.domain.dto.video; + +import com.hongik.graduationproject.domain.entity.VideoSummary; +import com.hongik.graduationproject.eum.Platform; + +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.List; + +public record VideoSummaryResponse( + String title, + String description, + List keywords, + String url, + String summary, + String address, + LocalDateTime createdAt, + Platform platform +) { + public VideoSummaryResponse(VideoSummary videoSummary) { + this( + videoSummary.getTitle(), + videoSummary.getDescription(), + Arrays.stream(videoSummary.getKeywords().split(",")).toList(), + videoSummary.getUrl(), + videoSummary.getSummary(), + videoSummary.getAddress(), + videoSummary.getCreatedAt(), + videoSummary.getPlatform() + ); + } + +} diff --git a/src/main/java/com/hongik/graduationproject/repository/VideoSummaryCategoryRepository.java b/src/main/java/com/hongik/graduationproject/repository/VideoSummaryCategoryRepository.java index 8a3ba34..58c14be 100644 --- a/src/main/java/com/hongik/graduationproject/repository/VideoSummaryCategoryRepository.java +++ b/src/main/java/com/hongik/graduationproject/repository/VideoSummaryCategoryRepository.java @@ -1,7 +1,11 @@ package com.hongik.graduationproject.repository; +import com.hongik.graduationproject.domain.entity.Category; import com.hongik.graduationproject.domain.entity.VideoSummaryCategory; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface VideoSummaryCategoryRepository extends JpaRepository { + List findAllByCategory(Category category); } diff --git a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java index c5fafa6..a95dde6 100644 --- a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java +++ b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java @@ -17,6 +17,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; import java.util.Optional; @Service @@ -79,4 +80,12 @@ public VideoSummaryStatusResponse getStatus(String videoCode) { } return VideoSummaryStatusResponse.from(statusCache); } + + public VideoSummaryListResponse getAllSummariesByCategoryId(Long categoryId) { + Category category = categoryRepository.getReferenceById(categoryId); + List videoSummaryResponseList = videoSummaryCategoryRepository.findAllByCategory(category).stream() + .map(videoSummaryCategory -> new VideoSummaryResponse(videoSummaryCategory.getVideoSummary())) + .toList(); + return new VideoSummaryListResponse(videoSummaryResponseList); + } } From 914a04ec78c6c6bfd10bf7e1481212595e2a2cae Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Mon, 8 Apr 2024 17:04:32 +0900 Subject: [PATCH 09/14] =?UTF-8?q?Refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=95=84=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/dto/video/VideoSummaryResponse.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java b/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java index 8b03486..3660fe4 100644 --- a/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java +++ b/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java @@ -9,23 +9,17 @@ public record VideoSummaryResponse( String title, - String description, List keywords, String url, - String summary, String address, - LocalDateTime createdAt, Platform platform ) { public VideoSummaryResponse(VideoSummary videoSummary) { this( videoSummary.getTitle(), - videoSummary.getDescription(), Arrays.stream(videoSummary.getKeywords().split(",")).toList(), videoSummary.getUrl(), - videoSummary.getSummary(), videoSummary.getAddress(), - videoSummary.getCreatedAt(), videoSummary.getPlatform() ); } From a7b3b7744de2975e3dfd5b6254501e6312534675 Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Mon, 8 Apr 2024 17:14:38 +0900 Subject: [PATCH 10/14] =?UTF-8?q?Refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20import=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduationproject/domain/dto/video/VideoSummaryResponse.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java b/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java index 3660fe4..7142100 100644 --- a/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java +++ b/src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java @@ -3,7 +3,6 @@ import com.hongik.graduationproject.domain.entity.VideoSummary; import com.hongik.graduationproject.eum.Platform; -import java.time.LocalDateTime; import java.util.Arrays; import java.util.List; From 17c76f785cb223eba0355c568156fb4259f27932 Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Mon, 8 Apr 2024 17:14:55 +0900 Subject: [PATCH 11/14] =?UTF-8?q?Feat:=20getAllSummariesByCategoryId?= =?UTF-8?q?=EC=97=90=20swagger=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduationproject/controller/VideoSummaryController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java b/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java index ca88055..7e07dbb 100644 --- a/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java +++ b/src/main/java/com/hongik/graduationproject/controller/VideoSummaryController.java @@ -53,9 +53,11 @@ public Response getSummaryByVideoSummaryId(@PathVariable(name = return Response.createSuccess(videoSummaryService.getVideoSummaryById(videoSummaryId)); } + @Operation(summary = "영상 요약 목록 조회", description = "categoryId로 영상 요약 목록 조회를 위한 메소드") + @ApiResponse(content = @Content(schema = @Schema(implementation = VideoSummaryListResponse.class))) @GetMapping("/summaries") @ResponseStatus(HttpStatus.OK) - public Response getAllSummariesByCategoryId(@RequestParam Long categoryId) { + public Response getAllSummariesByCategoryId(@Parameter(required = true) @RequestParam Long categoryId) { return Response.createSuccess(videoSummaryService.getAllSummariesByCategoryId(categoryId)); } From 1a7738495cd03edc5e3490e4c078b9ef1526347c Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Thu, 11 Apr 2024 12:23:50 +0900 Subject: [PATCH 12/14] =?UTF-8?q?Feat:=20getSubCategoryList()=EC=97=90=20s?= =?UTF-8?q?wagger=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduationproject/controller/CategoryController.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hongik/graduationproject/controller/CategoryController.java b/src/main/java/com/hongik/graduationproject/controller/CategoryController.java index cab406e..70ea94f 100644 --- a/src/main/java/com/hongik/graduationproject/controller/CategoryController.java +++ b/src/main/java/com/hongik/graduationproject/controller/CategoryController.java @@ -1,11 +1,14 @@ package com.hongik.graduationproject.controller; import com.hongik.graduationproject.domain.dto.Response; -import com.hongik.graduationproject.domain.dto.category.SubCategoryListRequest; import com.hongik.graduationproject.domain.dto.category.SubCategoryListResponse; +import com.hongik.graduationproject.domain.dto.video.VideoSummaryListResponse; import com.hongik.graduationproject.eum.MainCategory; import com.hongik.graduationproject.service.CategoryService; -import lombok.Getter; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @@ -16,6 +19,8 @@ public class CategoryController { private final CategoryService categoryService; + @Operation(summary = "서브 카테고리 목록 조회", description = "사용자의 특정 메인 카테고리에 해당하는 서브 카테고리 목록 조회를 위한 메소드") + @ApiResponse(content = @Content(schema = @Schema(implementation = SubCategoryListResponse.class))) @ResponseStatus(HttpStatus.OK) @GetMapping("/categories") public Response getSubCategoryList(@RequestParam MainCategory mainCategory) { From a36013f107de3128dbfee3cb11bdab6a391c781e Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Thu, 11 Apr 2024 23:17:09 +0900 Subject: [PATCH 13/14] =?UTF-8?q?Refactor:=20RequestParam=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduationproject/config/WebConfig.java | 14 ++++++++++++++ .../converter/MainCategoryRequestConverter.java | 15 +++++++++++++++ .../graduationproject/exception/ErrorCode.java | 4 +++- .../exception/GlobalExceptionHandler.java | 12 ++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hongik/graduationproject/config/WebConfig.java create mode 100644 src/main/java/com/hongik/graduationproject/config/converter/MainCategoryRequestConverter.java diff --git a/src/main/java/com/hongik/graduationproject/config/WebConfig.java b/src/main/java/com/hongik/graduationproject/config/WebConfig.java new file mode 100644 index 0000000..ced1a45 --- /dev/null +++ b/src/main/java/com/hongik/graduationproject/config/WebConfig.java @@ -0,0 +1,14 @@ +package com.hongik.graduationproject.config; + +import com.hongik.graduationproject.config.converter.MainCategoryRequestConverter; +import org.springframework.context.annotation.Configuration; +import org.springframework.format.FormatterRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + @Override + public void addFormatters(FormatterRegistry registry) { + registry.addConverter(new MainCategoryRequestConverter()); + } +} diff --git a/src/main/java/com/hongik/graduationproject/config/converter/MainCategoryRequestConverter.java b/src/main/java/com/hongik/graduationproject/config/converter/MainCategoryRequestConverter.java new file mode 100644 index 0000000..c9f8992 --- /dev/null +++ b/src/main/java/com/hongik/graduationproject/config/converter/MainCategoryRequestConverter.java @@ -0,0 +1,15 @@ +package com.hongik.graduationproject.config.converter; + +import com.hongik.graduationproject.eum.MainCategory; +import com.hongik.graduationproject.exception.AppException; +import com.hongik.graduationproject.exception.ErrorCode; +import org.springframework.core.convert.ConversionFailedException; +import org.springframework.core.convert.converter.Converter; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; + +public class MainCategoryRequestConverter implements Converter { + @Override + public MainCategory convert(String source) { + return MainCategory.valueOf(source.toUpperCase()); + } +} diff --git a/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java b/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java index 07f83f0..8bae177 100644 --- a/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java +++ b/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java @@ -10,7 +10,9 @@ public enum ErrorCode { INVALID_VIDEO_URL(HttpStatus.BAD_REQUEST, "유효하지 않은 영상 URL입니다."), ALREADY_REQUESTED_SUMMARIZING(HttpStatus.BAD_REQUEST, "사용자가 이미 해당 영상을 요약 요청했습니다. 잠시 후 다시 시도하세요"), FAILED_TO_EXTRACT_EXTRACT_ID(HttpStatus.BAD_REQUEST, "영상의 고유 ID를 추출하는데 실패했습니다."), - VIDEO_SUMMARY_NOT_FOUND(HttpStatus.NOT_FOUND,"영상 요약 정보를 찾을 수 없습니다"); + VIDEO_SUMMARY_NOT_FOUND(HttpStatus.NOT_FOUND,"영상 요약 정보를 찾을 수 없습니다"), + MAIN_CATEGORY_NOT_EXISTS(HttpStatus.BAD_REQUEST,"해당 메인 카테고리가 존재하지 않습니다."); + private final HttpStatus httpStatus; private final String message; } diff --git a/src/main/java/com/hongik/graduationproject/exception/GlobalExceptionHandler.java b/src/main/java/com/hongik/graduationproject/exception/GlobalExceptionHandler.java index 18cc863..63afbd9 100644 --- a/src/main/java/com/hongik/graduationproject/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/hongik/graduationproject/exception/GlobalExceptionHandler.java @@ -2,9 +2,13 @@ import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; +import org.springframework.core.convert.ConversionFailedException; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.method.annotation.MethodArgumentConversionNotSupportedException; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; @RestControllerAdvice @@ -19,4 +23,12 @@ ResponseEntity AppExceptionHandler(AppException ex, HttpServletRe .body(ErrorResponse.of(ex.getErrorCode())); } + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + public ResponseEntity handleConflict(MethodArgumentTypeMismatchException ex) { + log.error("ConversionFailedException: {}", ex.getMessage()); + return ResponseEntity + .status(ErrorCode.MAIN_CATEGORY_NOT_EXISTS.getHttpStatus()) + .body(ErrorResponse.of(ErrorCode.MAIN_CATEGORY_NOT_EXISTS)); + } + } From 39d841b80d7473d0a797c00a97bd32a7db0a06b4 Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Sat, 13 Apr 2024 15:32:22 +0900 Subject: [PATCH 14/14] =?UTF-8?q?Refactor:=20=ED=82=A4=EC=9B=8C=EB=93=9C?= =?UTF-8?q?=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=EC=97=B4=EB=A1=9C=20=EB=B3=80=ED=99=98=ED=95=A0=20=EB=95=8C=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hongik/graduationproject/domain/entity/VideoSummary.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/hongik/graduationproject/domain/entity/VideoSummary.java b/src/main/java/com/hongik/graduationproject/domain/entity/VideoSummary.java index a2273c7..ac1c4bd 100644 --- a/src/main/java/com/hongik/graduationproject/domain/entity/VideoSummary.java +++ b/src/main/java/com/hongik/graduationproject/domain/entity/VideoSummary.java @@ -55,7 +55,7 @@ private static String listToString(List keywords) { for (String keyword : keywords) { sb.append(keyword).append(','); } - return sb.substring(0, sb.length() - 2); + return sb.substring(0, sb.length() - 1); } else { return ""; }