Skip to content

Commit

Permalink
Merge pull request #15 from wagle-wagle-hackathon/hyeonji
Browse files Browse the repository at this point in the history
조언 api 수정
  • Loading branch information
hyeonji91 authored Feb 16, 2024
2 parents 3d51dd4 + 115b32d commit fad97f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<List<String>> getTotalResult(@RequestParam Long userId, @RequestParam Long resultId){
private ApiResult<ResponseResultDto.GetTotalResult> getTotalResult(@RequestParam Long userId, @RequestParam Long resultId){
return ApiResult.onSuccess(resultService.getTotalResult(userId, resultId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public static class TotalInfo {
private List<String> answerList;
}

@Getter
@Builder
public static class GetTotalResult{
List<String> advices;
String name;
}

}


Expand Down
10 changes: 6 additions & 4 deletions src/main/java/umc/beanstalk/result/service/ResultService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<Choice> 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();
}

}

0 comments on commit fad97f6

Please sign in to comment.