diff --git a/src/main/java/com/endlesshorses/oot/custom/result/controller/ResultController.java b/src/main/java/com/endlesshorses/oot/custom/result/controller/ResultController.java index 53c1d26..716d3a9 100644 --- a/src/main/java/com/endlesshorses/oot/custom/result/controller/ResultController.java +++ b/src/main/java/com/endlesshorses/oot/custom/result/controller/ResultController.java @@ -1,10 +1,19 @@ package com.endlesshorses.oot.custom.result.controller; +import com.endlesshorses.oot.custom.pattern.dto.PatternListResponseDto; +import com.endlesshorses.oot.custom.result.dto.ResultResponseDTO; +import com.endlesshorses.oot.custom.result.entity.Result; import com.endlesshorses.oot.custom.result.service.ResultService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.UUID; @RestController @RequiredArgsConstructor @@ -12,4 +21,26 @@ @RequestMapping("/api/results") public class ResultController { private final ResultService resultService; + + @Operation(summary = "타이어 커스텀 결과물 조회 메서드", description = "클라이언트가 요청한 타이어 결과물 정보를 조회하기 위한 메서드") + @GetMapping("/{id}") + @ResponseBody + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "결과물 조회 성공"), + @ApiResponse(responseCode = "400", description = "잘못된 요청, UUID 형식이 아닌 id가 입력된 경우"), + @ApiResponse(responseCode = "404", description = "결과물을 찾을 수 없음, 주어진 id에 해당하는 결과물이 없는 경우"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류"), + }) + + public ResponseEntity findResult(@PathVariable String id) { + return ResponseEntity.ok(resultService.findById(id)); + } + + @GetMapping + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "결과물 목록 조회 성공"), + }) + public List findAll() { + return resultService.list(); + } } diff --git a/src/main/java/com/endlesshorses/oot/custom/result/service/ResultService.java b/src/main/java/com/endlesshorses/oot/custom/result/service/ResultService.java index 84607bc..fabeb0f 100644 --- a/src/main/java/com/endlesshorses/oot/custom/result/service/ResultService.java +++ b/src/main/java/com/endlesshorses/oot/custom/result/service/ResultService.java @@ -1,11 +1,30 @@ package com.endlesshorses.oot.custom.result.service; +import com.endlesshorses.oot.custom.pattern.dto.PatternListResponseDto; +import com.endlesshorses.oot.custom.result.dto.ResultResponseDTO; +import com.endlesshorses.oot.custom.result.entity.Result; import com.endlesshorses.oot.custom.result.repository.ResultRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + @Service @RequiredArgsConstructor public class ResultService { private final ResultRepository resultRepository; + + public ResultResponseDTO findById(String id) { + return resultRepository.findById(id) + .map(ResultResponseDTO::new) + .orElseThrow(() -> new IllegalArgumentException("해당 id의 결과가 없습니다. id: " + id)); + } + + public List list() { + return resultRepository.findAll().stream() + .map(ResultResponseDTO::new) + .collect(Collectors.toList()); + } }