Skip to content

[refactor] 설문조사 enum형식으로 변경 -> 우선 에너지 레벨만 추가#101

Merged
LEEDONGH00N merged 3 commits intowith-travel:developfrom
JonghyeokNam:develop
Aug 26, 2025
Merged

[refactor] 설문조사 enum형식으로 변경 -> 우선 에너지 레벨만 추가#101
LEEDONGH00N merged 3 commits intowith-travel:developfrom
JonghyeokNam:develop

Conversation

@JonghyeokNam
Copy link
Contributor

이슈

구현 기능

  • 설문조사 기능 enum 형식으로 변경 -> 우선 에너지 레벨만 추가

작업 시간

확인 필요

  • 반환 형식 확인(현재 -> enum의 Code, Label 중 Code만 반환 (프론트에서 라벨 매핑))
  • 에너지레벨 외 나머지 enum 추가 필요 (오늘까지 완료 예정)

@LEEDONGH00N LEEDONGH00N requested a review from Copilot August 18, 2025 18:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the survey functionality from a generic Q&A format to an enum-based approach, initially adding only the energy level survey option. The changes transform the survey system from storing arbitrary questions and answers to using predefined enum types with structured response options.

Key changes:

  • Replaced generic question/answer structure with enum-based survey fields
  • Changed relationship from one-to-many to one-to-one between Member and Survey
  • Added EnergyLevel enum with predefined options and validation

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main/java/com/arom/with_travel/domain/survey/enums/SurveyEnum.java Interface defining contract for survey enum types
src/main/java/com/arom/with_travel/domain/survey/enums/EnergyLevel.java Energy level enum with predefined options and JSON serialization
src/main/java/com/arom/with_travel/domain/survey/Survey.java Refactored entity to use enum fields instead of generic answers
src/main/java/com/arom/with_travel/domain/member/Member.java Changed relationship from OneToMany to OneToOne with Survey
src/main/java/com/arom/with_travel/domain/survey/dto/request/SurveyRequestDto.java Updated DTO to accept enum fields instead of answer list
src/main/java/com/arom/with_travel/domain/survey/dto/response/SurveyResponseDto.java Modified response to return enum values instead of generic data
src/main/java/com/arom/with_travel/domain/survey/service/SurveyService.java Updated service methods to handle enum-based surveys with upsert logic
src/main/java/com/arom/with_travel/domain/survey/repository/SurveyRepository.java Modified repository methods for one-to-one relationship
src/main/java/com/arom/with_travel/domain/survey/controller/SurveyController.java Updated controller endpoints to match new survey structure
src/main/java/com/arom/with_travel/global/exception/error/ErrorCode.java Added error code for energy level validation
Test files All test files commented out (temporary during refactoring)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@JoinColumn(name = "member_id")
@OneToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "member_id", nullable = false)
private Member member;
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

The @OnetoOne relationship with optional = false and nullable = false creates a constraint that every Survey must have a Member, but the Member entity shows optional = true for the reverse relationship. This asymmetry could cause issues during entity creation or when a member exists without a survey.

Copilot uses AI. Check for mistakes.
// dto.getCommStyle(),
// dto.getPersonality(),
// dto.getCompanionStyle(),
// dto.getSpendPattern()
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

The extensive commented-out code for additional survey fields makes the code difficult to read and maintain. Consider removing these comments and adding the fields when they are actually implemented.

Suggested change
// dto.getSpendPattern()
);
return existing;
})
.orElseGet(() -> Survey.create(
member,
dto.getEnergyLevel()

Copilot uses AI. Check for mistakes.
public interface SurveyRepository extends JpaRepository<Survey, Long> {

List<Survey> findByMember(Member member);
Optional<Survey> findByMember(Member member);
Copy link
Contributor

Choose a reason for hiding this comment

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

외부 조인이 발생할 수 있는 쿼리입니다. 조인이 발생한다면 JPQL을 사용해 조인을 없애주세요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

findByMemberIdAndIsDeletedFalse 메서드를 사용하여 해결하였습니다.
(select s.*
from survey s
where s.member_id = ?
and s.is_deleted = false)

@NotEmpty(message = "설문 답변은 최소 1개 이상이어야 합니다.")
private List<String> answers;
@NotNull(message = "energyLevel은 필수입니다.")
private EnergyLevel energyLevel;
Copy link
Contributor

Choose a reason for hiding this comment

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

한가지 질문에 대해 여러 답변을 받는 경우엔 어떻게 되나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

제가 착각을 했는데 현재 DTO는 단일 선택만 요구하고 있어서 프론트에서 배열로 요청을 보내면(여러 답변을 받으면) 400 에러(Bad Request)가 납니다.
피그마에 중복 선택 불가로 나와있어서 이런 로직으로 구현했는데 다중 선택 로직도 추가해야할까요?

Comment on lines +34 to +53
public static Survey create(
Member member,
EnergyLevel energyLevel
// TravelGoal travelGoal,
// TravelPace travelPace,
// CommStyle commStyle,
// Personality personality,
// CompanionStyle companionStyle,
// SpendPattern spendPattern
) {
Survey s = new Survey();
s.member = member;
s.energyLevel = energyLevel;
// s.travelGoal = travelGoal;
// s.travelPace = travelPace;
// s.commStyle = commStyle;
// s.personality = personality;
// s.companionStyle = companionStyle;
// s.spendPattern = spendPattern;
return s;
Copy link
Contributor

Choose a reason for hiding this comment

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

Survey의 생성자에서 필드 값을 채워주고, 연관관계에 있는 엔티티와의 단방향 연결을 양쪽방향에서 수행하도록 추가해주세요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

이 부분을 아래 커밋과 같이 수정했는데 제가 해당 리뷰 내용이 아직 헷갈리는 부분이 있어서 천천히 봐주시면 감사하겠습니다.

@LEEDONGH00N LEEDONGH00N merged commit 4b1c9e3 into with-travel:develop Aug 26, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants