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-89] 동아리 지원 폼지 상세조회 API 구현 #238

Merged
merged 8 commits into from
Feb 4, 2025

Conversation

KoSeonJe
Copy link
Collaborator

@KoSeonJe KoSeonJe commented Feb 4, 2025

🚀 작업 내용

  • 동아리 지원 폼지 상세조회 API 구현
  • 동아리 지원 폼지 상세조회 API 테스트 작성
  • 이전 Form 테이블 설계시 누락된 sections 컬럼 추가 및 관련 Flyway 파일 작성

Summary by CodeRabbit

  • New Features

    • 사용자가 자신의 양식 목록을 조회하고 특정 양식의 세부 정보를 확인할 수 있도록 새로운 API 엔드포인트가 추가되었습니다.
    • 양식 응답에 여러 섹션 정보를 포함하여 구성과 분류가 개선되었습니다.
    • 양식 데이터의 응답 구조가 강화되어 보다 명확한 정보를 제공합니다.
  • Bug Fixes

    • 날짜 관련 표기 오류가 수정되어 양식 데이터의 일관성과 신뢰성이 향상되었습니다.

Copy link

coderabbitai bot commented Feb 4, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

이번 변경은 중앙 폼 조회 기능을 확장합니다. API 인터페이스와 컨트롤러에 getAllMyFormgetForm 메서드를 추가하여 사용자가 전체 폼 목록과 특정 폼 상세 정보를 조회할 수 있도록 했습니다. 또한 DTO 및 기록(record) 클래스의 필드 명칭(예: endDataendDate)을 수정하고, 폼 엔티티에 sections 필드를 추가하며, 이에 따른 서비스 로직, Repository 메서드, 데이터베이스 마이그레이션, 그리고 단위 테스트도 보완하였습니다.

Changes

파일 변경 내용
src/.../api/CentralFormApi.java
src/.../controller/CentralFormController.java
새로운 폼 조회 엔드포인트 getAllMyFormgetForm 메서드 추가 (API 인터페이스와 컨트롤러 구현)
src/.../dto/response/FormListResponse.java
src/.../dto/response/FormResponse.java
src/.../dto/query/FormListQuery.java
src/.../dto/query/FormQuery.java
DTO 및 기록(record) 클래스 수정: 필드명 오타 수정 (endDataendDate), 새로운 응답 및 쿼리 레코드 추가와 변환 메서드 추가
src/.../entity/Form.java sections 필드 추가 및 생성자, update 메서드 수정 (폼 엔티티에 section 정보 관리)
src/.../repository/FormFieldRepository.java 폼 및 section 기준 조회를 위한 findAllByFormAndSection 메서드 추가
src/.../service/FacadeCentralFormService.java
src/.../service/FacadeCentralFormServiceImpl.java
src/.../service/FormFieldService.java
서비스 인터페이스 및 구현체에 새로운 조회 메서드 (getAllMyForm, getForm) 추가, 불필요한 import 제거
src/.../db/migration/V36__form_add_column_sections.sql form 테이블에 sections 컬럼(TEXT, NOT NULL, 기본값 '[]') 추가
src/.../service/FacadeCentralFormServiceImplTest.java 새로운 단위 테스트 추가: 폼 목록 조회 및 특정 폼 조회 테스트, 기존 EntityManager 관련 설정 제거

Sequence Diagram(s)

sequenceDiagram
    participant U as 사용자
    participant C as CentralFormController
    participant S as FacadeCentralFormServiceImpl
    participant R as Repository/DB

    U->>C: GET /my/forms 또는 /my/forms/{formId} 요청
    C->>S: getAllMyForm(User) 또는 getForm(formId) 호출
    S->>R: 해당 폼 데이터 질의
    R-->>S: 폼 및 폼 필드 데이터 반환
    S-->>C: DTO(Query) 반환
    C-->>U: 최종 응답(FormListResponse 혹은 FormResponse) 전달
Loading

Possibly related PRs

Suggested labels

✨기능, 📖문서, D-0

Suggested reviewers

  • wonjunYou
  • 5uhwann
  • Seooooo24

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 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 e869e10 and 0350fd7.

