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-112] 지원자 메모하기 API 구현 #262

Merged
merged 4 commits into from
Feb 13, 2025
Merged

Conversation

Seooooo24
Copy link
Collaborator

@Seooooo24 Seooooo24 commented Feb 13, 2025

🚀 작업 내용

지원자 메모하기 API 구현하였습니다.
지원자 상세조회 API 응답 dto에 note 필드를 추가하였습니다.

🤔 고민했던 내용

note 컬럼에 기본값을 지정해주지 않고 null로 둬도 괜찮을지 궁금합니다.

💬 리뷰 중점사항

Summary by CodeRabbit

  • 신규 기능
    • 폼 신청 관련 메모를 업데이트할 수 있는 기능이 추가되었습니다.
    • API 요청 및 응답 모델에 메모 정보가 포함되어, 사용자에게 추가 정보를 제공합니다.
    • 데이터베이스에 새로운 컬럼이 도입되어 폼 신청 메모가 저장됩니다.

Copy link

coderabbitai bot commented Feb 13, 2025

Walkthrough

이 PR은 폼 신청과 관련된 노트 업데이트 기능을 추가합니다. API 인터페이스와 컨트롤러에 updateFormApplicationNote 메서드가 도입되었으며, 이를 지원하기 위해 요청, 응답, 쿼리 DTO에 새로운 note 필드와 변환 로직이 추가되었습니다. 또한, 엔티티 클래스에 노트 필드와 이를 갱신하는 메서드가 포함되었고, 서비스 레이어에서 이를 처리하는 새로운 메서드와 커맨드 객체가 도입되었습니다. 마지막으로, 데이터베이스 마이그레이션 스크립트를 통해 form_application 테이블에 note 컬럼이 추가되었습니다.

Changes

파일 / 경로 변경 내용
.../api/CentralFormApplicationApi.java
.../controller/CentralFormApplicationController.java
updateFormApplicationNote 메서드 추가하여 폼 신청 노트 업데이트 기능 구현
.../dto/request/UpdateFormApplicationNoteRequest.java
.../dto/command/UpdateFormApplicationNoteCommand.java
.../dto/response/FormApplicationResponse.java
.../dto/query/FormApplicationQuery.java
요청, 응답, 쿼리 객체에 note 필드 추가 및 관련 변환/빌더 로직 구현
.../entity/FormApplication.java note 필드와 updateNote 메서드 추가
.../service/FacadeCentralFormApplicationService.java
.../service/FacadeCentralFormApplicationServiceImpl.java
updateNote 메서드 추가 및 구현, 노트 업데이트 관련 비즈니스 로직 처리
.../db/migration/V40_alter_table_form_application_add_column.sql form_application 테이블에 note VARCHAR(500) NULL 컬럼 추가

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller
    participant Service
    participant Entity
    Client->>Controller: updateFormApplicationNote(formId, applicationId, principal, request)
    Controller->>Service: updateNote(command)
    Service->>Entity: updateNote(note)
    Entity-->>Service: 업데이트 결과 반환
    Service-->>Controller: 성공 응답 반환
    Controller-->>Client: 응답 전달
Loading

Possibly related PRs

  • [DDING-000] 지원자 조회 API 수정 #248: 메인 PR의 변경 사항은 FormApplicationResponse 레코드에서 새로운 필드 추가와 관련이 있으며, 두 PR 간의 직접적인 코드 연결을 나타냅니다.

Suggested labels

D-2

Suggested reviewers

  • wonjunYou
  • 5uhwann
  • KoSeonJe
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

@Seooooo24 Seooooo24 changed the title Feature/dding 112 [DDING-112] 지원자 메모하기 API 구현 Feb 13, 2025
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: 2

🧹 Nitpick comments (5)
src/main/java/ddingdong/ddingdongBE/domain/formapplication/entity/FormApplication.java (1)

44-55: 생성자에 note 필드 초기화 로직 추가가 필요합니다.

Builder 패턴을 사용하는 생성자에 note 필드도 포함시켜 일관된 객체 생성이 가능하도록 하는 것이 좋습니다.

     @Builder
     private FormApplication(String name, String studentNumber, String department,
             String phoneNumber, String email,
-            FormApplicationStatus status, Form form) {
+            FormApplicationStatus status, Form form, String note) {
         this.name = name;
         this.studentNumber = studentNumber;
         this.department = department;
         this.phoneNumber = phoneNumber;
         this.email = email;
         this.status = status;
         this.form = form;
+        this.note = note;
     }
