feat: api wrapping
This commit is contained in:
@@ -51,7 +51,7 @@ dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||
|
||||
// SpringDoc OpenAPI (Swagger)
|
||||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
|
||||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.kamco.cd.kamcoback.config;
|
||||
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@Slf4j
|
||||
@Order(value = 1)
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
// 로그인 정보가 잘못됐습니다 권한 없음
|
||||
@org.springframework.web.bind.annotation.ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
@ExceptionHandler(EntityNotFoundException.class)
|
||||
public ApiResponseDto<String> handlerEntityNotFoundException(EntityNotFoundException e) {
|
||||
log.warn("[EntityNotFoundException] resource :{} ", e.getMessage());
|
||||
String message = String.format("%s [%s]", e.getMessage(), e.getCause());
|
||||
return ApiResponseDto.createException(ApiResponseDto.ApiResponseCode.NOT_FOUND, message);
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,13 @@ public class AnimalCoreService
|
||||
@Transactional
|
||||
public AnimalDto.Basic create(AnimalDto.AddReq req) {
|
||||
ZooEntity zoo = null;
|
||||
if (req.getZooId() != null) {
|
||||
if (req.getZooUuid() != null) {
|
||||
zoo =
|
||||
zooRepository
|
||||
.getZooByUid(req.getZooId())
|
||||
.getZooByUuid(req.getZooUuid())
|
||||
.orElseThrow(
|
||||
() -> new EntityNotFoundException(" not found with id: " + req.getZooId()));
|
||||
() ->
|
||||
new EntityNotFoundException("Zoo not found with uuid: " + req.getZooUuid()));
|
||||
}
|
||||
AnimalEntity entity = new AnimalEntity(req.getCategory(), req.getSpecies(), req.getName(), zoo);
|
||||
AnimalEntity saved = animalRepository.save(entity);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class ZooApiController {
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ZooDto.AddReq.class))),
|
||||
schema = @Schema(implementation = ZooDto.Detail.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.kamco.cd.kamcoback.zoo.dto;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.kamco.cd.kamcoback.config.enums.EnumType;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.time.ZonedDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -14,6 +15,7 @@ import org.springframework.data.domain.Sort;
|
||||
|
||||
public class AnimalDto {
|
||||
|
||||
@Schema(name = "AnimalAddReq", description = "동물 생성 요청")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@@ -23,9 +25,10 @@ public class AnimalDto {
|
||||
private Category category;
|
||||
private Species species;
|
||||
private String name;
|
||||
private Long zooId; // 동물원 ID (선택)
|
||||
private String zooUuid; // 동물원 UUID (선택)
|
||||
}
|
||||
|
||||
@Schema(name = "AnimalBasic", description = "동물 기본 정보")
|
||||
@Getter
|
||||
public static class Basic {
|
||||
|
||||
@@ -98,6 +101,7 @@ public class AnimalDto {
|
||||
private final String text;
|
||||
}
|
||||
|
||||
@Schema(name = "AnimalSearchReq", description = "동물 검색 요청")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.kamco.cd.kamcoback.zoo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.time.ZonedDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -13,6 +14,7 @@ import org.springframework.data.domain.Sort;
|
||||
|
||||
public class ZooDto {
|
||||
|
||||
@Schema(name = "ZooAddReq", description = "동물원 생성 요청")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@@ -24,6 +26,7 @@ public class ZooDto {
|
||||
private String description;
|
||||
}
|
||||
|
||||
@Schema(name = "ZooBasic", description = "동물원 기본 정보")
|
||||
@Getter
|
||||
public static class Basic {
|
||||
|
||||
@@ -63,6 +66,7 @@ public class ZooDto {
|
||||
}
|
||||
}
|
||||
|
||||
@Schema(name = "ZooDetail", description = "동물원 상세 정보 (동물 개수 포함)")
|
||||
@Getter
|
||||
public static class Detail extends Basic {
|
||||
|
||||
@@ -82,6 +86,7 @@ public class ZooDto {
|
||||
}
|
||||
}
|
||||
|
||||
@Schema(name = "ZooSearchReq", description = "동물원 검색 요청")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
|
||||
Reference in New Issue
Block a user