Skip to content

Commit

Permalink
Refactor: 중복 처리 구현 완료로 인한 getStatus() 메소드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
qjvk2880 committed May 25, 2024
1 parent 179bb68 commit eacfee3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit eacfee3

Please sign in to comment.