공통코드 추가

This commit is contained in:
2025-11-18 11:35:28 +09:00
parent 1657045f6d
commit 725cad510e
9 changed files with 319 additions and 2 deletions

View File

@@ -0,0 +1,52 @@
package com.kamco.cd.kamcoback.code;
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
import com.kamco.cd.kamcoback.code.service.CommonCodeService;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto;
import com.kamco.cd.kamcoback.zoo.dto.ZooDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "공통코드 관리", description = "공통코드 관리 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/code")
public class CommonCodeApiController {
private final CommonCodeService commonCodeService;
@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)
})
@PostMapping
public ApiResponseDto<Long> save(
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "공통코드 생성 요청 정보",
required = true,
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = CommonCodeDto.AddReq.class)))
@RequestBody
CommonCodeDto.AddReq req) {
Long id = commonCodeService.save(req);
return ApiResponseDto.createOK(id);
}
}

View File

@@ -0,0 +1,83 @@
package com.kamco.cd.kamcoback.code.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
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 java.time.Instant;
import java.time.ZonedDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
public class CommonCodeDto {
@Schema(name = "CodeAddReq", description = "코드저장 요청")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class AddReq {
private String code;
private String name;
private String description;
private int order;
private boolean used;
private Long parentId;
}
@Schema(name = "AnimalBasic", description = "동물 기본 정보")
@Getter
public static class Basic {
@JsonIgnore
private Long id;
private String codeCd;
private String cdCt;
private String cdNm;
private Integer cdOdr;
private Boolean used;
private Boolean deleted;
CommonCodeEntity parent;
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
timezone = "Asia/Seoul")
private ZonedDateTime createdAt;
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
timezone = "Asia/Seoul")
private ZonedDateTime updatedAt;
public Basic(
Long id,
String codeCd,
String cdCt,
String cdNm,
Integer cdOdr,
Boolean used,
Boolean deleted,
CommonCodeEntity parent,
ZonedDateTime createdAt,
ZonedDateTime updatedAt) {
this.id = id;
this.codeCd = codeCd;
this.cdCt = cdCt;
this.cdNm = cdNm;
this.cdOdr = cdOdr;
this.used = used;
this.deleted = deleted;
this.parent = parent;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}
}
}

View File

@@ -0,0 +1,26 @@
package com.kamco.cd.kamcoback.code.service;
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
import com.kamco.cd.kamcoback.postgres.core.CommonCodeCoreService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class CommonCodeService {
private final CommonCodeCoreService commonCodeCoreService;
/**
* 공통코드 생성 요청
* @param req 생성요청 정보
* @return 생성된 코드 id
*/
@Transactional
public Long save(CommonCodeDto.AddReq req) {
Long id = commonCodeCoreService.save(req).getId();
return id;
}
}