공통코드 추가
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -14,11 +14,11 @@ import org.springframework.data.annotation.LastModifiedDate;
|
||||
public class CommonDateEntity {
|
||||
|
||||
@CreatedDate
|
||||
@Column(name = "created_date", updatable = false, nullable = false)
|
||||
@Column(name = "created_dttm", updatable = false, nullable = false)
|
||||
private ZonedDateTime createdDate;
|
||||
|
||||
@LastModifiedDate
|
||||
@Column(name = "modified_date", nullable = false)
|
||||
@Column(name = "updated_dttm", nullable = false)
|
||||
private ZonedDateTime modifiedDate;
|
||||
|
||||
@PrePersist
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto.Basic;
|
||||
import com.kamco.cd.kamcoback.common.service.BaseCoreService;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.AnimalEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.CommonCodeEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.ZooEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.CommonCodeRepository;
|
||||
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.SearchReq;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true)
|
||||
public class CommonCodeCoreService implements BaseCoreService<CommonCodeDto.Basic, Long, SearchReq> {
|
||||
|
||||
private final CommonCodeRepository commonCodeRepository;
|
||||
|
||||
public CommonCodeDto.Basic save(CommonCodeDto.AddReq req) {
|
||||
CommonCodeEntity code = null;
|
||||
// if (req.getZooUuid() != null) {
|
||||
// zoo =
|
||||
// zooRepository
|
||||
// .getZooByUuid(req.getZooUuid())
|
||||
// .orElseThrow(
|
||||
// () ->
|
||||
// new EntityNotFoundException("Zoo not found with uuid: " + req.getZooUuid()));
|
||||
// }
|
||||
CommonCodeEntity entity = new CommonCodeEntity(req.getCode(), req.getName(), req.getDescription(), req.getOrder(), req.isUsed());
|
||||
CommonCodeEntity saved = commonCodeRepository.save(entity);
|
||||
return saved.toDto();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Long aLong) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Basic getOneById(Long aLong) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Basic> search(SearchReq searchReq) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
|
||||
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
@Table(name = "tb_cm_cd")
|
||||
public class CommonCodeEntity extends CommonDateEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "code_id", nullable = false)
|
||||
private Long id;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "code_cd")
|
||||
private String codeCd;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "cd_ct")
|
||||
private String cdCt;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "cd_nm")
|
||||
private String cdNm;
|
||||
|
||||
@Column(name = "cd_odr")
|
||||
private Integer cdOdr;
|
||||
|
||||
@Column(name = "used")
|
||||
private Boolean used;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "deleted", nullable = false)
|
||||
private Boolean deleted = false;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "parent_id")
|
||||
private CommonCodeEntity parent;
|
||||
|
||||
@OneToMany(mappedBy = "parent")
|
||||
private Set<CommonCodeEntity> tbCmCds = new LinkedHashSet<>();
|
||||
|
||||
public CommonCodeEntity(String codeCd, String cdNm, String cdCt, Integer cdOdr, Boolean used) {
|
||||
this.codeCd = codeCd;
|
||||
this.cdNm = cdNm;
|
||||
this.cdCt = cdCt;
|
||||
this.cdOdr = cdOdr;
|
||||
this.used = used;
|
||||
}
|
||||
|
||||
public CommonCodeDto.Basic toDto() {
|
||||
return new CommonCodeDto.Basic(
|
||||
this.id,
|
||||
this.codeCd,
|
||||
this.cdCt,
|
||||
this.cdNm,
|
||||
this.cdOdr,
|
||||
this.used,
|
||||
this.deleted,
|
||||
this.parent,
|
||||
super.getCreatedDate(),
|
||||
super.getModifiedDate());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.entity.CommonCodeEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface CommonCodeRepository extends JpaRepository<CommonCodeEntity, Long>, CommonCodeRepositoryCustom {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository;
|
||||
|
||||
public interface CommonCodeRepositoryCustom {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository;
|
||||
|
||||
public class CommonCodeRepositoryImpl {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user