Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDING-50] SSE ACK API 구현 #208

Merged
merged 8 commits into from
Jan 13, 2025
Merged

[DDING-50] SSE ACK API 구현 #208

merged 8 commits into from
Jan 13, 2025

Conversation

5uhwann
Copy link
Collaborator

@5uhwann 5uhwann commented Jan 12, 2025

🚀 작업 내용

  • Sse VodProcessNotification ack Api 구현 - POST /server/vod-processing-notification/ack

🤔 고민했던 내용

💬 리뷰 중점사항

Summary by CodeRabbit

릴리즈 노트

  • 새로운 기능

    • 비디오 처리 알림 시스템 개선
    • VOD 처리 작업에 대한 알림 승인 기능 추가
  • 개선 사항

    • 서버 전송 이벤트(SSE) 알림 구조 업데이트
    • 비디오 처리 알림의 상태 관리 로직 강화
    • 알림을 ID로 검색할 수 있는 기능 추가
  • 기술적 변경

    • 알림 처리를 위한 새로운 컨트롤러 및 서비스 계층 도입
    • 알림 상태 업데이트를 위한 새로운 API 엔드포인트 추가

@5uhwann 5uhwann added ✨기능 기능 개발 및 구현 🎯리팩토링 리팩토링 및 고도화 이슈 labels Jan 12, 2025
@5uhwann 5uhwann self-assigned this Jan 12, 2025
Copy link

coderabbitai bot commented Jan 12, 2025

Walkthrough

이 풀 리퀘스트는 비디오 온디맨드(VOD) 처리 알림 시스템에 대한 주요 변경 사항을 포함하고 있습니다. 주요 변경 사항은 VOD 처리 알림을 위한 새로운 API, 컨트롤러, 서비스, DTO를 도입하여 알림 처리 메커니즘을 개선하는 것입니다. 서버 전송 이벤트(SSE)를 통해 VOD 처리 상태를 더 상세하게 전달하고, 알림 상태를 업데이트하는 기능을 추가했습니다.

Changes

파일 경로 변경 요약
src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/... - VodProcessingNotificationApi 인터페이스 추가
- VodProcessingNotificationController 추가
- AckNotificationRequest DTO 추가
- VodProcessingNotification 엔티티에 updateVodNotification 메서드 추가
- FacadeVodProcessingNotificationService 인터페이스 추가
- FacadeVodProcessingNotificationServiceImpl 구현체 추가
- GeneralVodProcessingNotificationServicegetById 메서드 추가
- VodProcessingNotificationService 인터페이스에 getById 메서드 추가
- UpdateAckedNotificationCommand DTO 추가
src/main/java/ddingdong/ddingdongBE/sse/service/dto/... SseVodProcessingNotificationDto DTO 추가
src/main/java/ddingdong/ddingdongBE/domain/feed/service/... FacadeClubFeedServiceImpl의 SSE 이벤트 처리 로직 변경
src/test/java/ddingdong/ddingdongBE/domain/vodprocessing/service/... FacadeVodProcessingNotificationServiceImplTest 테스트 클래스 추가

Suggested Labels

D-0

Suggested Reviewers

  • wonjunYou
  • KoSeonJe

Possibly Related PRs


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 67f0322 and 73a6c2e.

📒 Files selected for processing (1)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/FacadeVodProcessingNotificationServiceImpl.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/FacadeVodProcessingNotificationServiceImpl.java

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (6)
src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/VodProcessingNotificationService.java (1)

9-10: 예외 처리에 대한 문서화가 필요합니다.

getById 메서드가 존재하지 않는 ID로 조회될 경우의 예외 처리 방식을 문서화하면 좋을 것 같습니다. 예를 들어:

  • 어떤 예외가 발생하는지
  • 호출하는 쪽에서 어떻게 처리해야 하는지
src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/controller/VodProcessingNotificationController.java (1)

9-11: API 버전 관리를 고려해보세요.

API 버전 관리를 위해 @RequestMapping 어노테이션을 추가하는 것이 좋겠습니다:

 @RestController
 @RequiredArgsConstructor
