Skip to content

[DDING-001] 폼지 수정 로직 개선#294

Merged
5uhwann merged 12 commits intodevelopfrom
refactor/DDING-001
Mar 12, 2025
Merged

[DDING-001] 폼지 수정 로직 개선#294
5uhwann merged 12 commits intodevelopfrom
refactor/DDING-001

Conversation

@5uhwann
Copy link
Copy Markdown
Collaborator

@5uhwann 5uhwann commented Mar 8, 2025

🚀 작업 내용

폼지 수정 시 지원자 답변 내역 삭제 에러 해결을 위한 로직 개선

  • 에러 원인

    • 기존의 폼지 수정 로직 중 formField 수정 시 모든 formField 삭제 후 재생성 하는 로직 존재
    • 현재 API는 운영상의 이유로 폼지의 모집 마감기한만 수정 가능
    • 모집 마감기한 수정 요청 시 formField가 모두 삭제되고 이와 연관된 formAnswer 모두 삭제
  • 폼지 질문 수정 로직 개선

    • Form, FormField의 양방향 연관관계 설정
    • 폼지 수정 시 추가된 FormField, 삭제된 FormField, 수정된 FormField를 구분하여 List에 반영하도록 구현

🤔 고민했던 내용

💬 리뷰 중점사항

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • 폼 관리 기능이 개선되어, 필드 추가·수정·삭제가 더욱 효율적으로 수행됩니다.
    • 각 폼 필드에 식별자(ID)가 도입되어 데이터 관리의 일관성이 강화되었습니다.
    • 폼 응답 및 신청에 소프트 딜리트 기능이 추가되어, 삭제된 항목이 향후 복구 가능합니다.
  • Tests

    • 폼 관련 기능의 안정성을 검증하는 새로운 테스트 케이스들이 추가되었습니다.

@5uhwann 5uhwann added 🎯리팩토링 리팩토링 및 고도화 이슈 D-1 labels Mar 8, 2025
@5uhwann 5uhwann self-assigned this Mar 8, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 8, 2025

Walkthrough

이번 PR은 여러 도메인 클래스와 DTO에서의 메서드 명 변경, 필드 추가, 그리고 엔티티 간 관계 개선 등을 포함합니다.

  • ClubClubMember 클래스에서 메서드 이름이 올바르게 수정되었습니다.
  • UpdateFormRequestFormResponse DTO에 식별자(id) 필드가 추가되었으며, 이에 따른 변환 로직이 업데이트되었습니다.
  • Form 엔티티에서는 다대일 관계를 위한 formFields 필드와 관련 관리 메서드가 도입되었고, FormField 생성자와 업데이트 메서드가 보완되었습니다.
  • 또한, FacadeCentralFormServiceImpl의 업데이트 로직이 간소화되고, 소프트 삭제를 위한 어노테이션이 FormAnswerFormApplication에 추가되었으며, 단위 테스트가 보강되었습니다.

Changes

파일 경로 변경 요약
src/.../club/entity/Club.java
src/.../clubmember/entity/ClubMember.java
Club.addClubMember에서 clubMember.setClubFormConveniencesetClubForConvenience로 수정 및 해당 메서드명 변경
src/.../form/controller/dto/request/UpdateFormRequest.java
src/.../form/controller/dto/response/FormResponse.java
UpdateFormFieldRequestFormFieldListResponseid 필드 추가 및 변환 메서드 업데이트
src/.../form/entity/Form.java
src/.../form/entity/FormField.java
Form 엔티티에 formFields(일대다 관계) 필드와 관리 메서드(addFormFields, updateFormFields) 추가,
FormField 생성자에 id 추가, 새 메서드 도입 (setFormForConvenience, update)
src/.../form/service/FacadeCentralFormServiceImpl.java updateForm 메서드가 기존 필드 삭제 후 재생성 방식에서, Form.updateFormFields 호출을 통한 직접 업데이트 방식으로 변경 및 포맷 수정
src/.../form/service/dto/command/UpdateFormCommand.java UpdateFormFieldCommandid 필드 추가 및 엔티티 빌더 업데이트
src/.../formapplication/entity/FormAnswer.java
src/.../formapplication/entity/FormApplication.java
소프트 삭제 구현을 위해 @SQLDelete@SQLRestriction 어노테이션 추가
src/.../form/entity/FormTest.java Form 엔티티의 필드 추가, 수정, 삭제 기능에 대한 단위 테스트 클래스 추가

Sequence Diagram(s)

