Skip to content

Commit

Permalink
Merge pull request #36 from CodingWasabi/feature-35/survey
Browse files Browse the repository at this point in the history
🔥[FEAT]-#35- 비회원 성향 검사 구현
  • Loading branch information
daehwan2yo authored Dec 28, 2021
2 parents 43fb411 + 9fe60e8 commit fd26da1
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ public ResponseExistMemberDto existMember(RequestExistMemberDto requestDto) {
}

@Override
@Transactional(readOnly = true)
public ResponseMemberResultDto getResult(Member member) {
return ResponseMemberResultDto.from(member);
}

@Override
@Transactional
public void submitSurvey(Member member, RequestSurveyDto requestSurveyDto) {
Result result = SurveyHandler.proceed(requestSurveyDto);
resultRepository.save(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
@Getter
@AllArgsConstructor
public class ResponseMemberDetailResultDto {
private Long id;
private int id;
private Integer selected;

public static ResponseMemberDetailResultDto from(AnswerType answerType) {
return new ResponseMemberDetailResultDto(answerType.getId(), answerType.getSelected());
return new ResponseMemberDetailResultDto(answerType.getTypeId(), answerType.getSelected());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.codingwasabi.trti.domain.result.model.values;

import com.codingwasabi.trti.domain.common.Period;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand Down Expand Up @@ -48,4 +47,6 @@ public void minusCount0() {
public void minusCount1() {
this.count1--;
}

public abstract int getTypeId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ private ToActive(int answer) {
public static ToActive from(Integer answer) {
return new ToActive(answer);
}

@Override
public int getTypeId() {
return ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ private ToEat_1(int answer) {
public static ToEat_1 from(Integer answer) {
return new ToEat_1(answer);
}

@Override
public int getTypeId() {
return ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ private ToEat_2(int answer) {
public static ToEat_2 from(Integer answer) {
return new ToEat_2(answer);
}

@Override
public int getTypeId() {
return ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ private ToMove(int answer) {
public static ToMove from(int answer) {
return new ToMove(answer);
}

@Override
public int getTypeId() {
return ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ private ToStay_1(int answer) {
public static ToStay_1 from(Integer answer) {
return new ToStay_1(answer);
}

@Override
public int getTypeId() {
return ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ private ToStay_2(int answer) {
public static ToStay_2 from(Integer answer) {
return new ToStay_2(answer);
}

@Override
public int getTypeId() {
return ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ public class ToStay_3 extends AnswerType {
private ToStay_3(int answer) {
super(answer);
}

public static ToStay_3 from(Integer answer) {
return new ToStay_3(answer);
}


@Override
public int getTypeId() {
return ID;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.codingwasabi.trti.util.annonymous;

import com.codingwasabi.trti.util.annonymous.dto.ResponseAnonymousResultDto;
import com.codingwasabi.trti.util.survey.dto.RequestSurveyDto;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/anonymous")
public class AnonymousController {
private final AnonymousService anonymousService;

@PostMapping("/survey")
public ResponseEntity<ResponseAnonymousResultDto> submitSurvey(@RequestBody RequestSurveyDto requestSurveyDto) {
return ResponseEntity.ok(anonymousService.submitSurvey(requestSurveyDto));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.codingwasabi.trti.util.annonymous;

import com.codingwasabi.trti.domain.result.model.Result;
import com.codingwasabi.trti.util.annonymous.dto.ResponseAnonymousResultDto;
import com.codingwasabi.trti.util.survey.dto.RequestSurveyDto;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AnonymousService {

@Transactional
public ResponseAnonymousResultDto submitSurvey(RequestSurveyDto requestSurveyDto) {
return ResponseAnonymousResultDto.from(Result.from(requestSurveyDto.getAnswers()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.codingwasabi.trti.util.annonymous.dto;

import com.codingwasabi.trti.domain.member.model.response.ResponseMemberDetailResultDto;
import com.codingwasabi.trti.domain.result.model.Result;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

@Getter
@AllArgsConstructor
public class ResponseAnonymousResultDto {
private List<ResponseMemberDetailResultDto> answers;

public static ResponseAnonymousResultDto from(Result result) {
return new ResponseAnonymousResultDto(getDetailResult(result));
}

private static List<ResponseMemberDetailResultDto> getDetailResult(Result result) {
List<ResponseMemberDetailResultDto> resultList = new ArrayList<>();
resultList.add(ResponseMemberDetailResultDto.from(result.getToMove()));
resultList.add(ResponseMemberDetailResultDto.from(result.getToEat_1()));
resultList.add(ResponseMemberDetailResultDto.from(result.getToEat_2()));
resultList.add(ResponseMemberDetailResultDto.from(result.getToStay_1()));
resultList.add(ResponseMemberDetailResultDto.from(result.getToStay_2()));
resultList.add(ResponseMemberDetailResultDto.from(result.getToStay_3()));
resultList.add(ResponseMemberDetailResultDto.from(result.getToActive()));

return resultList;
}
}

0 comments on commit fd26da1

Please sign in to comment.