Skip to content

Commit

Permalink
feat: 결과물 조회 Controller, Service 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
byeon22 committed Feb 23, 2024
1 parent 62e7ecd commit 19c6f50
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
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();
}
}
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());
}
}

0 comments on commit 19c6f50

Please sign in to comment.