sequenceDiagram
    participant U as UpdateFormCommand
    participant S as FacadeCentralFormServiceImpl
    participant F as Form
    participant FF as FormField

    U->>S: updateForm(updateFormFieldCommands)
    S->>F: updateFormFields(updatedFormFields)
    F->>FF: 각 FormField 처리 (업데이트/추가/삭제)
Loading

Possibly related PRs

Suggested reviewers

  • wonjunYou
  • KoSeonJe
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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
Copy Markdown
Collaborator

@Seooooo24 Seooooo24 left a comment

Choose a reason for hiding this comment

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

LGTM... 고생 많으셨습니다!
코드 살펴보면서 몰랐던 부분도 많이 알게 됐습니다...ㅎㅎ

Copy link
Copy Markdown
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.

제 주관적인 피드백이 조금 들어간 것도 있고, 해결해야할 것도 있는 것 같아요!
알맞게 수정해주시면 될 것 같아요!!

Comment on lines +100 to +105
List<FormField> deletedFormFields = this.formFields.stream()
.filter(formField -> updatedFormFields.stream()
.filter(updatedFormField -> updatedFormField.getId() != null)
.noneMatch(updatedField -> updatedField.getId().equals(formField.getId())))
.toList();
this.formFields.removeAll(deletedFormFields);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

p4)
가독성을 위해 private 메소드로 분리해도 좋을 것 같아요

List<FormField> deletedFormFields = this.formFields.stream()
.filter(formField -> updatedFormFields.stream()
.filter(updatedFormField -> updatedFormField.getId() != null)
.noneMatch(updatedField -> updatedField.getId().equals(formField.getId())))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.noneMatch(updatedField -> updatedField.getId().equals(formField.getId())))
.noneMatch(updatedField -> updatedField.isEqualsId(formField)))

p5)
사소하지만 formField 내부에서 처리해줘도 좋을 것 같아요!

// 삭제될 폼 필드
List<FormField> deletedFormFields = this.formFields.stream()
.filter(formField -> updatedFormFields.stream()
.filter(updatedFormField -> updatedFormField.getId() != null)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.filter(updatedFormField -> updatedFormField.getId() != null)
.filter(updatedFormField -> updatedFormField.existId())

p5)
이것도 사소하지만, formField 내부에서 처리해도 좋을 것 같아요!

@github-actions github-actions bot added D-0 and removed D-1 labels Mar 9, 2025
5uhwann added 2 commits March 10, 2025 21:27
Introduce a `deleted_at` column to `form_answer` and `form_application` tables to support soft deletes. Also, update `email` and `phone_number` in `form_application` to enforce non-null constraints with increased length.
Copy link
Copy Markdown

@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: 0

🧹 Nitpick comments (3)
src/main/java/ddingdong/ddingdongBE/domain/formapplication/entity/FormAnswer.java (3)

16-16: LocalDateTime 임포트
deletedAt 필드를 처리하기 위해 LocalDateTime을 사용하고 있습니다. 타임존 고려가 필요한 경우 ZonedDateTime 등 다른 타입도 고민해볼 수 있습니다.


37-37: value 컬럼의 TEXT 변환
List<String> 데이터를 TEXT 필드로 저장하도록 설정하셨습니다. 대량 데이터가 저장될 수 있으니 DB 성능이나 인덱스 전략을 주의 깊게 살펴보세요.


48-49: deletedAt 필드 컬럼 정의
TIMESTAMP 컬럼으로 선언되었습니다. 시간대가 중요한 서비스라면 TIMESTAMP WITH TIME ZONE 적용 여부를 검토해보시길 권장합니다.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1e4198c and af39ead.

