JsonFormat
This commit is contained in:
@@ -3,14 +3,13 @@ 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 jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -45,7 +44,7 @@ public class CommonCodeApiController {
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = CommonCodeDto.AddReq.class)))
|
||||
@RequestBody
|
||||
CommonCodeDto.AddReq req) {
|
||||
@Valid CommonCodeDto.AddReq req) {
|
||||
Long id = commonCodeService.save(req);
|
||||
return ApiResponseDto.createOK(id);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,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 lombok.AllArgsConstructor;
|
||||
@@ -23,7 +25,9 @@ public class CommonCodeDto {
|
||||
@AllArgsConstructor
|
||||
public static class AddReq {
|
||||
|
||||
@NotEmpty
|
||||
private String code;
|
||||
@NotEmpty
|
||||
private String name;
|
||||
private String description;
|
||||
private int order;
|
||||
@@ -45,17 +49,11 @@ public class CommonCodeDto {
|
||||
private Boolean deleted;
|
||||
CommonCodeEntity parent;
|
||||
|
||||
@JsonFormat(
|
||||
shape = JsonFormat.Shape.STRING,
|
||||
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
|
||||
timezone = "Asia/Seoul")
|
||||
private ZonedDateTime createdAt;
|
||||
@JsonFormatDttm
|
||||
private ZonedDateTime createdDttm;
|
||||
|
||||
@JsonFormat(
|
||||
shape = JsonFormat.Shape.STRING,
|
||||
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
|
||||
timezone = "Asia/Seoul")
|
||||
private ZonedDateTime updatedAt;
|
||||
@JsonFormatDttm
|
||||
private ZonedDateTime updatedDttm;
|
||||
|
||||
public Basic(
|
||||
Long id,
|
||||
@@ -66,8 +64,8 @@ public class CommonCodeDto {
|
||||
Boolean used,
|
||||
Boolean deleted,
|
||||
CommonCodeEntity parent,
|
||||
ZonedDateTime createdAt,
|
||||
ZonedDateTime updatedAt) {
|
||||
ZonedDateTime createdDttm,
|
||||
ZonedDateTime updatedDttm) {
|
||||
this.id = id;
|
||||
this.codeCd = codeCd;
|
||||
this.cdCt = cdCt;
|
||||
@@ -76,8 +74,8 @@ public class CommonCodeDto {
|
||||
this.used = used;
|
||||
this.deleted = deleted;
|
||||
this.parent = parent;
|
||||
this.createdAt = createdAt;
|
||||
this.updatedAt = updatedAt;
|
||||
this.createdDttm = createdDttm;
|
||||
this.updatedDttm = updatedDttm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.kamco.cd.kamcoback.common.utils.interfaces;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ ElementType.FIELD, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@JacksonAnnotationsInside
|
||||
@JsonFormat(
|
||||
shape = JsonFormat.Shape.STRING,
|
||||
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
|
||||
timezone = "Asia/Seoul"
|
||||
)
|
||||
public @interface JsonFormatDttm {
|
||||
|
||||
}
|
||||
@@ -22,15 +22,15 @@ public class CommonCodeCoreService implements BaseCoreService<CommonCodeDto.Bas
|
||||
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()));
|
||||
// }
|
||||
if(req.getParentId() != null){
|
||||
CommonCodeEntity parentCommonCodeEntity = commonCodeRepository.findById(req.getParentId())
|
||||
.orElseThrow(() -> new EntityNotFoundException("parent id 를 찾을 수 없습니다. id : " + req.getParentId()));
|
||||
|
||||
CommonCodeEntity entity = new CommonCodeEntity(req.getCode(), req.getName(), req.getDescription(), req.getOrder(), req.isUsed());
|
||||
entity.addParent(parentCommonCodeEntity);
|
||||
return commonCodeRepository.save(entity).toDto();
|
||||
}
|
||||
|
||||
CommonCodeEntity entity = new CommonCodeEntity(req.getCode(), req.getName(), req.getDescription(), req.getOrder(), req.isUsed());
|
||||
CommonCodeEntity saved = commonCodeRepository.save(entity);
|
||||
return saved.toDto();
|
||||
|
||||
@@ -80,6 +80,10 @@ public class CommonCodeEntity extends CommonDateEntity {
|
||||
this.deleted,
|
||||
this.parent,
|
||||
super.getCreatedDate(),
|
||||
super.getModifiedDate());
|
||||
super.getModifiedDate());
|
||||
}
|
||||
|
||||
public void addParent(CommonCodeEntity parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user