Skip to content
Merged
7 changes: 5 additions & 2 deletions src/main/java/com/arom/with_travel/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public Member(String memberName, String email, Role role) {
}

private Member(String name, String email, String oauthId){
this.name = name;
this.email = email;
this.oauthId = oauthId;
this.role = Role.GUEST;
}

Expand Down Expand Up @@ -163,8 +166,8 @@ public void updateExtraInfo(String nickname, LocalDate birth, Gender gender) {
this.gender = gender;
}

public boolean needExtraInfo() {
return nickname == null || birth == null || gender == null;
public void markAdditionalDataChecked() {
this.additionalDataChecked = true;
}

public void uploadImage(Image image){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.arom.with_travel.domain.member.controller;

import com.arom.with_travel.domain.member.dto.request.MemberSignupRequestDto;
import com.arom.with_travel.domain.member.dto.request.SignupWithSurveyRequestDto;
import com.arom.with_travel.domain.member.dto.request.SocialMemberVerificationRequest;
import com.arom.with_travel.domain.member.dto.response.MemberSignupResponseDto;
import com.arom.with_travel.domain.member.dto.response.MemberSignupTokenResponse;
import com.arom.with_travel.domain.member.dto.response.SocialMemberVerificationResponse;
import com.arom.with_travel.domain.member.service.MemberSignupService;
import com.arom.with_travel.domain.member.service.SignupFacadeService;
import com.arom.with_travel.global.jwt.dto.response.AuthTokenResponse;
import com.arom.with_travel.global.security.domain.AuthenticatedMember;
import com.arom.with_travel.global.security.domain.PrincipalDetails;
import com.arom.with_travel.global.security.token.service.TokenService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
Expand All @@ -21,18 +23,24 @@
@RequiredArgsConstructor
@RequestMapping("/api/v1/signup")
@Tag(name = "회원가입", description = "카카오 신규 회원 추가 정보 입력 API")
@Slf4j
public class MemberSignupController {

private final MemberSignupService memberSignupService;
private final TokenService tokenService;
private final SignupFacadeService signupFacadeService;

// 추가 정보 등록
// 추가 정보 및 설문 조사 등록
@PostMapping("/register")
public ResponseEntity<MemberSignupResponseDto> fillExtraInfo(@AuthenticationPrincipal PrincipalDetails principal,
@RequestBody @Valid MemberSignupRequestDto req) {
public ResponseEntity<MemberSignupResponseDto> fillExtraInfo(
@AuthenticationPrincipal PrincipalDetails principal,
@RequestBody @Valid SignupWithSurveyRequestDto req) {

AuthenticatedMember member = principal.getAuthenticatedMember();
MemberSignupResponseDto dto = memberSignupService
.fillExtraInfo(member.getEmail(), req);

MemberSignupResponseDto dto =
signupFacadeService.fillExtraInfo(member.getEmail(), req);

return ResponseEntity.ok(dto);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.arom.with_travel.domain.member.dto.request;


import com.arom.with_travel.domain.survey.dto.request.SurveyRequestDto;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
Copy link
Contributor

Choose a reason for hiding this comment

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

Setter는 제거해주세요

public class SignupWithSurveyRequestDto {

@Valid @NotNull
Copy link
Contributor

Choose a reason for hiding this comment

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

@Valid는 컨트롤러에서 메서드 파라미터 검증할 때 사용하는 어노테이션이라서 여기서는 사용하지 않아도 됩니다.

private MemberSignupRequestDto extraInfo; // 닉네임·성별·생년월일

@Valid @NotEmpty
private List<SurveyRequestDto> surveys;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.arom.with_travel.domain.member.dto.request;

import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SocialMemberVerificationRequest {
@NotBlank private String oauthId;
@NotBlank private String email;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.arom.with_travel.domain.member.service;

import com.arom.with_travel.domain.member.Member;
import com.arom.with_travel.domain.member.dto.request.SignupWithSurveyRequestDto;
import com.arom.with_travel.domain.member.dto.response.MemberSignupResponseDto;
import com.arom.with_travel.domain.member.repository.MemberRepository;
import com.arom.with_travel.domain.survey.service.SurveyService;
import com.arom.with_travel.global.security.token.service.TokenService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class SignupFacadeService {

private final MemberSignupService memberSignupService;
private final SurveyService surveyService;
private final MemberRepository memberRepository;

Copy link
Contributor

Choose a reason for hiding this comment

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

현재 파사드 패턴을 적용하신걸로 보이는데, 이보단 MemberSignUpService에서 MemberRepository와 SurveyRepository를 사용해 정보를 저장하는걸 추천드립니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

좋은 방법이네요

@Transactional
public MemberSignupResponseDto fillExtraInfo(String email,
SignupWithSurveyRequestDto req) {
MemberSignupResponseDto memberDto =
memberSignupService.fillExtraInfo(email, req.getExtraInfo());

req.getSurveys().forEach(dto -> surveyService.createSurvey(email, dto));

Member member = memberRepository.findByEmail(email)
.orElseThrow(() -> new IllegalStateException("Member not found"));
member.markAdditionalDataChecked();
Copy link
Contributor

Choose a reason for hiding this comment

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

다른 Service에서 memberRepository.findByEmail(email) 또는 loadMemberOrThrow 메서드를 참고해서 수정해주세요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

적용했습니다


return memberDto;
}
}
13 changes: 1 addition & 12 deletions src/main/java/com/arom/with_travel/domain/survey/Survey.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public class Survey extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull @Lob
private String question;

// Survey 엔티티가 answers 문자열 리스트를 갖고 있고, 이 값들을 별도의 테이블에 저장하도록 리팩토링
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "survey_answers",
Expand All @@ -40,23 +37,15 @@ public class Survey extends BaseEntity {
@JoinColumn(name = "member_id")
private Member member;

public static Survey create(Member member, String question, List<String> answers) {
validateQuestion(question);
public static Survey create(Member member,List<String> answers) {
validateAnswers(answers);

Survey survey = new Survey();
survey.member = member;
survey.question = question;
survey.answers = answers;
return survey;
}

private static void validateQuestion(String question) {
if (question == null || question.isBlank()) {
throw BaseException.from(ErrorCode.INVALID_SURVEY_QUESTION);
}
}

private static void validateAnswers(List<String> answers){
if(answers == null || answers.isEmpty())
throw BaseException.from(ErrorCode.INVALID_SURVEY_ANSWER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
@Builder
public class SurveyRequestDto {

@NotBlank(message = "질문은 비어 있을 수 없습니다.")
private String question;

@NotEmpty(message = "설문 답변은 최소 1개 이상이어야 합니다.")
private List<String> answers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class SurveyResponseDto {
public static SurveyResponseDto from(Survey survey) {
return SurveyResponseDto.builder()
.surveyId(survey.getId())
.question(survey.getQuestion())
.answers(survey.getAnswers())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void createSurvey(String email, SurveyRequestDto dto) {
Member member = memberRepository.findByEmail(email)
.orElseThrow(() -> BaseException.from(ErrorCode.MEMBER_NOT_FOUND));

Survey survey = Survey.create(member, dto.getQuestion(), dto.getAnswers());
Survey survey = Survey.create(member, dto.getAnswers());
surveyRepository.save(survey);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ void setUp() {
// 테스트용 더미 데이터
member = Member.create("user1", "user1@email.com", Member.Role.USER);
dto = SurveyRequestDto.builder()
.question("Q?")
.answers(List.of("A1","A2"))
.build();
}
Expand Down