src/main/java/ddingdong/ddingdongBE/domain/formapplication/controller/CentralFormApplicationController.java (1)

47-52: 메서드 구현이 잘 되었습니다만, 추가적인 검증이 필요할 수 있습니다.

사용자 권한 검증은 잘 되어 있지만, 폼과 지원서의 존재 여부 확인이 서비스 레이어에 위임되어 있습니다. 이는 괜찮은 접근이지만, 명시적으로 문서화하면 좋을 것 같습니다.

다음과 같이 메서드에 주석을 추가하는 것을 고려해보세요:

+    /**
+     * 지원서 메모를 업데이트합니다.
+     * @throws EntityNotFoundException 폼 또는 지원서가 존재하지 않는 경우
+     * @throws UnauthorizedException 사용자가 권한이 없는 경우
+     */
     @Override
     public void updateFormApplicationNote(Long formId, Long applicationId,
             PrincipalDetails principalDetails, UpdateFormApplicationNoteRequest request) {
src/main/java/ddingdong/ddingdongBE/domain/formapplication/api/CentralFormApplicationApi.java (1)

56-66: API 정의가 잘 되어 있습니다.

OpenAPI 어노테이션을 통한 문서화가 잘 되어 있으며, RESTful 규칙을 잘 따르고 있습니다.

API 문서화를 더욱 상세하게 하면 좋을 것 같습니다:

     @Operation(summary = "지원자 메모하기 API")
+    @Operation(
+        summary = "지원자 메모하기 API",
+        description = "지원서에 대한 메모를 추가하거나 수정합니다. 메모는 관리자만 작성할 수 있습니다."
+    )
     @ApiResponse(responseCode = "204", description = "지원자 메모하기 성공")
+    @ApiResponse(responseCode = "404", description = "지원서를 찾을 수 없음")
+    @ApiResponse(responseCode = "403", description = "권한 없음")
src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/dto/query/FormApplicationQuery.java (1)

25-25: note 필드의 null 안전성을 고려해보세요.

현재 구현에서 note 필드가 null일 수 있는데, 이에 대한 명시적인 처리가 없습니다.

다음과 같은 개선을 고려해보세요:

-        String note,
+        @Schema(nullable = true)
+        String note,

-                .note(formApplication.getNote())
+                .note(Optional.ofNullable(formApplication.getNote()).orElse(""))

Also applies to: 79-79

src/main/java/ddingdong/ddingdongBE/domain/formapplication/controller/dto/response/FormApplicationResponse.java (1)

33-34: 메모 필드의 문서화가 잘 되어있습니다.

Schema 어노테이션을 통한 문서화가 잘 되어 있습니다.

예시 값을 다른 필드들과 일관성 있게 작성하면 좋을 것 같습니다:

-        @Schema(description = "메모", example = "좋은 지원자였습니다.")
+        @Schema(description = "지원자에 대한 메모", example = "적극적이고 열정이 있는 지원자")
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ae1314b and 74b99b9.

📒 Files selected for processing (10)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/api/CentralFormApplicationApi.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/controller/CentralFormApplicationController.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/controller/dto/request/UpdateFormApplicationNoteRequest.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/controller/dto/response/FormApplicationResponse.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/entity/FormApplication.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/FacadeCentralFormApplicationService.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/FacadeCentralFormApplicationServiceImpl.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/dto/command/UpdateFormApplicationNoteCommand.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/dto/query/FormApplicationQuery.java (2 hunks)
  • src/main/resources/db/migration/V40_alter_table_form_application_add_column.sql (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and analyze
🔇 Additional comments (5)
src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/dto/command/UpdateFormApplicationNoteCommand.java (1)

6-14: 구조가 깔끔하고 적절합니다!

커맨드 패턴을 잘 활용하였고, 필요한 모든 필드가 포함되어 있습니다. @Builder 어노테이션의 사용으로 객체 생성이 용이합니다.

src/main/java/ddingdong/ddingdongBE/domain/formapplication/controller/dto/request/UpdateFormApplicationNoteRequest.java (1)

8-21: 검증과 문서화가 잘 되어있습니다!

  • 한글 검증 메시지를 사용한 것이 좋습니다.
  • Swagger 문서화를 위한 예시가 포함되어 있습니다.
  • Command 변환 메서드가 깔끔하게 구현되어 있습니다.
src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/FacadeCentralFormApplicationService.java (1)

16-17: 인터페이스 확장이 일관성 있게 이루어졌습니다!

기존 메서드들과 동일한 패턴을 따르고 있으며, 메서드 시그니처가 적절합니다.

src/main/java/ddingdong/ddingdongBE/domain/formapplication/entity/FormApplication.java (1)

61-63: 메모 업데이트 메서드가 적절히 구현되었습니다!

간단하고 명확한 구현입니다.

src/main/resources/db/migration/V40_alter_table_form_application_add_column.sql (1)

1-2: 마이그레이션 스크립트가 적절히 구현되었습니다.

컬럼 정의가 적절합니다:

  • VARCHAR(500)은 노트 필드에 적합한 크기입니다
  • NULL 허용은 PR 설명에서 언급된 요구사항과 일치합니다

노트 필드의 NULL 허용 여부가 비즈니스 요구사항과 일치하는지 확인해주시기 바랍니다. 현재 구현은 NULL을 허용하고 있으며, 이는 지원자에 대한 메모가 선택적임을 의미합니다.

@@ -39,6 +39,8 @@ public class FormApplication extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
private Form form;

private String note;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

note 필드에 제약 조건 추가가 필요합니다.

데이터베이스 컬럼 크기 제한과 일관성을 위해 @Column 어노테이션에 length 속성을 추가하는 것이 좋습니다.

-    private String note;
+    @Column(length = 1000)
+    private String note;
📝 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
private String note;
@Column(length = 1000)
private String note;

Comment on lines +65 to +70
@Transactional
@Override
public void updateNote(UpdateFormApplicationNoteCommand command) {
FormApplication formApplication = formApplicationService.getById(command.applicationId());
formApplication.updateNote(command.note());
}
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. 노트 내용의 길이 제한 (500자) 검증
  2. 노트 내용의 XSS 방지를 위한 문자열 sanitization
  3. 존재하지 않는 applicationId에 대한 명확한 예외 처리

다음과 같이 수정하는 것을 제안드립니다:

@Transactional
@Override
public void updateNote(UpdateFormApplicationNoteCommand command) {
+   if (command.note() != null && command.note().length() > 500) {
+       throw new IllegalArgumentException("노트는 500자를 초과할 수 없습니다.");
+   }
+   
+   String sanitizedNote = HtmlUtils.htmlEscape(command.note());
    FormApplication formApplication = formApplicationService.getById(command.applicationId());
-   formApplication.updateNote(command.note());
+   formApplication.updateNote(sanitizedNote);
}
📝 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
@Transactional
@Override
public void updateNote(UpdateFormApplicationNoteCommand command) {
FormApplication formApplication = formApplicationService.getById(command.applicationId());
formApplication.updateNote(command.note());
}
@Transactional
@Override
public void updateNote(UpdateFormApplicationNoteCommand command) {
if (command.note() != null && command.note().length() > 500) {
throw new IllegalArgumentException("노트는 500자를 초과할 수 없습니다.");
}
String sanitizedNote = HtmlUtils.htmlEscape(command.note());
FormApplication formApplication = formApplicationService.getById(command.applicationId());
formApplication.updateNote(sanitizedNote);
}

@github-actions github-actions bot added D-1 and removed D-2 labels Feb 13, 2025
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.

확인하였습니다. 사용하지 않는, formId와 user만 제거해주세요!

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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 74b99b9 and dc97c25.

📒 Files selected for processing (3)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/controller/CentralFormApplicationController.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/controller/dto/request/UpdateFormApplicationNoteRequest.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/dto/command/UpdateFormApplicationNoteCommand.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/controller/dto/request/UpdateFormApplicationNoteRequest.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/formapplication/service/dto/command/UpdateFormApplicationNoteCommand.java (1)

1-4: 패키지 구조가 잘 구성되어 있습니다!

Command 패턴에 맞게 적절한 패키지 구조를 가지고 있으며, 필요한 Lombok 어노테이션만 임포트하고 있습니다.

src/main/java/ddingdong/ddingdongBE/domain/formapplication/controller/CentralFormApplicationController.java (1)

4-4: 새로운 DTO import가 적절히 추가되었습니다!

UpdateFormApplicationNoteRequest DTO의 import가 다른 request DTO들과 함께 잘 배치되어 있습니다.

Comment on lines +5 to +11
@Builder
public record UpdateFormApplicationNoteCommand (
Long applicationId,
String note
){

}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

필드 유효성 검증 추가를 고려해보세요.

PR 설명에서 언급된 note 필드의 null 값 처리에 대한 우려와 관련하여, 다음과 같은 개선사항을 제안드립니다:

  1. applicationId@NotNull 어노테이션 추가
  2. note 필드에 대한 명확한 제약조건 정의

다음과 같이 수정해보세요:

+import jakarta.validation.constraints.NotNull;
+
 @Builder
 public record UpdateFormApplicationNoteCommand (
+        @NotNull(message = "신청서 ID는 필수입니다")
         Long applicationId,
         String note
 ){
 }

note 필드의 경우:

  • null을 허용하려면 현재 상태를 유지
  • null을 허용하지 않으려면 @NotNull 추가
  • 빈 문자열을 허용하지 않으려면 @NotBlank 추가
  • 길이 제한이 필요하다면 @Size(max = XXX) 추가

비즈니스 요구사항에 맞는 제약조건을 선택해주세요.

📝 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
@Builder
public record UpdateFormApplicationNoteCommand (
Long applicationId,
String note
){
}
import jakarta.validation.constraints.NotNull;
@Builder
public record UpdateFormApplicationNoteCommand (
@NotNull(message = "신청서 ID는 필수입니다")
Long applicationId,
String note
) {
}

Comment on lines +47 to +51
@Override
public void updateFormApplicationNote(Long formId, Long applicationId,
PrincipalDetails principalDetails, UpdateFormApplicationNoteRequest request) {
facadeCentralFormApplicationService.updateNote(request.toCommand(applicationId));
}
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. formId 파라미터가 사용되지 않고 있습니다. 필요하지 않다면 제거하거나, 필요하다면 검증 로직을 추가해 주세요.
  2. 다른 메서드들과 달리 사용자 인증 검증(User user = principalDetails.getUser())이 누락되었습니다.
  3. 요청 파라미터에 대한 유효성 검사가 없습니다.
  4. 예외 처리가 누락되었습니다.

다음과 같이 수정하는 것을 제안드립니다:

    @Override
    public void updateFormApplicationNote(Long formId, Long applicationId,
            PrincipalDetails principalDetails, UpdateFormApplicationNoteRequest request) {
+       User user = principalDetails.getUser();
+       // formId에 대한 검증 로직 추가
+       facadeCentralFormApplicationService.validateFormAccess(formId, user);
+       // request 유효성 검사
+       if (request == null || applicationId == null) {
+           throw new IllegalArgumentException("Invalid request parameters");
+       }
        facadeCentralFormApplicationService.updateNote(request.toCommand(applicationId));
    }
📝 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 updateFormApplicationNote(Long formId, Long applicationId,
PrincipalDetails principalDetails, UpdateFormApplicationNoteRequest request) {
facadeCentralFormApplicationService.updateNote(request.toCommand(applicationId));
}
@Override
public void updateFormApplicationNote(Long formId, Long applicationId,
PrincipalDetails principalDetails, UpdateFormApplicationNoteRequest request) {
User user = principalDetails.getUser();
// formId에 대한 검증 로직 추가
facadeCentralFormApplicationService.validateFormAccess(formId, user);
// request 유효성 검사
if (request == null || applicationId == null) {
throw new IllegalArgumentException("Invalid request parameters");
}
facadeCentralFormApplicationService.updateNote(request.toCommand(applicationId));
}

Copy link

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

@Seooooo24 Seooooo24 merged commit 3cf8937 into develop Feb 13, 2025
3 of 4 checks passed
@Seooooo24 Seooooo24 deleted the feature/DDING-112 branch February 13, 2025 16:48
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