diff --git a/src/main/java/com/klaroworks/runtime/rolematrix/dto/Dtos.java b/src/main/java/com/klaroworks/runtime/rolematrix/dto/Dtos.java new file mode 100644 index 0000000..2aa640e --- /dev/null +++ b/src/main/java/com/klaroworks/runtime/rolematrix/dto/Dtos.java @@ -0,0 +1,46 @@ +package com.klaroworks.runtime.rolematrix.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.klaroworks.runtime.rolematrix.domain.RoleMatrix; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; + +import java.time.Instant; +import java.util.List; + +/** 표준 오류 응답 DTO */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public record ErrorResponse( + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "UTC") Instant timestamp, + int status, String error, String code, String message, String path, String traceId +) { + public static ErrorResponse of(int status, String code, String message, String path, String traceId) { + return new ErrorResponse(Instant.now(), status, resolveErrorName(status), code, message, path, traceId); + } + private static String resolveErrorName(int status) { + return switch (status) { case 400 -> "Bad Request"; case 404 -> "Not Found"; case 409 -> "Conflict"; case 500 -> "Internal Server Error"; default -> "Error"; }; + } +} + +/** 역할 매트릭스 생성 명령 */ +record CreateRoleMatrixCommand( + @NotBlank(message = "역할 매트릭스 이름은 필수입니다") @Size(max = 255) String name, + @Size(max = 1000) String description +) {} + +/** 역할 매트릭스 수정 명령 */ +record UpdateRoleMatrixCommand( + @Size(max = 255) String name, + @Size(max = 1000) String description +) {} + +/** 역할 매트릭스 응답 */ +@JsonInclude(JsonInclude.Include.NON_NULL) +record RoleMatrixResponse( + Long id, String name, String description, List permissionIds, Instant createdAt, Instant updatedAt +) { + public static RoleMatrixResponse from(RoleMatrix entity) { + return new RoleMatrixResponse(entity.getId(), entity.getName(), entity.getDescription(), entity.getPermissionIds(), entity.getCreatedAt(), entity.getUpdatedAt()); + } +}