📒 Files selected for processing (2)
  • src/main/java/ddingdong/ddingdongBE/domain/form/controller/dto/response/FormListResponse.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/service/dto/query/FormListQuery.java (2 hunks)

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.

@github-actions github-actions bot added the D-3 label Feb 4, 2025
@KoSeonJe KoSeonJe self-assigned this Feb 4, 2025
@KoSeonJe KoSeonJe added D-1 and removed D-3 labels Feb 4, 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: 6

🧹 Nitpick comments (3)
src/main/java/ddingdong/ddingdongBE/domain/form/repository/FormFieldRepository.java (1)

12-12: 섹션별 조회 메소드가 잘 추가되었습니다.

Form과 section을 기준으로 FormField를 필터링하는 새로운 메소드가 적절하게 추가되었습니다. 다만, 메소드의 용도와 사용 사례를 명확히 하기 위해 JavaDoc 주석을 추가하는 것을 제안드립니다.

다음과 같이 문서화를 추가하면 좋을 것 같습니다:

+    /**
+     * 특정 Form의 특정 섹션에 속한 모든 FormField를 조회합니다.
+     *
+     * @param form Form 엔티티
+     * @param section 조회할 섹션명
+     * @return 해당 Form의 특정 섹션에 속한 FormField 목록
+     */
     List<FormField> findAllByFormAndSection(Form form, String section);
src/main/java/ddingdong/ddingdongBE/domain/form/service/GeneralFormService.java (1)

37-40: 트랜잭션 처리와 문서화 개선이 필요합니다.

다음 사항들을 고려해 주세요:

  1. 읽기 전용 트랜잭션임을 명시적으로 표시하기 위해 @Transactional(readOnly = true) 어노테이션을 메소드 레벨에 추가하는 것이 좋습니다.
  2. 메소드의 목적과 동작을 설명하는 JavaDoc 문서화를 추가하면 코드의 가독성이 향상될 것입니다.

다음과 같이 개선해 보세요:

+   /**
+    * 특정 클럽에 속한 모든 폼을 조회합니다.
+    *
+    * @param club 조회할 클럽
+    * @return 클럽에 속한 폼 목록
+    */
+   @Transactional(readOnly = true)
    @Override
    public List<Form> getAllByClub(Club club) {
        return formRepository.findAllByClub(club);
    }
src/main/java/ddingdong/ddingdongBE/common/utils/TimeUtils.java (1)

31-35: 날짜 범위 체크 로직을 더 명확하게 개선할 수 있습니다.

현재 구현은 정확하지만, 가독성을 높일 수 있습니다.

다음과 같이 개선해 보세요:

  public static boolean isDateInRange(LocalDate nowDate, LocalDate startDate, LocalDate endDate) {
    if (nowDate == null || startDate == null || endDate == null) {
      return false;
    }
-   return !nowDate.isBefore(startDate) && !nowDate.isAfter(endDate);  }
+   return nowDate.compareTo(startDate) >= 0 && nowDate.compareTo(endDate) <= 0;
+  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8d7d274 and e869e10.

