From 358cb28843d547eb24f416668fea2ba3c26a270e Mon Sep 17 00:00:00 2001 From: sebbbin Date: Sat, 16 Sep 2023 23:35:03 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EC=84=A4=EB=AC=B8=EC=A1=B0=EC=82=AC?= =?UTF-8?q?=20=EA=B2=B0=EA=B3=BC=20=EB=B0=98=ED=99=98=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../survey/controller/SurveyController.java | 12 +++--------- .../dto/response/SurveyResultResponseDto.java | 16 ++++++++++++++++ .../domain/survey/service/SurveyService.java | 5 ++++- 3 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/response/SurveyResultResponseDto.java 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());