diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/controller/SurveyController.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/controller/SurveyController.java index 5644c7d..33f946b 100644 --- a/src/main/java/com/kusithm/hdmedi_server/domain/survey/controller/SurveyController.java +++ b/src/main/java/com/kusithm/hdmedi_server/domain/survey/controller/SurveyController.java @@ -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; @@ -24,16 +25,9 @@ public class SurveyController { @PostMapping public ResponseEntity> 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> getSurveyResult() { - - return ResponseEntity.status(HttpStatus.OK) - .body(BaseResponse.of(SuccessCode.OK, null)); + .body(BaseResponse.of(SuccessCode.CREATED, responseDto)); } @GetMapping("/all") diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/response/SurveyResultResponseDto.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/response/SurveyResultResponseDto.java new file mode 100644 index 0000000..9e71f22 --- /dev/null +++ b/src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/response/SurveyResultResponseDto.java @@ -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(); + } +} diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/service/SurveyService.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/service/SurveyService.java index 4b9a884..a45354a 100644 --- a/src/main/java/com/kusithm/hdmedi_server/domain/survey/service/SurveyService.java +++ b/src/main/java/com/kusithm/hdmedi_server/domain/survey/service/SurveyService.java @@ -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; @@ -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 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());