+ @RequestMapping("/api/v1")
 public class VodProcessingNotificationController implements VodProcessingNotificationApi {
src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/api/VodProcessingNotificationApi.java (1)

16-20: Swagger 문서를 더 상세하게 보완해주세요.

현재 Operation과 ApiResponse의 설명이 다소 간단합니다. 다음 내용을 추가하면 좋을 것 같습니다:

  • 요청 본문(request body)에 대한 설명
  • 발생 가능한 오류 응답 코드 (예: 400, 404 등)
  • 메서드의 동작 방식에 대한 자세한 설명
src/test/java/ddingdong/ddingdongBE/domain/vodprocessing/service/FacadeVodProcessingNotificationServiceImplTest.java (2)

23-41: 테스트 케이스 보완 필요

다음과 같은 테스트 케이스를 추가하는 것이 좋습니다:

  • 존재하지 않는 알림 ID에 대한 처리
  • 이미 COMPLETED 상태인 알림에 대한 처리
  • 동시에 여러 요청이 들어올 때의 동시성 처리

27-28: 메서드 이름 오타 수정 필요

creatPending()에 오타가 있습니다. createPending()으로 수정해야 합니다.

src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/FacadeVodProcessingJobServiceImpl.java (1)

Line range hint 56-65: 트랜잭션 경계 검토 필요

SSE 이벤트 전송이 트랜잭션 내에서 실행되고 있습니다. 다음 사항들을 고려해야 합니다:

  • 트랜잭션 롤백 시 이벤트 처리 방안
  • 이벤트 전송 실패 시 트랜잭션 처리 방안
  • 장기 실행 트랜잭션 방지
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f75593 and 67f0322.

📒 Files selected for processing (15)
  • src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/api/VodProcessingNotificationApi.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/controller/VodProcessingJobInternalController.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/controller/VodProcessingNotificationController.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/controller/dto/request/AckNotificationRequest.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/entity/VodProcessingNotification.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/FacadeVodProcessingJobServiceImpl.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/FacadeVodProcessingNotificationService.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/FacadeVodProcessingNotificationServiceImpl.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/GeneralVodProcessingNotificationService.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/VodProcessingNotificationService.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/dto/command/UpdateAckedNotificationCommand.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/sse/api/SseConnectionApi.java (0 hunks)
  • src/main/java/ddingdong/ddingdongBE/sse/service/dto/SseVodProcessingNotificationDto.java (1 hunks)
  • src/test/java/ddingdong/ddingdongBE/domain/vodprocessing/service/FacadeVodProcessingNotificationServiceImplTest.java (1 hunks)
💤 Files with no reviewable changes (1)
  • src/main/java/ddingdong/ddingdongBE/sse/api/SseConnectionApi.java
✅ Files skipped from review due to trivial changes (3)
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/controller/VodProcessingJobInternalController.java
  • src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/dto/command/UpdateAckedNotificationCommand.java
  • src/main/java/ddingdong/ddingdongBE/sse/service/dto/SseVodProcessingNotificationDto.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and analyze
🔇 Additional comments (2)
src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/FacadeVodProcessingNotificationService.java (1)

5-8: 인터페이스 설계가 깔끔합니다!

Facade 패턴과 Command 패턴을 적절히 활용하여 알림 업데이트 로직을 잘 캡슐화했습니다.

src/main/java/ddingdong/ddingdongBE/domain/vodprocessing/service/GeneralVodProcessingNotificationService.java (1)

23-27: 구현이 적절해 보입니다!

리소스를 찾을 수 없는 경우의 예외 처리와 에러 메시지가 명확하게 구현되어 있습니다.

Comment on lines +10 to +13
public record AckNotificationRequest(
@Schema(description = "수신 완료 VodProcessingNotificaionId", example = "1")
Long vodNotificationId
) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

입력값 유효성 검증이 필요합니다.

vodNotificationId에 대한 유효성 검증 어노테이션이 누락되었습니다. 다음과 같은 검증을 추가하는 것이 좋겠습니다:

 public record AckNotificationRequest(
         @Schema(description = "수신 완료 VodProcessingNotificaionId", example = "1")
+        @NotNull(message = "알림 ID는 필수입니다")
+        @Positive(message = "알림 ID는 양수여야 합니다")
         Long vodNotificationId
 ) {

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +15 to +18
@Override
public void ackNotification(AckNotificationRequest request) {
facadeVodProcessingNotificationService.updateAckedNotification(request.toCommand());
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

요청 검증과 예외 처리가 필요합니다.

  1. 요청 검증을 위한 @Valid 어노테이션이 누락되었습니다.
  2. 예외 상황(예: 존재하지 않는 알림 ID)에 대한 처리가 필요합니다.
 @Override
- public void ackNotification(AckNotificationRequest request) {
+ public void ackNotification(@Valid AckNotificationRequest request) {
     facadeVodProcessingNotificationService.updateAckedNotification(request.toCommand());
 }

예외 처리를 위한 글로벌 예외 핸들러나 컨트롤러 레벨의 예외 처리를 추가하는 것을 권장드립니다.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Override
public void ackNotification(AckNotificationRequest request) {
facadeVodProcessingNotificationService.updateAckedNotification(request.toCommand());
}
@Override
public void ackNotification(@Valid AckNotificationRequest request) {
facadeVodProcessingNotificationService.updateAckedNotification(request.toCommand());
}

Comment on lines 17 to 23
@Override
public void updateAckedNotification(UpdateAckedNotificationCommand command) {
VodProcessingNotification vodNotification =
vodProcessingNotificationService.getById(command.vodNotificationId());
vodNotification.updateVodNotification(VodNotificationStatus.COMPLETED);

}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

트랜잭션 설정을 수정해주세요.

updateAckedNotification 메서드는 상태를 변경하는 작업을 수행하므로 다음과 같은 수정이 필요합니다:

  1. 메서드에 @Transactional 어노테이션을 추가하여 읽기 전용 설정을 오버라이드
  2. 상태 변경 실패 시의 예외 처리 로직 추가
    @Override
+   @Transactional
    public void updateAckedNotification(UpdateAckedNotificationCommand command) {
        VodProcessingNotification vodNotification =
                vodProcessingNotificationService.getById(command.vodNotificationId());
        vodNotification.updateVodNotification(VodNotificationStatus.COMPLETED);
    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Override
public void updateAckedNotification(UpdateAckedNotificationCommand command) {
VodProcessingNotification vodNotification =
vodProcessingNotificationService.getById(command.vodNotificationId());
vodNotification.updateVodNotification(VodNotificationStatus.COMPLETED);
}
@Override
@Transactional
public void updateAckedNotification(UpdateAckedNotificationCommand command) {
VodProcessingNotification vodNotification =
vodProcessingNotificationService.getById(command.vodNotificationId());
vodNotification.updateVodNotification(VodNotificationStatus.COMPLETED);
}

Comment on lines +59 to +61
public void updateVodNotification(VodNotificationStatus vodNotificationStatus) {
this.vodNotificationStatus = vodNotificationStatus;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

상태 전이 검증 로직이 필요합니다.

현재 구현은 어떤 상태로든 변경이 가능하여 잘못된 상태 전이가 발생할 수 있습니다. 다음과 같은 개선이 필요합니다:

  1. 허용된 상태 전이만 가능하도록 검증 로직 추가
  2. 잘못된 상태 전이 시도 시 예외 처리

예시 구현:

    public void updateVodNotification(VodNotificationStatus vodNotificationStatus) {
+       validateStatusTransition(vodNotificationStatus);
        this.vodNotificationStatus = vodNotificationStatus;
    }

+   private void validateStatusTransition(VodNotificationStatus newStatus) {
+       if (!isValidTransition(this.vodNotificationStatus, newStatus)) {
+           throw new IllegalStateException(
+               String.format("Invalid status transition from %s to %s",
+                   this.vodNotificationStatus, newStatus));
+       }
+   }

+   private boolean isValidTransition(VodNotificationStatus current, VodNotificationStatus next) {
+       return switch (current) {
+           case SENT -> next == VodNotificationStatus.COMPLETED;
+           default -> false;
+       };
+   }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +68 to 74
SseEvent<SseVodProcessingNotificationDto> sseEvent = SseEvent.of(
"vod-processing",
vodProcessingJob.getConvertJobStatus(),
new SseVodProcessingNotificationDto(
vodProcessingJob.getVodProcessingNotification().getId(),
vodProcessingJob.getConvertJobStatus()),
LocalDateTime.now()
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

이벤트 실패 처리 로직 추가 필요

SSE 이벤트 전송 실패 시의 처리 로직이 누락되어 있습니다. 다음 사항들을 고려해야 합니다:

  • 재시도 메커니즘
  • 실패 로깅
  • 클라이언트에게 오류 상태 전달

Comment on lines +57 to 64
SseEvent<SseVodProcessingNotificationDto> sseEvent = SseEvent.of(
"vod-processing",
vodProcessingJob.getConvertJobStatus(),
new SseVodProcessingNotificationDto(
vodProcessingJob.getVodProcessingNotification().getId(),
vodProcessingJob.getConvertJobStatus()),
LocalDateTime.now()
);
sseConnectionService.sendVodProcessingNotification(vodProcessingJob, sseEvent);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

SSE 이벤트 생성 로직 중복 제거 필요

FacadeClubFeedServiceImpl와 동일한 SSE 이벤트 생성 로직이 중복되어 있습니다. 다음과 같은 개선이 필요합니다:

  • 공통 유틸리티 클래스로 이벤트 생성 로직 추출
  • 이벤트 타입 상수 정의
  • 실패 처리 로직 통합

예시 리팩토링:

+ // SseEventFactory.java
+ public class SseEventFactory {
+     public static SseEvent<SseVodProcessingNotificationDto> createVodProcessingEvent(
+             VodProcessingNotification notification,
+             ConvertJobStatus status) {
+         return SseEvent.of(
+             "vod-processing",
+             new SseVodProcessingNotificationDto(notification.getId(), status),
+             LocalDateTime.now()
+         );
+     }
+ }

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Collaborator

@KoSeonJe KoSeonJe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인하였습니다 고생하셨습니다! 코멘트 확인해주세요

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
76.9% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link
Collaborator

@KoSeonJe KoSeonJe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

@5uhwann 5uhwann merged commit f50131f into develop Jan 13, 2025
3 of 4 checks passed
@5uhwann 5uhwann deleted the feature/DDING-50 branch January 13, 2025 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨기능 기능 개발 및 구현 🎯리팩토링 리팩토링 및 고도화 이슈
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants