Skip to content

Commit

Permalink
Merge pull request #34 from CodingWasabi/feature-4/memberSurvey
Browse files Browse the repository at this point in the history
🔥[FEAT]-#4-Member Survey 구현
  • Loading branch information
daehwan2yo authored Dec 28, 2021
2 parents 22edce4 + 7c6f5bb commit 7c3fcfa
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
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);

ResponseExistMemberDto existMember(RequestExistMemberDto requestDto);

ResponseMemberResultDto getResult(Member member);

void submitSurvey(Member member, RequestSurveyDto requestSurveyDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,4 +33,12 @@ public ResponseEntity<ResponseExistMemberDto> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +19,7 @@
@RequiredArgsConstructor
public class MemberServiceImpl implements MemberService {
private final MemberRepository memberRepository;
private final ResultRepository resultRepository;

@Override
@Transactional(readOnly = true)
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RequestAnswerDto> answers;
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 7c3fcfa

Please sign in to comment.