From ecccfb4c164ecd152da3b575fb639713ef956e64 Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Wed, 22 May 2024 17:48:14 +0900 Subject: [PATCH 1/6] =?UTF-8?q?Refactor:=20=EC=A4=91=EB=B3=B5=20=EC=9A=94?= =?UTF-8?q?=EC=95=BD=20ErrorCode=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hongik/graduationproject/exception/ErrorCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java b/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java index 8bae177..7e2bf84 100644 --- a/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java +++ b/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java @@ -8,7 +8,7 @@ @Getter public enum ErrorCode { INVALID_VIDEO_URL(HttpStatus.BAD_REQUEST, "유효하지 않은 영상 URL입니다."), - ALREADY_REQUESTED_SUMMARIZING(HttpStatus.BAD_REQUEST, "사용자가 이미 해당 영상을 요약 요청했습니다. 잠시 후 다시 시도하세요"), + ALREADY_REQUESTED_SUMMARIZING(HttpStatus.BAD_REQUEST, "사용자가 이미 해당 영상을 요약 요청했습니다."), FAILED_TO_EXTRACT_EXTRACT_ID(HttpStatus.BAD_REQUEST, "영상의 고유 ID를 추출하는데 실패했습니다."), VIDEO_SUMMARY_NOT_FOUND(HttpStatus.NOT_FOUND,"영상 요약 정보를 찾을 수 없습니다"), MAIN_CATEGORY_NOT_EXISTS(HttpStatus.BAD_REQUEST,"해당 메인 카테고리가 존재하지 않습니다."); From 9431ab9dbc7e876b55b8aff40efa45e0aab64479 Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Wed, 22 May 2024 17:49:05 +0900 Subject: [PATCH 2/6] =?UTF-8?q?Feat:=20=ED=95=B4=EB=8B=B9=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=EA=B0=80=20=ED=8A=B9=EC=A0=95=20=EC=98=81?= =?UTF-8?q?=EC=83=81=EC=9D=84=20=EC=9D=B4=EB=AF=B8=20=EC=9A=94=EC=95=BD?= =?UTF-8?q?=ED=96=88=EB=8A=94=EC=A7=80=20=ED=99=95=EC=9D=B8=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/VideoSummaryCategoryRepository.java | 9 +++++++++ .../graduationproject/service/VideoSummaryService.java | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/hongik/graduationproject/repository/VideoSummaryCategoryRepository.java b/src/main/java/com/hongik/graduationproject/repository/VideoSummaryCategoryRepository.java index e1ba988..c01baae 100644 --- a/src/main/java/com/hongik/graduationproject/repository/VideoSummaryCategoryRepository.java +++ b/src/main/java/com/hongik/graduationproject/repository/VideoSummaryCategoryRepository.java @@ -3,7 +3,9 @@ import com.hongik.graduationproject.domain.entity.Category; import com.hongik.graduationproject.domain.entity.VideoSummary; import com.hongik.graduationproject.domain.entity.VideoSummaryCategory; +import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import java.util.List; @@ -11,4 +13,11 @@ public interface VideoSummaryCategoryRepository extends JpaRepository findAllByCategory(Category category); VideoSummaryCategory findByVideoSummary(VideoSummary videoSummary); boolean existsByCategoryAndVideoSummary(Category category, VideoSummary videoSummary); + + @EntityGraph(attributePaths = {"category", "category.user", "videoSummary"}) + @Query("SELECT COUNT(vsc) > 0 " + + "FROM VideoSummaryCategory vsc " + + "WHERE vsc.category.user.id = :userId " + + "AND vsc.videoSummary.videoCode = :videoCode") + boolean existsByVideoCodeAndUserId(String videoCode, Long userId); } diff --git a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java index beb61a1..bab7f25 100644 --- a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java +++ b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java @@ -37,7 +37,7 @@ public VideoSummaryInitiateResponse initiateSummarizing(VideoSummaryInitiateRequ userId = summaryInitiateRequest.getUserId(); - if (summaryStatusCacheRepository.existsByVideoCodeAndUserId(videoCode, userId)) { + if (checkDuplicateSummarizing(videoCode, userId)) { throw new AppException(ErrorCode.ALREADY_REQUESTED_SUMMARIZING); } @@ -61,6 +61,11 @@ public VideoSummaryInitiateResponse initiateSummarizing(VideoSummaryInitiateRequ return new VideoSummaryInitiateResponse(videoCode); } + private boolean checkDuplicateSummarizing(String videoCode, Long userId) { + return videoSummaryCategoryRepository.existsByVideoCodeAndUserId(videoCode, userId) || + summaryStatusCacheRepository.existsByVideoCodeAndUserId(videoCode, userId); + } + // 무조건 중복허용이 안되는 로직 public VideoSummaryDto getVideoSummaryById(Long videoSummaryId) { VideoSummary videoSummary = videoSummaryRepository.getReferenceById(videoSummaryId); From cb1cc1f53a15c0ea37b1e53a91b6cfd2fdbcae0d Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Wed, 22 May 2024 17:50:07 +0900 Subject: [PATCH 3/6] =?UTF-8?q?Refactor:=20statusCache=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=EB=AA=85=EC=9D=84=20mayBeStatusCache=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduationproject/service/VideoSummaryService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java index bab7f25..b45b54b 100644 --- a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java +++ b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java @@ -41,9 +41,9 @@ public VideoSummaryInitiateResponse initiateSummarizing(VideoSummaryInitiateRequ throw new AppException(ErrorCode.ALREADY_REQUESTED_SUMMARIZING); } - Optional statusCache = summaryStatusCacheRepository.findFirstByVideoCode(videoCode); - if (statusCache.isPresent()) { - summaryStatusCacheRepository.save(VideoSummaryStatusCache.of(summaryInitiateRequest, userId, statusCache.get())); + Optional mayBeStatusCache = summaryStatusCacheRepository.findFirstByVideoCode(videoCode); + if (mayBeStatusCache.isPresent()) { + summaryStatusCacheRepository.save(VideoSummaryStatusCache.of(summaryInitiateRequest, userId, mayBeStatusCache.get())); return new VideoSummaryInitiateResponse(videoCode); } From 69f5d19b9b2f1da262df3ec70383139584468cfc Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Wed, 22 May 2024 18:17:19 +0900 Subject: [PATCH 4/6] =?UTF-8?q?Refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20repository=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/ErrorCode.java | 4 +-- .../VideoSummaryStatusCacheRepository.java | 36 +++++++++---------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java b/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java index 7e2bf84..0719b7a 100644 --- a/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java +++ b/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java @@ -11,8 +11,8 @@ public enum ErrorCode { ALREADY_REQUESTED_SUMMARIZING(HttpStatus.BAD_REQUEST, "사용자가 이미 해당 영상을 요약 요청했습니다."), FAILED_TO_EXTRACT_EXTRACT_ID(HttpStatus.BAD_REQUEST, "영상의 고유 ID를 추출하는데 실패했습니다."), VIDEO_SUMMARY_NOT_FOUND(HttpStatus.NOT_FOUND,"영상 요약 정보를 찾을 수 없습니다"), - MAIN_CATEGORY_NOT_EXISTS(HttpStatus.BAD_REQUEST,"해당 메인 카테고리가 존재하지 않습니다."); - + MAIN_CATEGORY_NOT_EXISTS(HttpStatus.BAD_REQUEST,"해당 메인 카테고리가 존재하지 않습니다."), + SUMMARIZING_STATUS_NOT_EXIST(HttpStatus.NOT_FOUND, "요약 정보를 찾을 수 없습니다."); private final HttpStatus httpStatus; private final String message; } diff --git a/src/main/java/com/hongik/graduationproject/repository/VideoSummaryStatusCacheRepository.java b/src/main/java/com/hongik/graduationproject/repository/VideoSummaryStatusCacheRepository.java index 8bc4605..efe4fc6 100644 --- a/src/main/java/com/hongik/graduationproject/repository/VideoSummaryStatusCacheRepository.java +++ b/src/main/java/com/hongik/graduationproject/repository/VideoSummaryStatusCacheRepository.java @@ -1,20 +1,16 @@ -package com.hongik.graduationproject.repository; - - -import com.hongik.graduationproject.domain.entity.cache.VideoSummaryStatusCache; -import org.springframework.data.repository.CrudRepository; - -import java.util.List; -import java.util.Optional; - -public interface VideoSummaryStatusCacheRepository extends CrudRepository { - Optional findByVideoCode(String videoCode); - Optional findFirstByVideoCode(String videoCode); - - boolean existsByVideoCode(String videoCode); - - boolean existsByVideoCodeAndUserId(String videoCode, Long userId); - - Optional findByVideoCodeAndUserId(String videoCode, Long userId); - List findAllByVideoCode(String videoCode); -} +package com.hongik.graduationproject.repository; + + +import com.hongik.graduationproject.domain.entity.cache.VideoSummaryStatusCache; +import org.springframework.data.repository.CrudRepository; + +import java.util.List; +import java.util.Optional; + +public interface VideoSummaryStatusCacheRepository extends CrudRepository { + Optional findFirstByVideoCode(String videoCode); + + boolean existsByVideoCode(String videoCode); + + boolean existsByVideoCodeAndUserId(String videoCode, Long userId); +} From 179bb68338521954be770fcffa4b0c4341fa8a6a Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Wed, 22 May 2024 18:18:36 +0900 Subject: [PATCH 5/6] =?UTF-8?q?Feat:=20=EC=9A=94=EC=95=BD=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EB=A5=BC=20=EC=B0=BE=EC=95=84=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=EC=97=90=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/VideoSummaryStatusCacheRepository.java | 5 ++--- .../graduationproject/service/VideoSummaryService.java | 9 +++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/hongik/graduationproject/repository/VideoSummaryStatusCacheRepository.java b/src/main/java/com/hongik/graduationproject/repository/VideoSummaryStatusCacheRepository.java index efe4fc6..919a358 100644 --- a/src/main/java/com/hongik/graduationproject/repository/VideoSummaryStatusCacheRepository.java +++ b/src/main/java/com/hongik/graduationproject/repository/VideoSummaryStatusCacheRepository.java @@ -9,8 +9,7 @@ public interface VideoSummaryStatusCacheRepository extends CrudRepository { Optional findFirstByVideoCode(String videoCode); - - boolean existsByVideoCode(String videoCode); - + List findAllByVideoCode(String videoCode); + Optional findByVideoCodeAndUserId(String videoCode, Long userId); boolean existsByVideoCodeAndUserId(String videoCode, Long userId); } diff --git a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java index b45b54b..52061ab 100644 --- a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java +++ b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java @@ -6,6 +6,7 @@ import com.hongik.graduationproject.domain.entity.VideoSummaryCategory; import com.hongik.graduationproject.domain.entity.cache.VideoSummaryStatusCache; import com.hongik.graduationproject.eum.Platform; +import com.hongik.graduationproject.eum.SummaryStatus; import com.hongik.graduationproject.exception.AppException; import com.hongik.graduationproject.exception.ErrorCode; import com.hongik.graduationproject.repository.CategoryRepository; @@ -20,6 +21,8 @@ import java.util.List; import java.util.Optional; +import static com.hongik.graduationproject.eum.SummaryStatus.*; + @Service @RequiredArgsConstructor public class VideoSummaryService { @@ -78,8 +81,10 @@ public VideoSummaryDto getVideoSummaryById(Long videoSummaryId) { @Transactional public VideoSummaryStatusResponse getStatus(String videoCode, Long userId) { - VideoSummaryStatusCache statusCache = summaryStatusCacheRepository.findByVideoCode(videoCode).get(); - if (statusCache.getStatus().equals("COMPLETE")) { + VideoSummaryStatusCache statusCache = summaryStatusCacheRepository.findByVideoCodeAndUserId(videoCode, userId) + .orElseThrow(()-> new AppException(ErrorCode.SUMMARIZING_STATUS_NOT_EXIST)); + + if (statusCache.getStatus().equals(PROCESSING.name())) { // Category category = categoryRepository.findDefaultCategoryByUserIdAndMainCategory(userId, statusCache.getGeneratedMainCategory()).get(); Category category = categoryRepository.findDefaultCategoryByUserIdAndMainCategory(1L, statusCache.getGeneratedMainCategory()).get(); VideoSummary videoSummary = videoSummaryRepository.getReferenceById(statusCache.getVideoSummaryId()); From eacfee330e1f196527bbb0db5319ca2a81f18a85 Mon Sep 17 00:00:00 2001 From: qjvk2880 Date: Sat, 25 May 2024 22:53:05 +0900 Subject: [PATCH 6/6] =?UTF-8?q?Refactor:=20=EC=A4=91=EB=B3=B5=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EA=B5=AC=ED=98=84=20=EC=99=84=EB=A3=8C=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=9C=20getStatus()=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/ErrorCode.java | 3 ++- .../service/VideoSummaryService.java | 19 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java b/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java index 0719b7a..068c3e5 100644 --- a/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java +++ b/src/main/java/com/hongik/graduationproject/exception/ErrorCode.java @@ -12,7 +12,8 @@ public enum ErrorCode { FAILED_TO_EXTRACT_EXTRACT_ID(HttpStatus.BAD_REQUEST, "영상의 고유 ID를 추출하는데 실패했습니다."), VIDEO_SUMMARY_NOT_FOUND(HttpStatus.NOT_FOUND,"영상 요약 정보를 찾을 수 없습니다"), MAIN_CATEGORY_NOT_EXISTS(HttpStatus.BAD_REQUEST,"해당 메인 카테고리가 존재하지 않습니다."), - SUMMARIZING_STATUS_NOT_EXIST(HttpStatus.NOT_FOUND, "요약 정보를 찾을 수 없습니다."); + SUMMARIZING_STATUS_NOT_EXIST(HttpStatus.NOT_FOUND, "요약 정보를 찾을 수 없습니다."), + CATEGORY_NOT_EXIST(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 52061ab..4750746 100644 --- a/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java +++ b/src/main/java/com/hongik/graduationproject/service/VideoSummaryService.java @@ -82,21 +82,20 @@ public VideoSummaryDto getVideoSummaryById(Long videoSummaryId) { @Transactional public VideoSummaryStatusResponse getStatus(String videoCode, Long userId) { VideoSummaryStatusCache statusCache = summaryStatusCacheRepository.findByVideoCodeAndUserId(videoCode, userId) - .orElseThrow(()-> new AppException(ErrorCode.SUMMARIZING_STATUS_NOT_EXIST)); + .orElseThrow(() -> new AppException(ErrorCode.SUMMARIZING_STATUS_NOT_EXIST)); - if (statusCache.getStatus().equals(PROCESSING.name())) { + if (statusCache.getStatus().equals(COMPLETE.name())) { // Category category = categoryRepository.findDefaultCategoryByUserIdAndMainCategory(userId, statusCache.getGeneratedMainCategory()).get(); - Category category = categoryRepository.findDefaultCategoryByUserIdAndMainCategory(1L, statusCache.getGeneratedMainCategory()).get(); + Category category = categoryRepository.findDefaultCategoryByUserIdAndMainCategory(1L, statusCache.getGeneratedMainCategory()) + .orElseThrow(() -> new AppException(ErrorCode.CATEGORY_NOT_EXIST)); VideoSummary videoSummary = videoSummaryRepository.getReferenceById(statusCache.getVideoSummaryId()); - if (!videoSummaryCategoryRepository.existsByCategoryAndVideoSummary(category,videoSummary)) { - videoSummaryCategoryRepository.save(VideoSummaryCategory.builder() - .category(category) - .videoSummary(videoSummary) - .build()); - } - summaryStatusCacheRepository.delete(statusCache); + videoSummaryCategoryRepository.save(VideoSummaryCategory.builder() + .category(category) + .videoSummary(videoSummary) + .build()); + summaryStatusCacheRepository.delete(statusCache); } return VideoSummaryStatusResponse.from(statusCache); }