-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 결과물 조회 Controller, Service 코드 작성
- Loading branch information
Showing
2 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
35 changes: 33 additions & 2 deletions
35
src/main/java/com/endlesshorses/oot/custom/result/controller/ResultController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,46 @@ | ||
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 | ||
@Tag(name = "Result", description = "타이어 커스텀 결과물 관련 API") | ||
@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<ResultResponseDTO> findResult(@PathVariable String id) { | ||
return ResponseEntity.ok(resultService.findById(id)); | ||
} | ||
|
||
@GetMapping | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", description = "결과물 목록 조회 성공"), | ||
}) | ||
public List<ResultResponseDTO> findAll() { | ||
return resultService.list(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/endlesshorses/oot/custom/result/service/ResultService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ResultResponseDTO> list() { | ||
return resultRepository.findAll().stream() | ||
.map(ResultResponseDTO::new) | ||
.collect(Collectors.toList()); | ||
} | ||
} |