공통코드 기능 수정
This commit is contained in:
@@ -10,8 +10,13 @@ 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 jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -24,13 +29,53 @@ public class CommonCodeApiController {
|
||||
|
||||
private final CommonCodeService commonCodeService;
|
||||
|
||||
@Operation(summary = "목록 조회", description = "모든 공통코드 조회")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "조회 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = CommonCodeDto.Basic.class))),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@GetMapping
|
||||
public ApiResponseDto<List<CommonCodeDto.Basic>> getFindAll() {
|
||||
return ApiResponseDto.createOK(commonCodeService.getFindAll());
|
||||
}
|
||||
|
||||
@Operation(summary = "단건 조회", description = "단건 조회")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "조회 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = CommonCodeDto.Basic.class))),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@GetMapping("/{id}")
|
||||
public ApiResponseDto<CommonCodeDto.Basic> getOneById(
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "단건 조회",
|
||||
required = true)
|
||||
@PathVariable Long id) {
|
||||
return ApiResponseDto.ok(commonCodeService.getOneById(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "저장", description = "공통코드를 저장 합니다.")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(responseCode = "201", description = "공통코드 저장 성공", content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = Long.class))),
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = Long.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@@ -45,7 +90,49 @@ public class CommonCodeApiController {
|
||||
schema = @Schema(implementation = CommonCodeDto.AddReq.class)))
|
||||
@RequestBody
|
||||
@Valid CommonCodeDto.AddReq req) {
|
||||
Long id = commonCodeService.save(req);
|
||||
return ApiResponseDto.createOK(id);
|
||||
return ApiResponseDto.createOK(commonCodeService.save(req));
|
||||
}
|
||||
|
||||
@Operation(summary = "수정", description = "공통코드를 수정 합니다.")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(responseCode = "201", description = "공통코드 수정 성공", content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = Long.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public ApiResponseDto<Long> update(
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "공통코드 수정 요청 정보",
|
||||
required = true,
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = CommonCodeDto.ModifyReq.class)))
|
||||
@PathVariable Long id, @RequestBody @Valid CommonCodeDto.ModifyReq req) {
|
||||
return ApiResponseDto.createOK(commonCodeService.update(id, req));
|
||||
}
|
||||
|
||||
@Operation(summary = "삭제", description = "공통코드를 삭제 합니다.")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(responseCode = "201", description = "공통코드 삭제 성공", content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = Long.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResponseDto<Long> remove(
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "공통코드 삭제 요청 정보",
|
||||
required = true)
|
||||
@PathVariable Long id) {
|
||||
commonCodeService.remove(id);
|
||||
return ApiResponseDto.deleteOk(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package com.kamco.cd.kamcoback.code.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.CommonCodeEntity;
|
||||
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.Category;
|
||||
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.Species;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -18,7 +15,7 @@ import lombok.Setter;
|
||||
|
||||
public class CommonCodeDto {
|
||||
|
||||
@Schema(name = "CodeAddReq", description = "코드저장 요청")
|
||||
@Schema(name = "CodeAddReq", description = "공통코드 저장 정보")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@@ -35,19 +32,31 @@ public class CommonCodeDto {
|
||||
private Long parentId;
|
||||
}
|
||||
|
||||
@Schema(name = "AnimalBasic", description = "동물 기본 정보")
|
||||
@Schema(name = "CodeModifyReq", description = "공통코드 수정 정보")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class ModifyReq {
|
||||
@NotEmpty
|
||||
private String name;
|
||||
private String description;
|
||||
private int order;
|
||||
private boolean used;
|
||||
}
|
||||
|
||||
@Schema(name = "CommonCode Basic", description = "공통코드 기본 정보")
|
||||
@Getter
|
||||
public static class Basic {
|
||||
|
||||
@JsonIgnore
|
||||
private Long id;
|
||||
private String codeCd;
|
||||
private String cdCt;
|
||||
private String cdNm;
|
||||
private Integer cdOdr;
|
||||
private String code;
|
||||
private String description;
|
||||
private String name;
|
||||
private Integer order;
|
||||
private Boolean used;
|
||||
private Boolean deleted;
|
||||
CommonCodeEntity parent;
|
||||
private List<CommonCodeDto.Basic> children;
|
||||
|
||||
@JsonFormatDttm
|
||||
private ZonedDateTime createdDttm;
|
||||
@@ -57,23 +66,23 @@ public class CommonCodeDto {
|
||||
|
||||
public Basic(
|
||||
Long id,
|
||||
String codeCd,
|
||||
String cdCt,
|
||||
String cdNm,
|
||||
Integer cdOdr,
|
||||
String code,
|
||||
String description,
|
||||
String name,
|
||||
Integer order,
|
||||
Boolean used,
|
||||
Boolean deleted,
|
||||
CommonCodeEntity parent,
|
||||
List<CommonCodeDto.Basic> children,
|
||||
ZonedDateTime createdDttm,
|
||||
ZonedDateTime updatedDttm) {
|
||||
this.id = id;
|
||||
this.codeCd = codeCd;
|
||||
this.cdCt = cdCt;
|
||||
this.cdNm = cdNm;
|
||||
this.cdOdr = cdOdr;
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
this.name = name;
|
||||
this.order = order;
|
||||
this.used = used;
|
||||
this.deleted = deleted;
|
||||
this.parent = parent;
|
||||
this.children = children;
|
||||
this.createdDttm = createdDttm;
|
||||
this.updatedDttm = updatedDttm;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.kamco.cd.kamcoback.code.service;
|
||||
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
|
||||
import com.kamco.cd.kamcoback.postgres.core.CommonCodeCoreService;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -13,6 +14,24 @@ public class CommonCodeService {
|
||||
|
||||
private final CommonCodeCoreService commonCodeCoreService;
|
||||
|
||||
|
||||
/**
|
||||
* 공통코드 목록 조회
|
||||
* @return
|
||||
*/
|
||||
public List<CommonCodeDto.Basic> getFindAll() {
|
||||
return commonCodeCoreService.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 공통코드 단건 조회
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public CommonCodeDto.Basic getOneById(Long id) {
|
||||
return commonCodeCoreService.getOneById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 공통코드 생성 요청
|
||||
* @param req 생성요청 정보
|
||||
@@ -20,7 +39,23 @@ public class CommonCodeService {
|
||||
*/
|
||||
@Transactional
|
||||
public Long save(CommonCodeDto.AddReq req) {
|
||||
Long id = commonCodeCoreService.save(req).getId();
|
||||
return id;
|
||||
return commonCodeCoreService.save(req).getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 공통코드 수정 요청
|
||||
* @param id 코드 아이디
|
||||
* @param req 수정요청 정보
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
public Long update(Long id, CommonCodeDto.ModifyReq req) {
|
||||
return commonCodeCoreService.update(id, req).getId();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void remove(Long id) {
|
||||
commonCodeCoreService.remove(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user