From 115b32d174c48c5cada215e09e0bfd32eaee5272 Mon Sep 17 00:00:00 2001 From: hyeonji91 <112065014+hyeonji91@users.noreply.github.com> Date: Sat, 17 Feb 2024 07:03:01 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A1=B0=EC=96=B8=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beanstalk/result/controller/ResultController.java | 9 ++++++--- .../beanstalk/result/data/dto/ResponseResultDto.java | 7 +++++++ .../umc/beanstalk/result/service/ResultService.java | 10 ++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/umc/beanstalk/result/controller/ResultController.java b/src/main/java/umc/beanstalk/result/controller/ResultController.java index 4f246aa..73b6158 100644 --- a/src/main/java/umc/beanstalk/result/controller/ResultController.java +++ b/src/main/java/umc/beanstalk/result/controller/ResultController.java @@ -1,9 +1,11 @@ package umc.beanstalk.result.controller; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; import umc.beanstalk.common.apiPayload.ApiResult; +import umc.beanstalk.result.data.dto.ResponseResultDto; import umc.beanstalk.result.service.ResultService; import java.lang.management.LockInfo; @@ -15,11 +17,12 @@ public class ResultController { private final ResultService resultService; - //마지막 전체 결과를 종합해 조언 반환 - @GetMapping("/{userId}") + + @GetMapping("") + @Operation(summary = "마지막 전체 결과를 종합해 조언 반환") @Parameter(name="userId", description = "queryString로 userId") @Parameter(name="resultId", description = "queryString로 resultId") - private ApiResult> getTotalResult(@RequestParam Long userId, @RequestParam Long resultId){ + private ApiResult getTotalResult(@RequestParam Long userId, @RequestParam Long resultId){ return ApiResult.onSuccess(resultService.getTotalResult(userId, resultId)); } diff --git a/src/main/java/umc/beanstalk/result/data/dto/ResponseResultDto.java b/src/main/java/umc/beanstalk/result/data/dto/ResponseResultDto.java index 90d2c2e..d159ff9 100644 --- a/src/main/java/umc/beanstalk/result/data/dto/ResponseResultDto.java +++ b/src/main/java/umc/beanstalk/result/data/dto/ResponseResultDto.java @@ -18,6 +18,13 @@ public static class TotalInfo { private List answerList; } + @Getter + @Builder + public static class GetTotalResult{ + List advices; + String name; + } + } diff --git a/src/main/java/umc/beanstalk/result/service/ResultService.java b/src/main/java/umc/beanstalk/result/service/ResultService.java index f3717a6..718b9eb 100644 --- a/src/main/java/umc/beanstalk/result/service/ResultService.java +++ b/src/main/java/umc/beanstalk/result/service/ResultService.java @@ -21,16 +21,18 @@ @RequiredArgsConstructor public class ResultService { private final UserService userService; - private final UserChoiceService userChoiceService; private final ResultRepository resultRepository; private final ChoiceQueryService choiceQueryService; - public List getTotalResult(Long userId, Long resultId){ - + public ResponseResultDto.GetTotalResult getTotalResult(Long userId, Long resultId){ User user = userService.getUserById(userId); + Result result = resultRepository.findById(resultId).orElseThrow(()->new GeneralException(ErrorStatus._NOT_FOUND)); List choices = choiceQueryService.getChoicesByUserAndResultId(user, resultId); - return choices.stream().map(Choice::getAdvice).toList(); + return ResponseResultDto.GetTotalResult.builder() + .advices(choices.stream().map(Choice::getAdvice).toList()) + .name(result.getName()) + .build(); } }