diff --git a/src/main/java/com/codingwasabi/trti/domain/member/MemberService.java b/src/main/java/com/codingwasabi/trti/domain/member/MemberService.java index c3ba8c3..aa2b4a4 100644 --- a/src/main/java/com/codingwasabi/trti/domain/member/MemberService.java +++ b/src/main/java/com/codingwasabi/trti/domain/member/MemberService.java @@ -5,6 +5,7 @@ import com.codingwasabi.trti.domain.member.model.response.ResponseExistMemberDto; import com.codingwasabi.trti.domain.member.model.response.ResponseMemberResultDto; import com.codingwasabi.trti.domain.member.model.response.ResponseMyInfoDto; +import com.codingwasabi.trti.util.survey.dto.RequestSurveyDto; public interface MemberService { ResponseMyInfoDto getMemberInfo(Member member); @@ -12,4 +13,6 @@ public interface MemberService { ResponseExistMemberDto existMember(RequestExistMemberDto requestDto); ResponseMemberResultDto getResult(Member member); + + void submitSurvey(Member member, RequestSurveyDto requestSurveyDto); } diff --git a/src/main/java/com/codingwasabi/trti/domain/member/impl/MemberController.java b/src/main/java/com/codingwasabi/trti/domain/member/impl/MemberController.java index 8785d3c..cf5c1fe 100644 --- a/src/main/java/com/codingwasabi/trti/domain/member/impl/MemberController.java +++ b/src/main/java/com/codingwasabi/trti/domain/member/impl/MemberController.java @@ -6,13 +6,11 @@ import com.codingwasabi.trti.domain.member.model.response.ResponseExistMemberDto; import com.codingwasabi.trti.domain.member.model.response.ResponseMemberResultDto; import com.codingwasabi.trti.domain.member.model.response.ResponseMyInfoDto; +import com.codingwasabi.trti.util.survey.dto.RequestSurveyDto; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @@ -35,4 +33,12 @@ public ResponseEntity existMember(@RequestBody RequestEx getMemberResult(@AuthenticationPrincipal MemberAdaptor memberAdaptor) { return ResponseEntity.ok(memberService.getResult(memberAdaptor.getMember())); } + + @PostMapping("/survey") + public ResponseEntity submitSurvey(@AuthenticationPrincipal MemberAdaptor memberAdaptor, + @RequestBody RequestSurveyDto requestSurveyDto) { + memberService.submitSurvey(memberAdaptor.getMember(), requestSurveyDto); + + return ResponseEntity.ok().build(); + } } diff --git a/src/main/java/com/codingwasabi/trti/domain/member/impl/MemberServiceImpl.java b/src/main/java/com/codingwasabi/trti/domain/member/impl/MemberServiceImpl.java index 49e0fd8..de6423b 100644 --- a/src/main/java/com/codingwasabi/trti/domain/member/impl/MemberServiceImpl.java +++ b/src/main/java/com/codingwasabi/trti/domain/member/impl/MemberServiceImpl.java @@ -7,6 +7,10 @@ import com.codingwasabi.trti.domain.member.model.response.ResponseMemberResultDto; import com.codingwasabi.trti.domain.member.model.response.ResponseMyInfoDto; import com.codingwasabi.trti.domain.member.repository.MemberRepository; +import com.codingwasabi.trti.domain.result.model.Result; +import com.codingwasabi.trti.domain.result.repository.ResultRepository; +import com.codingwasabi.trti.util.survey.SurveyHandler; +import com.codingwasabi.trti.util.survey.dto.RequestSurveyDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -15,6 +19,7 @@ @RequiredArgsConstructor public class MemberServiceImpl implements MemberService { private final MemberRepository memberRepository; + private final ResultRepository resultRepository; @Override @Transactional(readOnly = true) @@ -36,4 +41,12 @@ public ResponseExistMemberDto existMember(RequestExistMemberDto requestDto) { public ResponseMemberResultDto getResult(Member member) { return ResponseMemberResultDto.from(member); } + + @Override + public void submitSurvey(Member member, RequestSurveyDto requestSurveyDto) { + Result result = SurveyHandler.proceed(requestSurveyDto); + resultRepository.save(result); + + member.setResult(result); + } } diff --git a/src/main/java/com/codingwasabi/trti/domain/member/model/entity/Member.java b/src/main/java/com/codingwasabi/trti/domain/member/model/entity/Member.java index f71b3ad..e19d958 100644 --- a/src/main/java/com/codingwasabi/trti/domain/member/model/entity/Member.java +++ b/src/main/java/com/codingwasabi/trti/domain/member/model/entity/Member.java @@ -5,10 +5,7 @@ import com.codingwasabi.trti.domain.member.model.enumValue.Authority; import com.codingwasabi.trti.domain.member.model.enumValue.Gender; import com.codingwasabi.trti.domain.result.model.Result; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; @@ -53,4 +50,11 @@ public Authority getAuthority() { public Result getResult() { return result; } + + public void setResult(Result result) { + if (result == null) { + throw new IllegalArgumentException("[ERROR] 성향 검사 추출 중 에러가 발생했습니다. (internal error)"); + } + this.result = result; + } } diff --git a/src/main/java/com/codingwasabi/trti/util/survey/SurveyHandler.java b/src/main/java/com/codingwasabi/trti/util/survey/SurveyHandler.java index 9f90003..fc96b5d 100644 --- a/src/main/java/com/codingwasabi/trti/util/survey/SurveyHandler.java +++ b/src/main/java/com/codingwasabi/trti/util/survey/SurveyHandler.java @@ -4,5 +4,8 @@ import com.codingwasabi.trti.util.survey.dto.RequestSurveyDto; public interface SurveyHandler { - Result proceed(RequestSurveyDto requestDto); + + static Result proceed(RequestSurveyDto requestDto) { + return Result.from(requestDto.getAnswers()); + } } diff --git a/src/main/java/com/codingwasabi/trti/util/survey/dto/RequestAnswerDto.java b/src/main/java/com/codingwasabi/trti/util/survey/dto/RequestAnswerDto.java index ddeb4fb..d2f8a3c 100644 --- a/src/main/java/com/codingwasabi/trti/util/survey/dto/RequestAnswerDto.java +++ b/src/main/java/com/codingwasabi/trti/util/survey/dto/RequestAnswerDto.java @@ -1,8 +1,10 @@ package com.codingwasabi.trti.util.survey.dto; +import lombok.AllArgsConstructor; import lombok.Getter; @Getter +@AllArgsConstructor public class RequestAnswerDto { private Long id; private Integer answer; diff --git a/src/main/java/com/codingwasabi/trti/util/survey/dto/RequestSurveyDto.java b/src/main/java/com/codingwasabi/trti/util/survey/dto/RequestSurveyDto.java index 745da60..52a9cef 100644 --- a/src/main/java/com/codingwasabi/trti/util/survey/dto/RequestSurveyDto.java +++ b/src/main/java/com/codingwasabi/trti/util/survey/dto/RequestSurveyDto.java @@ -2,10 +2,12 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; import java.util.List; @Getter +@NoArgsConstructor @AllArgsConstructor public class RequestSurveyDto { private List answers; diff --git a/src/main/java/com/codingwasabi/trti/util/survey/tmptrti/TmpTRTISurveyHandler.java b/src/main/java/com/codingwasabi/trti/util/survey/tmptrti/TmpTRTISurveyHandler.java index bfd3b64..fd0d304 100644 --- a/src/main/java/com/codingwasabi/trti/util/survey/tmptrti/TmpTRTISurveyHandler.java +++ b/src/main/java/com/codingwasabi/trti/util/survey/tmptrti/TmpTRTISurveyHandler.java @@ -1,12 +1,6 @@ package com.codingwasabi.trti.util.survey.tmptrti; -import com.codingwasabi.trti.domain.result.model.Result; import com.codingwasabi.trti.util.survey.SurveyHandler; -import com.codingwasabi.trti.util.survey.dto.RequestSurveyDto; public class TmpTRTISurveyHandler implements SurveyHandler { - @Override - public Result proceed(RequestSurveyDto requestDto) { - return Result.from(requestDto.getAnswers()); - } }