📒 Files selected for processing (20)
  • src/main/java/ddingdong/ddingdongBE/common/utils/TimeUtils.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/activityreport/service/dto/command/CreateActivityReportCommand.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/activityreport/service/dto/command/UpdateActivityReportCommand.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/api/CentralFormApi.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/controller/CentralFormController.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/controller/dto/response/FormListResponse.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/controller/dto/response/FormResponse.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/entity/Form.java (4 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/repository/FormFieldRepository.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/repository/FormRepository.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/service/FacadeCentralFormService.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/service/FacadeCentralFormServiceImpl.java (4 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/service/FormFieldService.java (0 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/service/FormService.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/service/GeneralFormService.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/service/dto/query/FormListQuery.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/service/dto/query/FormQuery.java (1 hunks)
  • src/main/resources/db/migration/V36__form_add_column_sections.sql (1 hunks)
  • src/test/java/ddingdong/ddingdongBE/common/utils/TimeUtilsTest.java (1 hunks)
  • src/test/java/ddingdong/ddingdongBE/domain/form/service/FacadeCentralFormServiceImplTest.java (2 hunks)
💤 Files with no reviewable changes (1)
  • src/main/java/ddingdong/ddingdongBE/domain/form/service/FormFieldService.java
✅ Files skipped from review due to trivial changes (1)
  • src/main/resources/db/migration/V36__form_add_column_sections.sql
🔇 Additional comments (19)
src/main/java/ddingdong/ddingdongBE/domain/form/repository/FormFieldRepository.java (1)

10-10: 기존 메소드가 잘 구현되어 있습니다!

Form 엔티티와 관련된 모든 FormField를 조회하는 기본 메소드가 적절하게 구현되어 있습니다.

src/main/java/ddingdong/ddingdongBE/domain/form/repository/FormRepository.java (1)

10-10: 메소드 구현이 적절합니다!

Spring Data JPA 명명 규칙을 잘 따르고 있으며, 클럽별 폼 조회 기능을 명확하게 구현했습니다.

src/main/java/ddingdong/ddingdongBE/domain/form/service/FormService.java (1)

15-15: 서비스 인터페이스 설계가 깔끔합니다!

서비스 계층의 명명 규칙을 잘 따르고 있으며, 리포지토리 계층과 일관성 있게 구현되었습니다.

src/main/java/ddingdong/ddingdongBE/domain/form/service/FacadeCentralFormService.java (1)

18-20: LGTM! 인터페이스 설계가 명확합니다.

메소드 시그니처가 명확하고 반환 타입이 적절하게 선택되었습니다.

src/main/java/ddingdong/ddingdongBE/domain/activityreport/service/dto/command/UpdateActivityReportCommand.java (1)

3-3: LGTM! TimeUtils로의 마이그레이션이 올바르게 수행되었습니다.

TimeParser에서 TimeUtils로의 변경이 일관성 있게 적용되었습니다.

Also applies to: 25-26

src/main/java/ddingdong/ddingdongBE/domain/activityreport/service/dto/command/CreateActivityReportCommand.java (1)

3-3: 리팩토링이 잘 적용되었습니다!

TimeParser에서 TimeUtils로의 클래스명 변경이 일관성 있게 적용되었습니다.

Also applies to: 26-27

src/main/java/ddingdong/ddingdongBE/domain/form/service/dto/query/FormQuery.java (1)

42-56: DTO 변환 로직이 깔끔하게 구현되었습니다!

FormFormField 엔티티들을 DTO로 변환하는 로직이 스트림 API를 활용하여 간결하고 명확하게 구현되었습니다.

src/main/java/ddingdong/ddingdongBE/domain/form/entity/Form.java (2)

44-46: 새로운 sections 필드가 적절하게 추가되었습니다.

필드가 @column@convert 어노테이션으로 올바르게 설정되어 있습니다.


58-58: 생성자와 업데이트 메서드에 sections 필드가 잘 통합되었습니다.

sections 필드가 생성자와 update 메서드에 적절하게 추가되었습니다.

Also applies to: 66-66

src/main/java/ddingdong/ddingdongBE/domain/form/controller/CentralFormController.java (2)

48-54: getAllMyForm 메서드가 효율적으로 구현되었습니다.

Stream API를 사용하여 응답 변환을 깔끔하게 처리했습니다.


57-60: getForm 메서드가 간결하게 구현되었습니다.

정적 팩토리 메서드를 활용하여 응답 변환을 명확하게 처리했습니다.

src/main/java/ddingdong/ddingdongBE/domain/form/controller/dto/response/FormResponse.java (3)

13-28: 응답 DTO가 명확하게 문서화되었습니다.

Swagger 어노테이션을 통해 각 필드의 설명과 예시가 잘 문서화되어 있습니다.


31-44: 중첩된 FormFieldListResponse 레코드가 잘 구조화되었습니다.

필드 응답에 대한 구조가 명확하며 문서화가 잘 되어있습니다.


58-72: 변환 메서드가 효율적으로 구현되었습니다.

Stream API를 활용하여 formFields 변환을 깔끔하게 처리했습니다.

src/main/java/ddingdong/ddingdongBE/domain/form/api/CentralFormApi.java (2)

63-73: 전체조회 API가 잘 정의되었습니다.

보안 요구사항과 응답 형식이 명확하게 지정되어 있습니다.


75-83: 상세조회 API가 잘 정의되었습니다.

API 문서화가 완벽하며 응답 스키마가 명확합니다.

src/main/java/ddingdong/ddingdongBE/domain/form/service/FacadeCentralFormServiceImpl.java (2)

66-73: 클럽의 모든 폼 조회 로직이 잘 구현되었습니다.

클럽 사용자의 ID를 통해 클럽을 조회하고, 해당 클럽의 모든 폼을 가져와서 FormListQuery로 변환하는 로직이 깔끔하게 구현되었습니다.


82-85: 폼 활성화 상태 체크 로직이 잘 구현되었습니다.

TimeUtils를 활용하여 현재 날짜가 폼의 시작일과 종료일 사이에 있는지 확인하는 로직이 깔끔하게 구현되었습니다.

src/test/java/ddingdong/ddingdongBE/domain/form/service/FacadeCentralFormServiceImplTest.java (1)

203-240: getAllMyForm 테스트가 잘 작성되었습니다.

테스트 시나리오가 명확하고, 예상 결과에 대한 검증이 적절하게 이루어졌습니다.

Comment on lines 8 to 21
class TimeUtilsTest {

@DisplayName("현재 날짜가 기간 내 포함된다면 true를 반환한다.")
@Test
void isDateInRange() {
// given
LocalDate now = LocalDate.now();
LocalDate startDate = now.minusDays(1);
LocalDate endDate = now.plusDays(1);
// when
boolean isActive = TimeUtils.isDateInRange(now, startDate, endDate);
// then
Assertions.assertThat(isActive).isTrue();
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

테스트 케이스 보완 필요

현재 테스트는 기본적인 긍정 케이스만 검증하고 있습니다. 다음과 같은 추가 테스트 케이스를 고려해 주세요:

  • 시작일이 null인 경우
  • 종료일이 null인 경우
  • 현재 날짜가 시작일과 같은 경우
  • 현재 날짜가 종료일과 같은 경우
  • 현재 날짜가 범위를 벗어난 경우

예시 테스트 케이스:

@DisplayName("시작일이 null이면 false를 반환한다")
@Test
void isDateInRange_nullStartDate() {
    // given
    LocalDate now = LocalDate.now();
    LocalDate endDate = now.plusDays(1);
    // when
    boolean isActive = TimeUtils.isDateInRange(now, null, endDate);
    // then
    Assertions.assertThat(isActive).isFalse();
}

Long formId,
String title,
LocalDate startDate,
LocalDate endData,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

필드 이름 오타 수정 필요

'endData' 필드명에 오타가 있습니다. 'endDate'로 수정해 주세요.

-        LocalDate endData,
+        LocalDate endDate,
📝 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
LocalDate endData,
LocalDate endDate,

.formId(form.getId())
.title(form.getTitle())
.startDate(form.getStartDate())
.endData(form.getEndDate())
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

메소드 내 필드 참조 오타 수정 필요

from 메소드에서도 동일한 오타를 수정해 주세요.

-                .endData(form.getEndDate())
+                .endDate(form.getEndDate())
📝 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
.endData(form.getEndDate())
.endDate(form.getEndDate())

@Schema(description = "지원 폼지 시작일", example = "2001-01-01")
LocalDate startDate,
@Schema(description = "지원 폼지 종료일", example = "2001-01-02")
LocalDate endData,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

필드명 오타를 수정해 주세요.

endDataendDate의 오타로 보입니다. 날짜를 나타내는 필드이므로 endDate로 수정하는 것이 적절합니다.

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

-       LocalDate endData,
+       LocalDate endDate,

그리고 from 메소드에서도 동일하게 수정:

-               .endData(query.endData())
+               .endDate(query.endDate())

Also applies to: 27-27

Comment on lines +75 to +80
@Override
public FormQuery getForm(Long formId) {
Form form = formService.getById(formId);
List<FormField> formFields = formFieldService.findAllByForm(form);
return FormQuery.of(form, formFields);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

폼 상세 조회 로직에 권한 검증이 필요합니다.

현재 구현에서는 누구나 formId만 알면 폼을 조회할 수 있습니다. 클럽 소유자만 자신의 폼을 조회할 수 있도록 권한 검증이 필요합니다.

다음과 같이 수정을 제안합니다:

 @Override
 public FormQuery getForm(Long formId) {
     Form form = formService.getById(formId);
+    Club club = form.getClub();
+    validateEqualsClub(club, form);
     List<FormField> formFields = formFieldService.findAllByForm(form);
     return FormQuery.of(form, formFields);
 }
📝 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 FormQuery getForm(Long formId) {
Form form = formService.getById(formId);
List<FormField> formFields = formFieldService.findAllByForm(form);
return FormQuery.of(form, formFields);
}
@Override
public FormQuery getForm(Long formId) {
Form form = formService.getById(formId);
Club club = form.getClub();
validateEqualsClub(club, form);
List<FormField> formFields = formFieldService.findAllByForm(form);
return FormQuery.of(form, formFields);
}

Comment on lines +242 to +262
@DisplayName("동아리는 폼지를 상세조회 할 수 있다.")
@Test
void getForm() {
// given
Form form = fixtureMonkey.giveMeBuilder(Form.class)
.set("id", 1L)
.set("title", "제목1")
.set("club", null)
.sample();
Form form2 = fixtureMonkey.giveMeBuilder(Form.class)
.set("id", 2L)
.set("title", "제목2")
.set("club", null)
.sample();
formService.create(form);
formService.create(form2);
// when
FormQuery formQuery = facadeCentralFormService.getForm(1L);
// then
assertThat(formQuery.title()).isEqualTo("제목1");
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

getForm 테스트에 권한 검증 케이스가 누락되었습니다.

현재 테스트는 기본적인 조회 기능만 검증하고 있습니다. 다음 사항들을 추가로 검증해야 합니다:

  • 클럽 소유자가 자신의 폼을 조회하는 케이스
  • 다른 클럽의 폼을 조회할 때 예외가 발생하는 케이스

다음과 같이 테스트 케이스 추가를 제안합니다:

 @DisplayName("동아리는 폼지를 상세조회 할 수 있다.")
 @Test
 void getForm() {
   // given
+    User user = fixtureMonkey.giveMeBuilder(User.class)
+            .set("id", 1L)
+            .set("Role", Role.CLUB)
+            .set("deletedAt", null)
+            .sample();
+    User savedUser = userRepository.save(user);
+    Club club = fixtureMonkey.giveMeBuilder(Club.class)
+            .set("id", 1L)
+            .set("user", savedUser)
+            .set("score", null)
+            .set("clubMembers", null)
+            .set("deletedAt", null)
+            .sample();
+    clubRepository.save(club);
     Form form = fixtureMonkey.giveMeBuilder(Form.class)
             .set("id", 1L)
             .set("title", "제목1")
-            .set("club", null)
+            .set("club", club)
             .sample();
     Form form2 = fixtureMonkey.giveMeBuilder(Form.class)
             .set("id", 2L)
             .set("title", "제목2")
-            .set("club", null)
+            .set("club", club)
             .sample();
     formService.create(form);
     formService.create(form2);
   // when
     FormQuery formQuery = facadeCentralFormService.getForm(1L);
     // then
     assertThat(formQuery.title()).isEqualTo("제목1");
+    assertThat(formQuery.club().getId()).isEqualTo(club.getId());
 }

+@DisplayName("동아리는 다른 동아리의 폼지를 상세조회 할 수 없다.")
+@Test
+void getFormWithNonHaveAuthority() {
+    // given
+    User user1 = fixtureMonkey.giveMeBuilder(User.class)
+            .set("id", 1L)
+            .set("Role", Role.CLUB)
+            .set("deletedAt", null)
+            .sample();
+    User savedUser1 = userRepository.save(user1);
+    Club club1 = fixtureMonkey.giveMeBuilder(Club.class)
+            .set("id", 1L)
+            .set("user", savedUser1)
+            .set("score", null)
+            .set("clubMembers", null)
+            .set("deletedAt", null)
+            .sample();
+    clubRepository.save(club1);
+
+    User user2 = fixtureMonkey.giveMeBuilder(User.class)
+            .set("id", 2L)
+            .set("Role", Role.CLUB)
+            .set("deletedAt", null)
+            .sample();
+    User savedUser2 = userRepository.save(user2);
+    Club club2 = fixtureMonkey.giveMeBuilder(Club.class)
+            .set("id", 2L)
+            .set("user", savedUser2)
+            .set("score", null)
+            .set("clubMembers", null)
+            .set("deletedAt", null)
+            .sample();
+    clubRepository.save(club2);
+
+    Form form = fixtureMonkey.giveMeBuilder(Form.class)
+            .set("id", 1L)
+            .set("title", "제목1")
+            .set("club", club1)
+            .sample();
+    formService.create(form);
+
+    // when/then
+    assertThrows(NonHaveAuthority.class, () -> {
+        facadeCentralFormService.getForm(1L);
+    });
+}
📝 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
@DisplayName("동아리는 폼지를 상세조회 할 수 있다.")
@Test
void getForm() {
// given
Form form = fixtureMonkey.giveMeBuilder(Form.class)
.set("id", 1L)
.set("title", "제목1")
.set("club", null)
.sample();
Form form2 = fixtureMonkey.giveMeBuilder(Form.class)
.set("id", 2L)
.set("title", "제목2")
.set("club", null)
.sample();
formService.create(form);
formService.create(form2);
// when
FormQuery formQuery = facadeCentralFormService.getForm(1L);
// then
assertThat(formQuery.title()).isEqualTo("제목1");
}
@DisplayName("동아리는 폼지를 상세조회 할 수 있다.")
@Test
void getForm() {
// given
User user = fixtureMonkey.giveMeBuilder(User.class)
.set("id", 1L)
.set("Role", Role.CLUB)
.set("deletedAt", null)
.sample();
User savedUser = userRepository.save(user);
Club club = fixtureMonkey.giveMeBuilder(Club.class)
.set("id", 1L)
.set("user", savedUser)
.set("score", null)
.set("clubMembers", null)
.set("deletedAt", null)
.sample();
clubRepository.save(club);
Form form = fixtureMonkey.giveMeBuilder(Form.class)
.set("id", 1L)
.set("title", "제목1")
.set("club", club)
.sample();
Form form2 = fixtureMonkey.giveMeBuilder(Form.class)
.set("id", 2L)
.set("title", "제목2")
.set("club", club)
.sample();
formService.create(form);
formService.create(form2);
// when
FormQuery formQuery = facadeCentralFormService.getForm(1L);
// then
assertThat(formQuery.title()).isEqualTo("제목1");
assertThat(formQuery.club().getId()).isEqualTo(club.getId());
}
@DisplayName("동아리는 다른 동아리의 폼지를 상세조회 할 수 없다.")
@Test
void getFormWithNonHaveAuthority() {
// given
User user1 = fixtureMonkey.giveMeBuilder(User.class)
.set("id", 1L)
.set("Role", Role.CLUB)
.set("deletedAt", null)
.sample();
User savedUser1 = userRepository.save(user1);
Club club1 = fixtureMonkey.giveMeBuilder(Club.class)
.set("id", 1L)
.set("user", savedUser1)
.set("score", null)
.set("clubMembers", null)
.set("deletedAt", null)
.sample();
clubRepository.save(club1);
User user2 = fixtureMonkey.giveMeBuilder(User.class)
.set("id", 2L)
.set("Role", Role.CLUB)
.set("deletedAt", null)
.sample();
User savedUser2 = userRepository.save(user2);
Club club2 = fixtureMonkey.giveMeBuilder(Club.class)
.set("id", 2L)
.set("user", savedUser2)
.set("score", null)
.set("clubMembers", null)
.set("deletedAt", null)
.sample();
clubRepository.save(club2);
Form form = fixtureMonkey.giveMeBuilder(Form.class)
.set("id", 1L)
.set("title", "제목1")
.set("club", club1)
.sample();
formService.create(form);
// when/then
assertThrows(NonHaveAuthority.class, () -> {
facadeCentralFormService.getForm(1L);
});
}

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

고생 많으셨습니다!

@KoSeonJe KoSeonJe merged commit b64952b into develop Feb 4, 2025
1 check failed
@KoSeonJe KoSeonJe deleted the feature/DDING-89 branch February 4, 2025 14:46
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