JsonFormat

This commit is contained in:
2025-11-18 14:15:52 +09:00
parent af4fe2b2ed
commit a63b4c33f3
6 changed files with 47 additions and 27 deletions

View File

@@ -33,6 +33,7 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.boot:spring-boot-starter-validation'
//geometry //geometry
implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.fasterxml.jackson.core:jackson-databind'

View File

@@ -3,14 +3,13 @@ package com.kamco.cd.kamcoback.code;
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto; import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
import com.kamco.cd.kamcoback.code.service.CommonCodeService; import com.kamco.cd.kamcoback.code.service.CommonCodeService;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto; 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.Operation;
import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -45,7 +44,7 @@ public class CommonCodeApiController {
mediaType = "application/json", mediaType = "application/json",
schema = @Schema(implementation = CommonCodeDto.AddReq.class))) schema = @Schema(implementation = CommonCodeDto.AddReq.class)))
@RequestBody @RequestBody
CommonCodeDto.AddReq req) { @Valid CommonCodeDto.AddReq req) {
Long id = commonCodeService.save(req); Long id = commonCodeService.save(req);
return ApiResponseDto.createOK(id); return ApiResponseDto.createOK(id);
} }

View File

@@ -2,10 +2,12 @@ package com.kamco.cd.kamcoback.code.dto;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore; 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.postgres.entity.CommonCodeEntity;
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.Category; import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.Category;
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.Species; import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.Species;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import java.time.Instant; import java.time.Instant;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@@ -23,7 +25,9 @@ public class CommonCodeDto {
@AllArgsConstructor @AllArgsConstructor
public static class AddReq { public static class AddReq {
@NotEmpty
private String code; private String code;
@NotEmpty
private String name; private String name;
private String description; private String description;
private int order; private int order;
@@ -45,17 +49,11 @@ public class CommonCodeDto {
private Boolean deleted; private Boolean deleted;
CommonCodeEntity parent; CommonCodeEntity parent;
@JsonFormat( @JsonFormatDttm
shape = JsonFormat.Shape.STRING, private ZonedDateTime createdDttm;
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
timezone = "Asia/Seoul")
private ZonedDateTime createdAt;
@JsonFormat( @JsonFormatDttm
shape = JsonFormat.Shape.STRING, private ZonedDateTime updatedDttm;
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
timezone = "Asia/Seoul")
private ZonedDateTime updatedAt;
public Basic( public Basic(
Long id, Long id,
@@ -66,8 +64,8 @@ public class CommonCodeDto {
Boolean used, Boolean used,
Boolean deleted, Boolean deleted,
CommonCodeEntity parent, CommonCodeEntity parent,
ZonedDateTime createdAt, ZonedDateTime createdDttm,
ZonedDateTime updatedAt) { ZonedDateTime updatedDttm) {
this.id = id; this.id = id;
this.codeCd = codeCd; this.codeCd = codeCd;
this.cdCt = cdCt; this.cdCt = cdCt;
@@ -76,8 +74,8 @@ public class CommonCodeDto {
this.used = used; this.used = used;
this.deleted = deleted; this.deleted = deleted;
this.parent = parent; this.parent = parent;
this.createdAt = createdAt; this.createdDttm = createdDttm;
this.updatedAt = updatedAt; this.updatedDttm = updatedDttm;
} }
} }
} }

View File

@@ -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 {
}

View File

@@ -22,15 +22,15 @@ public class CommonCodeCoreService implements BaseCoreService<CommonCodeDto.Bas
private final CommonCodeRepository commonCodeRepository; private final CommonCodeRepository commonCodeRepository;
public CommonCodeDto.Basic save(CommonCodeDto.AddReq req) { public CommonCodeDto.Basic save(CommonCodeDto.AddReq req) {
CommonCodeEntity code = null; if(req.getParentId() != null){
// if (req.getZooUuid() != null) { CommonCodeEntity parentCommonCodeEntity = commonCodeRepository.findById(req.getParentId())
// zoo = .orElseThrow(() -> new EntityNotFoundException("parent id 를 찾을 수 없습니다. id : " + req.getParentId()));
// zooRepository
// .getZooByUuid(req.getZooUuid()) CommonCodeEntity entity = new CommonCodeEntity(req.getCode(), req.getName(), req.getDescription(), req.getOrder(), req.isUsed());
// .orElseThrow( entity.addParent(parentCommonCodeEntity);
// () -> return commonCodeRepository.save(entity).toDto();
// new EntityNotFoundException("Zoo not found with uuid: " + req.getZooUuid())); }
// }
CommonCodeEntity entity = new CommonCodeEntity(req.getCode(), req.getName(), req.getDescription(), req.getOrder(), req.isUsed()); CommonCodeEntity entity = new CommonCodeEntity(req.getCode(), req.getName(), req.getDescription(), req.getOrder(), req.isUsed());
CommonCodeEntity saved = commonCodeRepository.save(entity); CommonCodeEntity saved = commonCodeRepository.save(entity);
return saved.toDto(); return saved.toDto();

View File

@@ -80,6 +80,10 @@ public class CommonCodeEntity extends CommonDateEntity {
this.deleted, this.deleted,
this.parent, this.parent,
super.getCreatedDate(), super.getCreatedDate(),
super.getModifiedDate()); super.getModifiedDate());
}
public void addParent(CommonCodeEntity parent) {
this.parent = parent;
} }
} }