📒 Files selected for processing (3)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/entity/FormAnswer.java (3 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/entity/FormApplication.java (2 hunks)
  • src/main/resources/db/migration/V43__alter_table_form_application_and_form_answer.sql (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/entity/FormApplication.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and analyze
🔇 Additional comments (9)
src/main/resources/db/migration/V43__alter_table_form_application_and_form_answer.sql (4)

1-2: 소프트 삭제 컬럼 추가 (form_answer)
소프트 삭제 구현을 위해 deleted_at 컬럼이 추가되었습니다. NULL 허용으로 설정되었으니, 삭제 로직이 예상대로 동작하는지 확인해 주세요.


4-5: 소프트 삭제 컬럼 추가 (form_application)
form_application 테이블에도 동일하게 deleted_at을 추가하여 soft delete 로직을 일관성 있게 유지할 수 있습니다. 문제 없어 보입니다.


7-8:

Details

❓ Verification inconclusive

email 컬럼 수정
이메일 컬럼을 255자로 확장하고 NOT NULL 제약을 추가하였습니다. 기존 데이터 중 null 이나 255자를 초과하는 값이 없는지 확인이 필요합니다.


🏁 Script executed:

#!/bin/bash
echo "SELECT COUNT(*) AS NullEmailCount FROM form_application WHERE email IS NULL;"
echo "SELECT COUNT(*) AS TooLongEmailCount FROM form_application WHERE LENGTH(email) > 255;"

Length of output: 343


이메일 컬럼 수정 – 데이터 무결성 검증 필요

이 변경사항으로 인해 이메일 컬럼이 255자로 확장되고 NOT NULL 제약이 추가되었습니다. 다만, 제공된 검증 스크립트는 실제 쿼리 실행 결과가 아닌 쿼리문 텍스트만을 출력했으므로, 실제 데이터베이스 환경에서 아래 쿼리를 실행하여 이메일 컬럼에 null 값이나 255자를 초과하는 값이 없는지 재검증해 주시기 바랍니다.

  • 검증할 쿼리:
    • SELECT COUNT(*) AS NullEmailCount FROM form_application WHERE email IS NULL;
    • SELECT COUNT(*) AS TooLongEmailCount FROM form_application WHERE LENGTH(email) > 255;

10-11:

Details

❓ Verification inconclusive

phone_number 컬럼 수정
phone_number 컬럼을 255자로 확장하고 NOT NULL 제약을 추가하였습니다. 기존 데이터 중 null 이나 255자를 초과하는 값이 없는지 확인해 주세요.


🏁 Script executed:

#!/bin/bash
echo "SELECT COUNT(*) AS NullPhoneCount FROM form_application WHERE phone_number IS NULL;"
echo "SELECT COUNT(*) AS TooLongPhoneCount FROM form_application WHERE LENGTH(phone_number) > 255;"

Length of output: 371


전화번호 컬럼 변경 내용 및 검증 요청

  • form_application 테이블의 phone_number 컬럼이 VARCHAR(255)로 확장되고, NOT NULL 제약이 추가되었습니다.
  • 변경 전에 기존 데이터에 null 값이나 255자를 초과하는 데이터가 있는지 반드시 확인해 주세요.
  • 리뷰에 포함된 아래 SQL 쿼리를 실제 데이터베이스에 실행하여 검증하시기 바랍니다.
SELECT COUNT(*) AS NullPhoneCount FROM form_application WHERE phone_number IS NULL;
SELECT COUNT(*) AS TooLongPhoneCount FROM form_application WHERE LENGTH(phone_number) > 255;
src/main/java/ddingdong/ddingdongBE/domain/formapplication/entity/FormAnswer.java (5)

7-7: JPA 컬럼 어노테이션 임포트
JPA 컬럼 선언에 필요한 임포트가 추가되었습니다. 별다른 문제 없습니다.


22-23: Hibernate 소프트 삭제용 어노테이션 임포트
소프트 삭제 구현에 필요한 @SQLDelete, @SQLRestriction 어노테이션이 올바르게 추가되었습니다. JPA 동작과의 충돌 없이 정상 작동하는지 확인해 주세요.


28-29: 소프트 삭제 로직 정의
@SQLDelete@SQLRestriction으로 삭제 시점을 CURRENT_TIMESTAMP로 기록하고, 조회 시 deleted_atNULL인 경우만 반환하도록 설정되었습니다. 이전 리뷰에서 요청되었던 deleted_at 필드가 잘 반영되어 일관성이 있습니다.


52-57: Builder 매개변수에 deletedAt 추가
deletedAt 인자를 포함해 객체를 생성할 수 있게 되어, 소프트 삭제 시점을 주입하거나 테스트하는 데 유연성이 높아졌습니다.


61-61: deletedAt 필드 설정
생성자 내부에서 deletedAt 필드에 값을 할당하고 있습니다. 특별한 로직이 없어 보이며 정상적인 구현으로 보입니다.

@sonarqubecloud
Copy link
Copy Markdown

@5uhwann 5uhwann merged commit 481451e into develop Mar 12, 2025
4 checks passed
@5uhwann 5uhwann deleted the refactor/DDING-001 branch March 12, 2025 07:14
KoSeonJe pushed a commit that referenced this pull request Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

D-0 🎯리팩토링 리팩토링 및 고도화 이슈

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants