Skip to content

Commit

Permalink
[feat] 설문조사 결과 반환 api
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbbin committed Sep 16, 2023
1 parent 54c7435 commit 358cb28
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.kusithm.hdmedi_server.domain.survey.dto.request.CreateSurveyDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.SurveyDetailResultDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.SurveyResultResponseDto;
import com.kusithm.hdmedi_server.domain.survey.service.SurveyService;
import com.kusithm.hdmedi_server.global.common.BaseResponse;
import com.kusithm.hdmedi_server.global.common.HDmediUser;
Expand All @@ -24,16 +25,9 @@ public class SurveyController {
@PostMapping
public ResponseEntity<BaseResponse<?>> submitSurvey(@AuthenticatedUserId final HDmediUser hDmediUser,
@RequestBody final CreateSurveyDto requestDto) {
surveyService.processSurvey(hDmediUser, requestDto);
final SurveyResultResponseDto responseDto = surveyService.processSurvey(hDmediUser, requestDto);
return ResponseEntity.status(HttpStatus.CREATED)
.body(BaseResponse.of(SuccessCode.CREATED, null));
}

@GetMapping
public ResponseEntity<BaseResponse<?>> getSurveyResult() {

return ResponseEntity.status(HttpStatus.OK)
.body(BaseResponse.of(SuccessCode.OK, null));
.body(BaseResponse.of(SuccessCode.CREATED, responseDto));
}

@GetMapping("/all")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.kusithm.hdmedi_server.domain.survey.dto.response;

import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public class SurveyResultResponseDto {
private int totalScore;

public static SurveyResultResponseDto of(int totalScore){
return SurveyResultResponseDto.builder()
.totalScore(totalScore)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.kusithm.hdmedi_server.domain.survey.dto.request.BaseSurveyDto;
import com.kusithm.hdmedi_server.domain.survey.dto.request.CreateSurveyDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.SurveyDetailResultDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.SurveyResultResponseDto;
import com.kusithm.hdmedi_server.domain.survey.repository.SurveyRepository;
import com.kusithm.hdmedi_server.global.common.HDmediUser;
import com.kusithm.hdmedi_server.global.common.MessageSourceProvider;
Expand All @@ -27,14 +28,16 @@ public class SurveyService {
private final SurveyRepository surveyRepository;
private final MessageSourceProvider messageSourceProvider;

public void processSurvey(HDmediUser hDmediUser, CreateSurveyDto createSurveyDto) {
public SurveyResultResponseDto processSurvey(HDmediUser hDmediUser, CreateSurveyDto createSurveyDto) {
List<BaseSurvey> baseSurveyList = createBaseSurvey(createSurveyDto.getQuestionList());
Respondent respondent = Respondent.createRespondent(baseSurveyList, createSurveyDto.getTotalScore());
Survey currentSurvey = findSurvey(hDmediUser.getId());
addRespondentSurvey(hDmediUser.getIsGuest(), currentSurvey, respondent);
saveSurvey(currentSurvey);
return SurveyResultResponseDto.of(respondent.getTotalScore());
}


public SurveyDetailResultDto getDetailResult(HDmediUser hDmediUser, Long surveyId){
Survey currentSurvey = findSurvey(hDmediUser.getId());
Respondent parentsRespondent = getParentsRespondent(currentSurvey, surveyId.intValue());
Expand Down

0 comments on commit 358cb28

Please sign in to comment.