From 12aa3ae5a3779d36159f736fc446689a30e2d290 Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Tue, 26 Aug 2025 13:31:03 +0900 Subject: [PATCH 01/11] =?UTF-8?q?[=ED=8C=8C=EC=9D=BC=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20=EA=B0=9C=EC=84=A0]=20FileUploadResponseDto=20?= =?UTF-8?q?=EB=B0=8F=20MultipleFileUploadResponseDto=EC=97=90=20groupOid?= =?UTF-8?q?=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80,=20FileServiceImpl?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=9D=91=EB=8B=B5=20DTO=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=20=EB=B0=8F?= =?UTF-8?q?=20createUploadResponse=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0.=20FileUtils=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EC=97=90=20=ED=8C=8C=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=A0=9C=EA=B1=B0=EB=A1=9C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/base/file/dto/FileUploadDto.java | 16 ++ .../base/file/dto/FileUploadResponseDto.java | 3 + .../dto/MultipleFileUploadRequestDto.java | 2 + .../dto/MultipleFileUploadResponseDto.java | 1 + .../base/file/service/FileServiceImpl.java | 23 +- .../bio_backend/global/utils/FileUtils.java | 267 +++--------------- 6 files changed, 81 insertions(+), 231 deletions(-) create mode 100644 src/main/java/com/bio/bio_backend/domain/base/file/dto/FileUploadDto.java diff --git a/src/main/java/com/bio/bio_backend/domain/base/file/dto/FileUploadDto.java b/src/main/java/com/bio/bio_backend/domain/base/file/dto/FileUploadDto.java new file mode 100644 index 0000000..ac202b1 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/base/file/dto/FileUploadDto.java @@ -0,0 +1,16 @@ +package com.bio.bio_backend.domain.base.file.dto; + +import lombok.Builder; +import lombok.Data; +import java.util.List; + +@Data +@Builder +public class FileUploadDto { + private Long groupOid; + private List files; // 파일 정보들 + private int totalCount; + private int successCount; + private int failureCount; + private List errorMessages; +} diff --git a/src/main/java/com/bio/bio_backend/domain/base/file/dto/FileUploadResponseDto.java b/src/main/java/com/bio/bio_backend/domain/base/file/dto/FileUploadResponseDto.java index 56162fd..f7fe9e1 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/file/dto/FileUploadResponseDto.java +++ b/src/main/java/com/bio/bio_backend/domain/base/file/dto/FileUploadResponseDto.java @@ -1,12 +1,15 @@ package com.bio.bio_backend.domain.base.file.dto; +import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Builder; import lombok.Data; @Data @Builder +@JsonInclude(JsonInclude.Include.NON_NULL) public class FileUploadResponseDto { private Long oid; + private Long groupOid; private String originalFileName; private String downloadUrl; } diff --git a/src/main/java/com/bio/bio_backend/domain/base/file/dto/MultipleFileUploadRequestDto.java b/src/main/java/com/bio/bio_backend/domain/base/file/dto/MultipleFileUploadRequestDto.java index 91d668f..d86cba8 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/file/dto/MultipleFileUploadRequestDto.java +++ b/src/main/java/com/bio/bio_backend/domain/base/file/dto/MultipleFileUploadRequestDto.java @@ -1,10 +1,12 @@ package com.bio.bio_backend.domain.base.file.dto; +import lombok.Builder; import lombok.Data; import org.springframework.web.multipart.MultipartFile; import java.util.List; @Data +@Builder public class MultipleFileUploadRequestDto { private List files; private String description; diff --git a/src/main/java/com/bio/bio_backend/domain/base/file/dto/MultipleFileUploadResponseDto.java b/src/main/java/com/bio/bio_backend/domain/base/file/dto/MultipleFileUploadResponseDto.java index c89529f..f6792c0 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/file/dto/MultipleFileUploadResponseDto.java +++ b/src/main/java/com/bio/bio_backend/domain/base/file/dto/MultipleFileUploadResponseDto.java @@ -8,6 +8,7 @@ import java.util.List; @Builder public class MultipleFileUploadResponseDto { private List files; + private Long groupOid; private int totalCount; private int successCount; private int failureCount; diff --git a/src/main/java/com/bio/bio_backend/domain/base/file/service/FileServiceImpl.java b/src/main/java/com/bio/bio_backend/domain/base/file/service/FileServiceImpl.java index 2778f65..99b1af7 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/file/service/FileServiceImpl.java +++ b/src/main/java/com/bio/bio_backend/domain/base/file/service/FileServiceImpl.java @@ -57,7 +57,12 @@ public class FileServiceImpl implements FileService { File savedFile = processFileUpload(multipartFile, requestDto.getDescription(), generateOid()); // 응답 DTO 생성 및 반환 - return createUploadResponse(savedFile); + return FileUploadResponseDto.builder() + .oid(savedFile.getOid()) + .groupOid(savedFile.getGroupOid()) + .originalFileName(savedFile.getOriginalFileName()) + .downloadUrl(contextPath + "/files/download/" + savedFile.getOid()) + .build(); } @Override @@ -90,7 +95,11 @@ public class FileServiceImpl implements FileService { // 단일 파일 업로드 처리 File savedFile = processFileUpload(multipartFile, requestDto.getDescription(), groupOid); - FileUploadResponseDto uploadedFile = createUploadResponse(savedFile); + FileUploadResponseDto uploadedFile = FileUploadResponseDto.builder() + .oid(savedFile.getOid()) + .originalFileName(savedFile.getOriginalFileName()) + .downloadUrl(contextPath + "/files/download/" + savedFile.getOid()) + .build(); uploadedFiles.add(uploadedFile); successCount++; @@ -105,8 +114,8 @@ public class FileServiceImpl implements FileService { } } - // 다중 파일 업로드 결과 반환 return MultipleFileUploadResponseDto.builder() + .groupOid(groupOid) .files(uploadedFiles) .totalCount(files.size()) .successCount(successCount) @@ -157,14 +166,6 @@ public class FileServiceImpl implements FileService { .groupOid(groupOid) .build(); } - - private FileUploadResponseDto createUploadResponse(File savedFile) { - return FileUploadResponseDto.builder() - .oid(savedFile.getOid()) - .originalFileName(savedFile.getOriginalFileName()) - .downloadUrl(contextPath + "/files/download/" + savedFile.getOid()) - .build(); - } @Override public File getFileByOid(Long oid) { diff --git a/src/main/java/com/bio/bio_backend/global/utils/FileUtils.java b/src/main/java/com/bio/bio_backend/global/utils/FileUtils.java index ae0bbf9..ec06f9f 100644 --- a/src/main/java/com/bio/bio_backend/global/utils/FileUtils.java +++ b/src/main/java/com/bio/bio_backend/global/utils/FileUtils.java @@ -2,21 +2,32 @@ package com.bio.bio_backend.global.utils; import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.UUID; +import org.springframework.stereotype.Component; +import lombok.RequiredArgsConstructor; +import com.bio.bio_backend.domain.base.file.dto.FileUploadDto; +import com.bio.bio_backend.domain.base.file.dto.FileUploadResponseDto; +import com.bio.bio_backend.domain.base.file.dto.MultipleFileUploadRequestDto; +import com.bio.bio_backend.domain.base.file.dto.MultipleFileUploadResponseDto; +import com.bio.bio_backend.domain.base.file.service.FileService; +import java.util.List; +import com.bio.bio_backend.domain.base.file.dto.FileUploadRequestDto; /** * 파일 관련 유틸리티 클래스 */ +@Component +@RequiredArgsConstructor public class FileUtils { + private final FileService fileService; + /** * 파일 유효성 검사 */ @@ -35,32 +46,6 @@ public class FileUtils { } } - /** - * 업로드 디렉토리 생성 - */ - public static Path createUploadDirectory(String uploadPath) throws IOException { - Path uploadDir = Paths.get(uploadPath); - if (!Files.exists(uploadDir)) { - Files.createDirectories(uploadDir); - } - return uploadDir; - } - - /** - * 년월일 기반 업로드 디렉토리 생성 - * 예: uploads/2024/01/15/ - */ - public static Path createDateBasedUploadDirectory(String baseUploadPath) throws IOException { - LocalDate today = LocalDate.now(); - String yearMonthDay = today.format(DateTimeFormatter.ofPattern("yyyy/MM/dd")); - - Path dateBasedPath = Paths.get(baseUploadPath, yearMonthDay); - if (!Files.exists(dateBasedPath)) { - Files.createDirectories(dateBasedPath); - } - return dateBasedPath; - } - /** * 년월 기반 업로드 디렉토리 생성 * 예: uploads/2024/01/ @@ -76,35 +61,6 @@ public class FileUtils { return yearMonthPath; } - /** - * 년 기반 업로드 디렉토리 생성 - * 예: uploads/2024/ - */ - public static Path createYearUploadDirectory(String baseUploadPath) throws IOException { - LocalDate today = LocalDate.now(); - String year = today.format(DateTimeFormatter.ofPattern("yyyy")); - - Path yearPath = Paths.get(baseUploadPath, year); - if (!Files.exists(yearPath)) { - Files.createDirectories(yearPath); - } - return yearPath; - } - - /** - * 지정된 날짜로 업로드 디렉토리 생성 - * 예: uploads/2024/01/15/ - */ - public static Path createDateBasedUploadDirectory(String baseUploadPath, LocalDate date) throws IOException { - String yearMonthDay = date.format(DateTimeFormatter.ofPattern("yyyy/MM/dd")); - - Path dateBasedPath = Paths.get(baseUploadPath, yearMonthDay); - if (!Files.exists(dateBasedPath)) { - Files.createDirectories(dateBasedPath); - } - return dateBasedPath; - } - /** * 파일 확장자 추출 */ @@ -127,7 +83,7 @@ public class FileUtils { */ public static Path saveFileToDisk(MultipartFile multipartFile, Path uploadDir, String storedFileName) throws IOException { Path targetLocation = uploadDir.resolve(storedFileName); - Files.copy(multipartFile.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING); + Files.copy(multipartFile.getInputStream(), targetLocation, java.nio.file.StandardCopyOption.REPLACE_EXISTING); return targetLocation; } @@ -137,174 +93,45 @@ public class FileUtils { public static String cleanFileName(String originalFileName) { return StringUtils.cleanPath(originalFileName); } + /** - * 파일 크기를 사람이 읽기 쉬운 형태로 변환 + * 파일 업로드 (단일/다중 파일 모두 지원) + * 사용 예시: + * // 단일 파일 업로드 + * FileUploadDto fileResult = fileUtils.uploadFile( + * requestDto.getFile(), + * "프로필 이미지" + * ); + * member.setFileGroupId(fileResult.getGroupOid()); + * // 다중 파일 업로드 + * FileUploadDto filesResult = fileUtils.uploadFiles( + * requestDto.getFiles(), + * "게시판 첨부파일: " + board.getTitle() + * ); + * board.setFileGroupId(filesResult.getGroupOid()); */ - public static String formatFileSize(long bytes) { - if (bytes < 1024) return bytes + " B"; - if (bytes < 1024 * 1024) return String.format("%.1f KB", bytes / 1024.0); - if (bytes < 1024 * 1024 * 1024) return String.format("%.1f MB", bytes / (1024.0 * 1024.0)); - return String.format("%.1f GB", bytes / (1024.0 * 1024.0 * 1024.0)); + public FileUploadDto uploadFile(MultipartFile file, String description) { + // 단일 파일도 List로 감싸서 다중 파일 업로드 방식 사용 + List files = List.of(file); + return uploadFiles(files, description); } - /** - * 파일 확장자로부터 MIME 타입 추정 - */ - public static String getMimeTypeFromExtension(String fileName) { - if (fileName == null) return "application/octet-stream"; + public FileUploadDto uploadFiles(List files, String description) { + MultipleFileUploadRequestDto requestDto = MultipleFileUploadRequestDto.builder() + .files(files) + .description(description) + .build(); - String extension = extractFileExtension(fileName).toLowerCase(); - switch (extension) { - case ".txt": return "text/plain"; - case ".html": case ".htm": return "text/html"; - case ".css": return "text/css"; - case ".js": return "application/javascript"; - case ".json": return "application/json"; - case ".xml": return "application/xml"; - case ".pdf": return "application/pdf"; - case ".zip": return "application/zip"; - case ".jpg": case ".jpeg": return "image/jpeg"; - case ".png": return "image/png"; - case ".gif": return "image/gif"; - case ".bmp": return "image/bmp"; - case ".svg": return "image/svg+xml"; - case ".mp4": return "video/mp4"; - case ".avi": return "video/x-msvideo"; - case ".mp3": return "audio/mpeg"; - case ".wav": return "audio/wav"; - default: return "application/octet-stream"; - } - } - - /** - * 안전한 파일명 생성 (특수문자 제거) - */ - public static String createSafeFileName(String originalFileName) { - if (originalFileName == null) return ""; + MultipleFileUploadResponseDto response = fileService.uploadMultipleFiles(requestDto); - // 특수문자 제거 및 공백을 언더스코어로 변경 - String safeName = originalFileName - .replaceAll("[^a-zA-Z0-9가-힣._-]", "_") - .replaceAll("_+", "_") - .trim(); - - // 파일명이 너무 길면 자르기 - if (safeName.length() > 100) { - String extension = extractFileExtension(safeName); - safeName = safeName.substring(0, 100 - extension.length()) + extension; - } - - return safeName; - } - - /** - * 파일이 이미지인지 확인 - */ - public static boolean isImageFile(String fileName) { - if (fileName == null) return false; - - String extension = extractFileExtension(fileName).toLowerCase(); - return extension.matches("\\.(jpg|jpeg|png|gif|bmp|svg|webp)$"); - } - - /** - * 파일이 문서인지 확인 - */ - public static boolean isDocumentFile(String fileName) { - if (fileName == null) return false; - - String extension = extractFileExtension(fileName).toLowerCase(); - return extension.matches("\\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|rtf)$"); - } - - /** - * 파일이 압축파일인지 확인 - */ - public static boolean isArchiveFile(String fileName) { - if (fileName == null) return false; - - String extension = extractFileExtension(fileName).toLowerCase(); - return extension.matches("\\.(zip|rar|7z|tar|gz|bz2)$"); - } - - /** - * 현재 날짜의 년월일 문자열 반환 - * 예: "2024/01/15" - */ - public static String getCurrentDatePath() { - LocalDate today = LocalDate.now(); - return today.format(DateTimeFormatter.ofPattern("yyyy/MM/dd")); - } - - /** - * 지정된 날짜의 년월일 문자열 반환 - * 예: "2024/01/15" - */ - public static String getDatePath(LocalDate date) { - return date.format(DateTimeFormatter.ofPattern("yyyy/MM/dd")); - } - - /** - * 파일 경로에서 년월일 정보 추출 - * 예: "uploads/2024/01/15/file.txt" -> "2024/01/15" - */ - public static String extractDateFromPath(String filePath) { - if (filePath == null || filePath.isEmpty()) { - return ""; - } - - // 정규식으로 년/월/일 패턴 찾기 - java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("(\\d{4}/\\d{2}/\\d{2})"); - java.util.regex.Matcher matcher = pattern.matcher(filePath); - - if (matcher.find()) { - return matcher.group(1); - } - - return ""; - } - - /** - * 년월일 폴더 구조가 유효한지 확인 - * 예: "2024/01/15" -> true, "2024/13/45" -> false - */ - public static boolean isValidDatePath(String datePath) { - if (datePath == null || datePath.isEmpty()) { - return false; - } - - try { - String[] parts = datePath.split("/"); - if (parts.length != 3) { - return false; - } - - int year = Integer.parseInt(parts[0]); - int month = Integer.parseInt(parts[1]); - int day = Integer.parseInt(parts[2]); - - // 년도 범위 체크 (1900 ~ 2100) - if (year < 1900 || year > 2100) { - return false; - } - - // 월 범위 체크 (1 ~ 12) - if (month < 1 || month > 12) { - return false; - } - - // 일 범위 체크 (1 ~ 31) - if (day < 1 || day > 31) { - return false; - } - - // 실제 존재하는 날짜인지 확인 - LocalDate.of(year, month, day); - return true; - - } catch (Exception e) { - return false; - } + return FileUploadDto.builder() + .groupOid(response.getGroupOid()) + .files(response.getFiles()) + .totalCount(response.getTotalCount()) + .successCount(response.getSuccessCount()) + .failureCount(response.getFailureCount()) + .errorMessages(response.getErrorMessages()) + .build(); } } From d37986558e503985efa4eb0841ef42194d5fdae4 Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Tue, 26 Aug 2025 13:59:51 +0900 Subject: [PATCH 02/11] =?UTF-8?q?[=ED=8C=8C=EC=9D=BC=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20=EA=B0=9C=EC=84=A0]=20FileUploadRequestDto=EC=97=90?= =?UTF-8?q?=EC=84=9C=20groupOid=20=ED=95=84=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bio_backend/domain/base/file/dto/FileUploadRequestDto.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/bio/bio_backend/domain/base/file/dto/FileUploadRequestDto.java b/src/main/java/com/bio/bio_backend/domain/base/file/dto/FileUploadRequestDto.java index 4e89e9c..77c2c09 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/file/dto/FileUploadRequestDto.java +++ b/src/main/java/com/bio/bio_backend/domain/base/file/dto/FileUploadRequestDto.java @@ -7,5 +7,4 @@ import org.springframework.web.multipart.MultipartFile; public class FileUploadRequestDto { private MultipartFile file; private String description; - private Long groupOid; } From 88a508bd5448090663c8850c515c4d977d6f9b4d Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Tue, 26 Aug 2025 15:50:43 +0900 Subject: [PATCH 03/11] =?UTF-8?q?[=EA=B3=B5=ED=86=B5=20=EC=BD=94=EB=93=9C]?= =?UTF-8?q?=20=EC=A4=91=EA=B0=84=20=EC=BB=A4=EB=B0=8B=EB=B0=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddl/schema.sql | 65 ++++++ .../controller/CommonCodeController.java | 208 ++++++++++++++++++ .../admin/CommonCode/dto/CommonCodeDto.java | 29 +++ .../CommonCode/dto/CommonGroupCodeDto.java | 28 +++ .../dto/CreateCommonCodeRequestDto.java | 55 +++++ .../dto/CreateCommonCodeResponseDto.java | 30 +++ .../dto/CreateCommonGroupCodeRequestDto.java | 45 ++++ .../dto/CreateCommonGroupCodeResponseDto.java | 27 +++ .../dto/UpdateCommonCodeRequestDto.java | 49 +++++ .../dto/UpdateCommonGroupCodeRequestDto.java | 39 ++++ .../admin/CommonCode/entity/CommonCode.java | 73 ++++++ .../CommonCode/entity/CommonGroupCode.java | 53 +++++ .../CommonCode/mapper/CommonCodeMapper.java | 68 ++++++ .../mapper/CommonGroupCodeMapper.java | 67 ++++++ .../repository/CommonCodeRepository.java | 32 +++ .../repository/CommonGroupCodeRepository.java | 23 ++ .../CommonCode/service/CommonCodeService.java | 28 +++ .../service/CommonCodeServiceImpl.java | 165 ++++++++++++++ 18 files changed, 1084 insertions(+) create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/controller/CommonCodeController.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonCodeDto.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonGroupCodeDto.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeRequestDto.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeResponseDto.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeRequestDto.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeResponseDto.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonCodeRequestDto.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonGroupCodeRequestDto.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonCode.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonGroupCode.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonCodeMapper.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonGroupCodeMapper.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonCodeRepository.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonGroupCodeRepository.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeService.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeServiceImpl.java diff --git a/ddl/schema.sql b/ddl/schema.sql index e406dac..4c4c75d 100644 --- a/ddl/schema.sql +++ b/ddl/schema.sql @@ -1,4 +1,47 @@ + create table st_common_code ( + sort_order integer not null, + use_flag boolean not null, + created_at timestamp(6) not null, + created_oid bigint, + oid bigint not null, + updated_at timestamp(6) not null, + updated_oid bigint, + code varchar(50) not null unique, + group_code varchar(50) not null, + parent_code varchar(50), + character_ref1 varchar(100), + character_ref2 varchar(100), + character_ref3 varchar(100), + character_ref4 varchar(100), + character_ref5 varchar(100), + name varchar(100) not null, + description varchar(500), + created_id varchar(255), + updated_id varchar(255), + primary key (oid) + ); + + create table st_common_group_code ( + sort_order integer not null, + use_flag boolean not null, + created_at timestamp(6) not null, + created_oid bigint, + oid bigint not null, + updated_at timestamp(6) not null, + updated_oid bigint, + code varchar(50) not null unique, + character_ref1_title varchar(100), + character_ref2_title varchar(100), + character_ref3_title varchar(100), + character_ref4_title varchar(100), + character_ref5_title varchar(100), + name varchar(100) not null, + created_id varchar(255), + updated_id varchar(255), + primary key (oid) + ); + create table st_file ( use_flag boolean not null, created_at timestamp(6) not null, @@ -38,5 +81,27 @@ primary key (oid) ); + create index idx_common_code_code + on st_common_code (code); + + create index idx_common_code_group_code + on st_common_code (group_code); + + create index idx_common_code_parent_code + on st_common_code (parent_code); + + create index idx_common_group_code_code + on st_common_group_code (code); + create index idx_member_user_id on st_member (user_id); + + alter table if exists st_common_code + add constraint FKdk30t67v5e2vo1k7gl5sk1jp9 + foreign key (group_code) + references st_common_group_code (code); + + alter table if exists st_common_code + add constraint FKgcyw9ydft76p31oox94ho93wf + foreign key (parent_code) + references st_common_code (code); diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/controller/CommonCodeController.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/controller/CommonCodeController.java new file mode 100644 index 0000000..b2fa801 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/controller/CommonCodeController.java @@ -0,0 +1,208 @@ +package com.bio.bio_backend.domain.admin.CommonCode.controller; + +import com.bio.bio_backend.domain.admin.CommonCode.dto.*; +import com.bio.bio_backend.domain.admin.CommonCode.service.CommonCodeService; +import com.bio.bio_backend.domain.admin.CommonCode.mapper.CommonCodeMapper; +import com.bio.bio_backend.domain.admin.CommonCode.mapper.CommonGroupCodeMapper; +import com.bio.bio_backend.global.dto.ApiResponseDto; +import com.bio.bio_backend.global.constants.ApiResponseCode; +import com.bio.bio_backend.global.annotation.LogExecution; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import jakarta.validation.Valid; +import java.util.List; + +@Slf4j +@RestController +@RequestMapping("/admin/common-code") +@RequiredArgsConstructor +@Tag(name = "공통 코드 관리", description = "공통 코드 및 그룹 코드 관리 API") +public class CommonCodeController { + + private final CommonCodeService commonCodeService; + private final CommonCodeMapper commonCodeMapper; + private final CommonGroupCodeMapper commonGroupCodeMapper; + + // 그룹 코드 관련 API + @LogExecution("그룹 코드 생성") + @Operation(summary = "그룹 코드 생성", description = "새로운 그룹 코드를 생성합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "201", description = "그룹 코드 생성 성공"), + @ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))), + @ApiResponse(responseCode = "409", description = "중복된 그룹 코드", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))) + }) + @PostMapping("/group") + public ResponseEntity> createGroupCode(@RequestBody @Valid CreateCommonGroupCodeRequestDto requestDto) { + CommonGroupCodeDto groupCodeDto = commonGroupCodeMapper.toCommonGroupCodeDto(requestDto); + CommonGroupCodeDto createdGroupCode = commonCodeService.createGroupCode(groupCodeDto); + CreateCommonGroupCodeResponseDto responseDto = commonGroupCodeMapper.toCreateCommonGroupCodeResponseDto(createdGroupCode); + ApiResponseDto apiResponse = ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_CREATED, responseDto); + + return ResponseEntity.status(HttpStatus.CREATED).body(apiResponse); + } + + @LogExecution("그룹 코드 수정") + @Operation(summary = "그룹 코드 수정", description = "기존 그룹 코드를 수정합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "그룹 코드 수정 성공"), + @ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))), + @ApiResponse(responseCode = "404", description = "그룹 코드를 찾을 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))) + }) + @PutMapping("/group/{code}") + public ResponseEntity> updateGroupCode( + @PathVariable String code, + @RequestBody @Valid UpdateCommonGroupCodeRequestDto requestDto) { + CommonGroupCodeDto groupCodeDto = commonGroupCodeMapper.toCommonGroupCodeDto(requestDto); + commonCodeService.updateGroupCode(code, groupCodeDto); + return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_UPDATED)); + } + + @LogExecution("그룹 코드 삭제") + @Operation(summary = "그룹 코드 삭제", description = "그룹 코드를 삭제합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "그룹 코드 삭제 성공"), + @ApiResponse(responseCode = "400", description = "하위 공통 코드가 존재하여 삭제할 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))), + @ApiResponse(responseCode = "404", description = "그룹 코드를 찾을 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))) + }) + @DeleteMapping("/group/{code}") + public ResponseEntity> deleteGroupCode(@PathVariable String code) { + commonCodeService.deleteGroupCode(code); + return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_DELETED)); + } + + @LogExecution("그룹 코드 조회") + @Operation(summary = "그룹 코드 조회", description = "특정 그룹 코드를 조회합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "그룹 코드 조회 성공"), + @ApiResponse(responseCode = "404", description = "그룹 코드를 찾을 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))) + }) + @GetMapping("/group/{code}") + public ResponseEntity> getGroupCode(@PathVariable String code) { + CommonGroupCodeDto groupCode = commonCodeService.getGroupCode(code); + return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, groupCode)); + } + + @LogExecution("전체 그룹 코드 조회") + @Operation(summary = "전체 그룹 코드 조회", description = "모든 그룹 코드를 조회합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "전체 그룹 코드 조회 성공") + }) + @GetMapping("/group") + public ResponseEntity>> getAllGroupCodes() { + List groupCodes = commonCodeService.getAllGroupCodes(); + return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, groupCodes)); + } + + @LogExecution("활성 그룹 코드 조회") + @Operation(summary = "활성 그룹 코드 조회", description = "사용 중인 그룹 코드만 조회합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "활성 그룹 코드 조회 성공") + }) + @GetMapping("/group/active") + public ResponseEntity>> getActiveGroupCodes() { + List groupCodes = commonCodeService.getActiveGroupCodes(); + return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, groupCodes)); + } + + // 공통 코드 관련 API + @LogExecution("공통 코드 생성") + @Operation(summary = "공통 코드 생성", description = "새로운 공통 코드를 생성합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "201", description = "공통 코드 생성 성공"), + @ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))), + @ApiResponse(responseCode = "409", description = "중복된 공통 코드", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))) + }) + @PostMapping + public ResponseEntity> createCode(@RequestBody @Valid CreateCommonCodeRequestDto requestDto) { + CommonCodeDto commonCodeDto = commonCodeMapper.toCommonCodeDto(requestDto); + CommonCodeDto createdCommonCode = commonCodeService.createCode(commonCodeDto); + CreateCommonCodeResponseDto responseDto = commonCodeMapper.toCreateCommonCodeResponseDto(createdCommonCode); + ApiResponseDto apiResponse = ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_CREATED, responseDto); + + return ResponseEntity.status(HttpStatus.CREATED).body(apiResponse); + } + + @LogExecution("공통 코드 수정") + @Operation(summary = "공통 코드 수정", description = "기존 공통 코드를 수정합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "공통 코드 수정 성공"), + @ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))), + @ApiResponse(responseCode = "404", description = "공통 코드를 찾을 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))) + }) + @PutMapping("/{code}") + public ResponseEntity> updateCode( + @PathVariable String code, + @RequestBody @Valid UpdateCommonCodeRequestDto requestDto) { + CommonCodeDto commonCodeDto = commonCodeMapper.toCommonCodeDto(requestDto); + commonCodeService.updateCode(code, commonCodeDto); + return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_UPDATED)); + } + + @LogExecution("공통 코드 삭제") + @Operation(summary = "공통 코드 삭제", description = "공통 코드를 삭제합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "공통 코드 삭제 성공"), + @ApiResponse(responseCode = "400", description = "하위 공통 코드가 존재하여 삭제할 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))), + @ApiResponse(responseCode = "404", description = "공통 코드를 찾을 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))) + }) + @DeleteMapping("/{code}") + public ResponseEntity> deleteCode(@PathVariable String code) { + commonCodeService.deleteCode(code); + return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_DELETED)); + } + + @LogExecution("공통 코드 조회") + @Operation(summary = "공통 코드 조회", description = "특정 공통 코드를 조회합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "공통 코드 조회 성공"), + @ApiResponse(responseCode = "404", description = "공통 코드를 찾을 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))) + }) + @GetMapping("/{code}") + public ResponseEntity> getCode(@PathVariable String code) { + CommonCodeDto commonCode = commonCodeService.getCode(code); + return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, commonCode)); + } + + @LogExecution("그룹별 공통 코드 조회") + @Operation(summary = "그룹별 공통 코드 조회", description = "특정 그룹에 속한 공통 코드들을 조회합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "그룹별 공통 코드 조회 성공") + }) + @GetMapping("/group/{groupCode}/codes") + public ResponseEntity>> getCodesByGroupCode(@PathVariable String groupCode) { + List commonCodes = commonCodeService.getActiveCodesByGroupCode(groupCode); + return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, commonCodes)); + } + + @LogExecution("상위 코드별 공통 코드 조회") + @Operation(summary = "상위 코드별 공통 코드 조회", description = "특정 상위 코드에 속한 공통 코드들을 조회합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "상위 코드별 공통 코드 조회 성공") + }) + @GetMapping("/parent/{parentCode}/codes") + public ResponseEntity>> getCodesByParentCode(@PathVariable String parentCode) { + List commonCodes = commonCodeService.getActiveCodesByParentCode(parentCode); + return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, commonCodes)); + } + + @LogExecution("전체 공통 코드 조회") + @Operation(summary = "전체 공통 코드 조회", description = "모든 공통 코드를 조회합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "전체 공통 코드 조회 성공") + }) + @GetMapping + public ResponseEntity>> getAllCodes() { + List commonCodes = commonCodeService.getAllCodes(); + return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, commonCodes)); + } +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonCodeDto.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonCodeDto.java new file mode 100644 index 0000000..4f72c12 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonCodeDto.java @@ -0,0 +1,29 @@ +package com.bio.bio_backend.domain.admin.CommonCode.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CommonCodeDto { + + private Long oid; + private String code; + private String name; + private String description; + private String groupCode; + private String parentCode; + private String characterRef1; + private String characterRef2; + private String characterRef3; + private String characterRef4; + private String characterRef5; + private Integer sortOrder; + private Boolean useFlag; +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonGroupCodeDto.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonGroupCodeDto.java new file mode 100644 index 0000000..656bc21 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonGroupCodeDto.java @@ -0,0 +1,28 @@ +package com.bio.bio_backend.domain.admin.CommonCode.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CommonGroupCodeDto { + + private Long oid; + private String code; + private String name; + private String characterRef1Title; + private String characterRef2Title; + private String characterRef3Title; + private String characterRef4Title; + private String characterRef5Title; + private Integer sortOrder; + private Boolean useFlag; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeRequestDto.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeRequestDto.java new file mode 100644 index 0000000..e208395 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeRequestDto.java @@ -0,0 +1,55 @@ +package com.bio.bio_backend.domain.admin.CommonCode.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CreateCommonCodeRequestDto { + + @NotBlank(message = "코드는 필수입니다") + @Size(max = 50, message = "코드는 50자를 초과할 수 없습니다") + private String code; + + @NotBlank(message = "이름은 필수입니다") + @Size(max = 100, message = "이름은 100자를 초과할 수 없습니다") + private String name; + + @Size(max = 500, message = "설명은 500자를 초과할 수 없습니다") + private String description; + + @NotBlank(message = "그룹 코드는 필수입니다") + @Size(max = 50, message = "그룹 코드는 50자를 초과할 수 없습니다") + private String groupCode; + + @Size(max = 50, message = "상위 코드는 50자를 초과할 수 없습니다") + private String parentCode; + + @Size(max = 100, message = "문자 참조1은 100자를 초과할 수 없습니다") + private String characterRef1; + + @Size(max = 100, message = "문자 참조2는 100자를 초과할 수 없습니다") + private String characterRef2; + + @Size(max = 100, message = "문자 참조3은 100자를 초과할 수 없습니다") + private String characterRef3; + + @Size(max = 100, message = "문자 참조4는 100자를 초과할 수 없습니다") + private String characterRef4; + + @Size(max = 100, message = "문자 참조5는 100자를 초과할 수 없습니다") + private String characterRef5; + + @Builder.Default + private Integer sortOrder = 0; + + @Builder.Default + private Boolean useFlag = true; +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeResponseDto.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeResponseDto.java new file mode 100644 index 0000000..4b9f3ff --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeResponseDto.java @@ -0,0 +1,30 @@ +package com.bio.bio_backend.domain.admin.CommonCode.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CreateCommonCodeResponseDto { + + private Long oid; + private String code; + private String name; + private String description; + private String groupCode; + private String parentCode; + private String characterRef1; + private String characterRef2; + private String characterRef3; + private String characterRef4; + private String characterRef5; + private Integer sortOrder; + private Boolean useFlag; + private LocalDateTime createdAt; +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeRequestDto.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeRequestDto.java new file mode 100644 index 0000000..60df3d6 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeRequestDto.java @@ -0,0 +1,45 @@ +package com.bio.bio_backend.domain.admin.CommonCode.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CreateCommonGroupCodeRequestDto { + + @NotBlank(message = "코드는 필수입니다") + @Size(max = 50, message = "코드는 50자를 초과할 수 없습니다") + private String code; + + @NotBlank(message = "이름은 필수입니다") + @Size(max = 100, message = "이름은 100자를 초과할 수 없습니다") + private String name; + + @Size(max = 100, message = "차트 참조1 제목은 100자를 초과할 수 없습니다") + private String characterRef1Title; + + @Size(max = 100, message = "차트 참조2 제목은 100자를 초과할 수 없습니다") + private String characterRef2Title; + + @Size(max = 100, message = "차트 참조3 제목은 100자를 초과할 수 없습니다") + private String characterRef3Title; + + @Size(max = 100, message = "차트 참조4 제목은 100자를 초과할 수 없습니다") + private String characterRef4Title; + + @Size(max = 100, message = "차트 참조5 제목은 100자를 초과할 수 없습니다") + private String characterRef5Title; + + @Builder.Default + private Integer sortOrder = 0; + + @Builder.Default + private Boolean useFlag = true; +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeResponseDto.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeResponseDto.java new file mode 100644 index 0000000..fdab153 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeResponseDto.java @@ -0,0 +1,27 @@ +package com.bio.bio_backend.domain.admin.CommonCode.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CreateCommonGroupCodeResponseDto { + + private Long oid; + private String code; + private String name; + private String characterRef1Title; + private String characterRef2Title; + private String characterRef3Title; + private String characterRef4Title; + private String characterRef5Title; + private Integer sortOrder; + private Boolean useFlag; + private LocalDateTime createdAt; +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonCodeRequestDto.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonCodeRequestDto.java new file mode 100644 index 0000000..a4dd497 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonCodeRequestDto.java @@ -0,0 +1,49 @@ +package com.bio.bio_backend.domain.admin.CommonCode.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class UpdateCommonCodeRequestDto { + + @NotBlank(message = "이름은 필수입니다") + @Size(max = 100, message = "이름은 100자를 초과할 수 없습니다") + private String name; + + @Size(max = 500, message = "설명은 500자를 초과할 수 없습니다") + private String description; + + @NotBlank(message = "그룹 코드는 필수입니다") + @Size(max = 50, message = "그룹 코드는 50자를 초과할 수 없습니다") + private String groupCode; + + @Size(max = 50, message = "상위 코드는 50자를 초과할 수 없습니다") + private String parentCode; + + @Size(max = 100, message = "문자 참조1은 100자를 초과할 수 없습니다") + private String characterRef1; + + @Size(max = 100, message = "문자 참조2는 100자를 초과할 수 없습니다") + private String characterRef2; + + @Size(max = 100, message = "문자 참조3은 100자를 초과할 수 없습니다") + private String characterRef3; + + @Size(max = 100, message = "문자 참조4는 100자를 초과할 수 없습니다") + private String characterRef4; + + @Size(max = 100, message = "문자 참조5는 100자를 초과할 수 없습니다") + private String characterRef5; + + private Integer sortOrder; + + private Boolean useFlag; +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonGroupCodeRequestDto.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonGroupCodeRequestDto.java new file mode 100644 index 0000000..ec2d6ff --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonGroupCodeRequestDto.java @@ -0,0 +1,39 @@ +package com.bio.bio_backend.domain.admin.CommonCode.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class UpdateCommonGroupCodeRequestDto { + + @NotBlank(message = "이름은 필수입니다") + @Size(max = 100, message = "이름은 100자를 초과할 수 없습니다") + private String name; + + @Size(max = 100, message = "문자 참조1 제목은 100자를 초과할 수 없습니다") + private String characterRef1Title; + + @Size(max = 100, message = "문자 참조2 제목은 100자를 초과할 수 없습니다") + private String characterRef2Title; + + @Size(max = 100, message = "문자 참조3 제목은 100자를 초과할 수 없습니다") + private String characterRef3Title; + + @Size(max = 100, message = "문자 참조4 제목은 100자를 초과할 수 없습니다") + private String characterRef4Title; + + @Size(max = 100, message = "문자 참조5 제목은 100자를 초과할 수 없습니다") + private String characterRef5Title; + + private Integer sortOrder; + + private Boolean useFlag; +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonCode.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonCode.java new file mode 100644 index 0000000..4616d6e --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonCode.java @@ -0,0 +1,73 @@ +package com.bio.bio_backend.domain.admin.CommonCode.entity; + +import com.bio.bio_backend.global.constants.AppConstants; +import com.bio.bio_backend.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Getter @Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Table( + name = AppConstants.TABLE_PREFIX + "common_code", + indexes = { + @Index(name = "idx_common_code_code", columnList = "code"), + @Index(name = "idx_common_code_group_code", columnList = "group_code"), + @Index(name = "idx_common_code_parent_code", columnList = "parent_code") + } +) +public class CommonCode extends BaseEntity { + + @Column(name = "code", nullable = false, length = 50, unique = true) + private String code; + + @Column(name = "name", nullable = false, length = 100) + private String name; + + @Column(name = "description", length = 500) + private String description; + + @Column(name = "group_code", nullable = false, length = 50) + private String groupCode; + + @Column(name = "parent_code", length = 50) + private String parentCode; + + @Column(name = "character_ref1", length = 100) + private String characterRef1; + + @Column(name = "character_ref2", length = 100) + private String characterRef2; + + @Column(name = "character_ref3", length = 100) + private String characterRef3; + + @Column(name = "character_ref4", length = 100) + private String characterRef4; + + @Column(name = "character_ref5", length = 100) + private String characterRef5; + + @Column(name = "sort_order", nullable = false) + @Builder.Default + private Integer sortOrder = 0; + + @Column(name = "use_flag", nullable = false) + @Builder.Default + private Boolean useFlag = true; + + // 관계 설정 + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "group_code", referencedColumnName = "code", insertable = false, updatable = false) + private CommonGroupCode commonGroupCode; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "parent_code", referencedColumnName = "code", insertable = false, updatable = false) + private CommonCode parentCodeEntity; +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonGroupCode.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonGroupCode.java new file mode 100644 index 0000000..22ae60c --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonGroupCode.java @@ -0,0 +1,53 @@ +package com.bio.bio_backend.domain.admin.CommonCode.entity; + +import com.bio.bio_backend.global.constants.AppConstants; +import com.bio.bio_backend.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Getter @Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Table( + name = AppConstants.TABLE_PREFIX + "common_group_code", + indexes = { + @Index(name = "idx_common_group_code_code", columnList = "code") + } +) +public class CommonGroupCode extends BaseEntity { + + @Column(name = "code", nullable = false, length = 50, unique = true) + private String code; + + @Column(name = "name", nullable = false, length = 100) + private String name; + + @Column(name = "character_ref1_title", length = 100) + private String characterRef1Title; + + @Column(name = "character_ref2_title", length = 100) + private String characterRef2Title; + + @Column(name = "character_ref3_title", length = 100) + private String characterRef3Title; + + @Column(name = "character_ref4_title", length = 100) + private String characterRef4Title; + + @Column(name = "character_ref5_title", length = 100) + private String characterRef5Title; + + @Column(name = "sort_order", nullable = false) + @Builder.Default + private Integer sortOrder = 0; + + @Column(name = "use_flag", nullable = false) + @Builder.Default + private Boolean useFlag = true; +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonCodeMapper.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonCodeMapper.java new file mode 100644 index 0000000..c4dd553 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonCodeMapper.java @@ -0,0 +1,68 @@ +package com.bio.bio_backend.domain.admin.CommonCode.mapper; + +import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonCodeDto; +import com.bio.bio_backend.domain.admin.CommonCode.dto.CreateCommonCodeRequestDto; +import com.bio.bio_backend.domain.admin.CommonCode.dto.CreateCommonCodeResponseDto; +import com.bio.bio_backend.domain.admin.CommonCode.dto.UpdateCommonCodeRequestDto; +import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonCode; +import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper(componentModel = "spring") +public interface CommonCodeMapper { + + CommonCodeMapper INSTANCE = Mappers.getMapper(CommonCodeMapper.class); + + /** + * CommonCode 엔티티를 CommonCodeDto로 변환 + */ + CommonCodeDto toCommonCodeDto(CommonCode entity); + + /** + * CommonCodeDto를 CommonCode 엔티티로 변환 + */ + @Mapping(target = "commonGroupCode", ignore = true) + @Mapping(target = "parentCodeEntity", ignore = true) + CommonCode toCommonCode(CommonCodeDto dto); + + /** + * CommonCode 엔티티 리스트를 CommonCodeDto 리스트로 변환 + */ + List toCommonCodeDtoList(List entities); + + /** + * CommonCodeDto 리스트를 CommonCode 엔티티 리스트로 변환 + */ + List toCommonCodeList(List dtos); + + /** + * CommonCodeDto를 CreateCommonCodeResponseDto로 변환 + */ + @Mapping(target = "createdAt", ignore = true) + CreateCommonCodeResponseDto toCreateCommonCodeResponseDto(CommonCodeDto dto); + + /** + * CreateCommonCodeRequestDto를 CommonCodeDto로 변환 + */ + @Mapping(target = "oid", ignore = true) + CommonCodeDto toCommonCodeDto(CreateCommonCodeRequestDto requestDto); + + /** + * UpdateCommonCodeRequestDto를 CommonCodeDto로 변환 + */ + @Mapping(target = "code", ignore = true) + @Mapping(target = "oid", ignore = true) + CommonCodeDto toCommonCodeDto(UpdateCommonCodeRequestDto requestDto); + + /** + * CommonCodeDto의 값으로 CommonCode 엔티티를 업데이트 (null 값은 무시) + */ + @IgnoreBaseEntityMapping + @Mapping(target = "commonGroupCode", ignore = true) + @Mapping(target = "parentCodeEntity", ignore = true) + void updateCommonCodeFromDto(CommonCodeDto commonCodeDto, @org.mapstruct.MappingTarget CommonCode commonCode); +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonGroupCodeMapper.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonGroupCodeMapper.java new file mode 100644 index 0000000..038df71 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonGroupCodeMapper.java @@ -0,0 +1,67 @@ +package com.bio.bio_backend.domain.admin.CommonCode.mapper; + +import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonGroupCodeDto; +import com.bio.bio_backend.domain.admin.CommonCode.dto.CreateCommonGroupCodeRequestDto; +import com.bio.bio_backend.domain.admin.CommonCode.dto.CreateCommonGroupCodeResponseDto; +import com.bio.bio_backend.domain.admin.CommonCode.dto.UpdateCommonGroupCodeRequestDto; +import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonGroupCode; +import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper(componentModel = "spring") +public interface CommonGroupCodeMapper { + + CommonGroupCodeMapper INSTANCE = Mappers.getMapper(CommonGroupCodeMapper.class); + + /** + * CommonGroupCode 엔티티를 CommonGroupCodeDto로 변환 + */ + CommonGroupCodeDto toCommonGroupCodeDto(CommonGroupCode entity); + + /** + * CommonGroupCodeDto를 CommonGroupCode 엔티티로 변환 + */ + CommonGroupCode toCommonGroupCode(CommonGroupCodeDto dto); + + /** + * CommonGroupCode 엔티티 리스트를 CommonGroupCodeDto 리스트로 변환 + */ + List toCommonGroupCodeDtoList(List entities); + + /** + * CommonGroupCodeDto 리스트를 CommonGroupCode 엔티티 리스트로 변환 + */ + List toCommonGroupCodeList(List dtos); + + /** + * CommonGroupCodeDto를 CreateCommonGroupCodeResponseDto로 변환 + */ + CreateCommonGroupCodeResponseDto toCreateCommonGroupCodeResponseDto(CommonGroupCodeDto dto); + + /** + * CreateCommonGroupCodeRequestDto를 CommonGroupCodeDto로 변환 + */ + @Mapping(target = "oid", ignore = true) + @Mapping(target = "createdAt", ignore = true) + @Mapping(target = "updatedAt", ignore = true) + CommonGroupCodeDto toCommonGroupCodeDto(CreateCommonGroupCodeRequestDto requestDto); + + /** + * UpdateCommonGroupCodeRequestDto를 CommonGroupCodeDto로 변환 + */ + @Mapping(target = "oid", ignore = true) + @Mapping(target = "code", ignore = true) + @Mapping(target = "createdAt", ignore = true) + @Mapping(target = "updatedAt", ignore = true) + CommonGroupCodeDto toCommonGroupCodeDto(UpdateCommonGroupCodeRequestDto requestDto); + + /** + * CommonGroupCodeDto의 값으로 CommonGroupCode 엔티티를 업데이트 (null 값은 무시) + */ + @IgnoreBaseEntityMapping + void updateCommonGroupCodeFromDto(CommonGroupCodeDto groupCodeDto, @org.mapstruct.MappingTarget CommonGroupCode groupCode); +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonCodeRepository.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonCodeRepository.java new file mode 100644 index 0000000..369153d --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonCodeRepository.java @@ -0,0 +1,32 @@ +package com.bio.bio_backend.domain.admin.CommonCode.repository; + +import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonCode; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; + +@Repository +public interface CommonCodeRepository extends JpaRepository { + + Optional findByCode(String code); + + List findByGroupCodeAndUseFlagOrderBySortOrderAsc(String groupCode, Boolean useFlag); + + List findByParentCodeAndUseFlagOrderBySortOrderAsc(String parentCode, Boolean useFlag); + + @Query("SELECT cc FROM CommonCode cc WHERE cc.groupCode = :groupCode AND cc.useFlag = :useFlag ORDER BY cc.sortOrder ASC") + List findActiveCodesByGroupCodeOrderBySortOrder(@Param("groupCode") String groupCode, @Param("useFlag") Boolean useFlag); + + @Query("SELECT cc FROM CommonCode cc WHERE cc.parentCode = :parentCode AND cc.useFlag = :useFlag ORDER BY cc.sortOrder ASC") + List findActiveCodesByParentCodeOrderBySortOrder(@Param("parentCode") String parentCode, @Param("useFlag") Boolean useFlag); + + boolean existsByCode(String code); + + boolean existsByGroupCode(String groupCode); + + boolean existsByParentCode(String parentCode); +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonGroupCodeRepository.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonGroupCodeRepository.java new file mode 100644 index 0000000..012c852 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonGroupCodeRepository.java @@ -0,0 +1,23 @@ +package com.bio.bio_backend.domain.admin.CommonCode.repository; + +import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonGroupCode; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; + +@Repository +public interface CommonGroupCodeRepository extends JpaRepository { + + Optional findByCode(String code); + + List findByUseFlagOrderBySortOrderAsc(Boolean useFlag); + + @Query("SELECT cgc FROM CommonGroupCode cgc WHERE cgc.useFlag = :useFlag ORDER BY cgc.sortOrder ASC") + List findActiveGroupCodesOrderBySortOrder(@Param("useFlag") Boolean useFlag); + + boolean existsByCode(String code); +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeService.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeService.java new file mode 100644 index 0000000..dd9ab88 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeService.java @@ -0,0 +1,28 @@ +package com.bio.bio_backend.domain.admin.CommonCode.service; + +import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonCodeDto; +import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonGroupCodeDto; + +import java.util.List; + +public interface CommonCodeService { + + // 그룹 코드 관련 + CommonGroupCodeDto createGroupCode(CommonGroupCodeDto groupCodeDto); + void updateGroupCode(String code, CommonGroupCodeDto groupCodeDto); + void deleteGroupCode(String code); + CommonGroupCodeDto getGroupCode(String code); + List getAllGroupCodes(); + List getActiveGroupCodes(); + + // 공통 코드 관련 + CommonCodeDto createCode(CommonCodeDto codeDto); + void updateCode(String code, CommonCodeDto codeDto); + void deleteCode(String code); + CommonCodeDto getCode(String code); + List getCodesByGroupCode(String groupCode); + List getActiveCodesByGroupCode(String groupCode); + List getCodesByParentCode(String parentCode); + List getActiveCodesByParentCode(String parentCode); + List getAllCodes(); +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeServiceImpl.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeServiceImpl.java new file mode 100644 index 0000000..8490ddc --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeServiceImpl.java @@ -0,0 +1,165 @@ +package com.bio.bio_backend.domain.admin.CommonCode.service; + +import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonCodeDto; +import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonGroupCodeDto; +import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonCode; +import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonGroupCode; +import com.bio.bio_backend.domain.admin.CommonCode.mapper.CommonCodeMapper; +import com.bio.bio_backend.domain.admin.CommonCode.mapper.CommonGroupCodeMapper; +import com.bio.bio_backend.domain.admin.CommonCode.repository.CommonCodeRepository; +import com.bio.bio_backend.domain.admin.CommonCode.repository.CommonGroupCodeRepository; +import com.bio.bio_backend.global.exception.ApiException; +import com.bio.bio_backend.global.constants.ApiResponseCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Slf4j +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class CommonCodeServiceImpl implements CommonCodeService { + + private final CommonGroupCodeRepository commonGroupCodeRepository; + private final CommonCodeRepository commonCodeRepository; + private final CommonCodeMapper commonCodeMapper; + private final CommonGroupCodeMapper commonGroupCodeMapper; + + // 그룹 코드 관련 메서드들 + @Override + @Transactional + public CommonGroupCodeDto createGroupCode(CommonGroupCodeDto groupCodeDto) { + if (commonGroupCodeRepository.existsByCode(groupCodeDto.getCode())) { + throw new ApiException(ApiResponseCode.USER_ID_DUPLICATE, "이미 존재하는 그룹 코드입니다: " + groupCodeDto.getCode()); + } + + CommonGroupCode groupCode = commonGroupCodeMapper.toCommonGroupCode(groupCodeDto); + CommonGroupCode savedGroupCode = commonGroupCodeRepository.save(groupCode); + return commonGroupCodeMapper.toCommonGroupCodeDto(savedGroupCode); + } + + @Override + @Transactional + public void updateGroupCode(String code, CommonGroupCodeDto groupCodeDto) { + CommonGroupCode existingGroupCode = commonGroupCodeRepository.findByCode(code) + .orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND, "그룹 코드를 찾을 수 없습니다: " + code)); + + commonGroupCodeMapper.updateCommonGroupCodeFromDto(groupCodeDto, existingGroupCode); + commonGroupCodeRepository.save(existingGroupCode); + } + + @Override + @Transactional + public void deleteGroupCode(String code) { + CommonGroupCode groupCode = commonGroupCodeRepository.findByCode(code) + .orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND, "그룹 코드를 찾을 수 없습니다: " + code)); + + // 하위 공통 코드가 있는지 확인 + if (commonCodeRepository.existsByGroupCode(code)) { + throw new ApiException(ApiResponseCode.COMMON_BAD_REQUEST, "하위 공통 코드가 존재하여 삭제할 수 없습니다: " + code); + } + + commonGroupCodeRepository.delete(groupCode); + } + + @Override + public CommonGroupCodeDto getGroupCode(String code) { + CommonGroupCode groupCode = commonGroupCodeRepository.findByCode(code) + .orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND, "그룹 코드를 찾을 수 없습니다: " + code)); + return commonGroupCodeMapper.toCommonGroupCodeDto(groupCode); + } + + @Override + public List getAllGroupCodes() { + List groupCodes = commonGroupCodeRepository.findAll(); + return commonGroupCodeMapper.toCommonGroupCodeDtoList(groupCodes); + } + + @Override + public List getActiveGroupCodes() { + List groupCodes = commonGroupCodeRepository.findByUseFlagOrderBySortOrderAsc(true); + return commonGroupCodeMapper.toCommonGroupCodeDtoList(groupCodes); + } + + // 공통 코드 관련 메서드들 + @Override + @Transactional + public CommonCodeDto createCode(CommonCodeDto commonCodeDto) { + if (commonCodeRepository.existsByCode(commonCodeDto.getCode())) { + throw new ApiException(ApiResponseCode.USER_ID_DUPLICATE, "이미 존재하는 공통 코드입니다: " + commonCodeDto.getCode()); + } + + // 그룹 코드 존재 여부 확인 + if (!commonGroupCodeRepository.existsByCode(commonCodeDto.getGroupCode())) { + throw new ApiException(ApiResponseCode.COMMON_BAD_REQUEST, "존재하지 않는 그룹 코드입니다: " + commonCodeDto.getGroupCode()); + } + + CommonCode commonCode = commonCodeMapper.toCommonCode(commonCodeDto); + CommonCode savedCommonCode = commonCodeRepository.save(commonCode); + return commonCodeMapper.toCommonCodeDto(savedCommonCode); + } + + @Override + @Transactional + public void updateCode(String code, CommonCodeDto commonCodeDto) { + CommonCode existingCommonCode = commonCodeRepository.findByCode(code) + .orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND, "공통 코드를 찾을 수 없습니다: " + code)); + + commonCodeMapper.updateCommonCodeFromDto(commonCodeDto, existingCommonCode); + commonCodeRepository.save(existingCommonCode); + } + + @Override + @Transactional + public void deleteCode(String code) { + CommonCode commonCode = commonCodeRepository.findByCode(code) + .orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND, "공통 코드를 찾을 수 없습니다: " + code)); + + // 하위 공통 코드가 있는지 확인 + if (commonCodeRepository.existsByParentCode(code)) { + throw new ApiException(ApiResponseCode.COMMON_BAD_REQUEST, "하위 공통 코드가 존재하여 삭제할 수 없습니다: " + code); + } + + commonCodeRepository.delete(commonCode); + } + + @Override + public CommonCodeDto getCode(String code) { + CommonCode commonCode = commonCodeRepository.findByCode(code) + .orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND, "공통 코드를 찾을 수 없습니다: " + code)); + return commonCodeMapper.toCommonCodeDto(commonCode); + } + + @Override + public List getCodesByGroupCode(String groupCode) { + List commonCodes = commonCodeRepository.findByGroupCodeAndUseFlagOrderBySortOrderAsc(groupCode, true); + return commonCodeMapper.toCommonCodeDtoList(commonCodes); + } + + @Override + public List getActiveCodesByGroupCode(String groupCode) { + List commonCodes = commonCodeRepository.findActiveCodesByGroupCodeOrderBySortOrder(groupCode, true); + return commonCodeMapper.toCommonCodeDtoList(commonCodes); + } + + @Override + public List getCodesByParentCode(String parentCode) { + List commonCodes = commonCodeRepository.findByParentCodeAndUseFlagOrderBySortOrderAsc(parentCode, true); + return commonCodeMapper.toCommonCodeDtoList(commonCodes); + } + + @Override + public List getActiveCodesByParentCode(String parentCode) { + List commonCodes = commonCodeRepository.findActiveCodesByParentCodeOrderBySortOrder(parentCode, true); + return commonCodeMapper.toCommonCodeDtoList(commonCodes); + } + + @Override + public List getAllCodes() { + List commonCodes = commonCodeRepository.findAll(); + return commonCodeMapper.toCommonCodeDtoList(commonCodes); + } +} From 6df8409e9686ea6c704128f687724eb943b31a39 Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Tue, 26 Aug 2025 15:57:09 +0900 Subject: [PATCH 04/11] =?UTF-8?q?[Spring=20Boot=20Actuator=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80]=20build.gradle=EC=97=90=20Spring=20Boot=20Actuator?= =?UTF-8?q?=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80=20=EB=B0=8F?= =?UTF-8?q?=20README.md=EC=97=90=20=EC=8B=9C=EC=8A=A4=ED=85=9C=20=EB=AA=A8?= =?UTF-8?q?=EB=8B=88=ED=84=B0=EB=A7=81=20=EA=B4=80=EB=A0=A8=20=EB=AC=B8?= =?UTF-8?q?=EC=84=9C=ED=99=94.=20application.properties=EC=97=90=20Actuato?= =?UTF-8?q?r=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 25 ++++++++++++---- build.gradle | 3 ++ src/main/resources/application.properties | 36 +++++++++++++++++++++-- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 54ab7a2..4e8c017 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,21 @@ public enum ApiResponseCode { - **URL**: `http://localhost:8080/service/swagger-ui.html` - **API Docs**: `http://localhost:8080/service/api-docs` +### 5. 시스템 모니터링 (Actuator) + +#### Health 체크 + +- **기본 Health**: `http://localhost:8080/service/actuator/health` +- **Readiness Probe**: `http://localhost:8080/service/actuator/health/readiness` +- **Liveness Probe**: `http://localhost:8080/service/actuator/health/liveness` + +#### 시스템 정보 + +- **애플리케이션 정보**: `http://localhost:8080/service/actuator/info` +- **환경 설정**: `http://localhost:8080/service/actuator/env` +- **설정 속성**: `http://localhost:8080/service/actuator/configprops` +- **메트릭**: `http://localhost:8080/service/actuator/metrics` + #### 주요 어노테이션 ```java @@ -182,7 +197,7 @@ public enum ApiResponseCode { - **SwaggerConfig.java**: OpenAPI 기본 정보 설정 - **application.properties**: Swagger UI 커스터마이징 -### 5. 트랜잭션 관리 +### 6. 트랜잭션 관리 #### 기본 설정 @@ -206,7 +221,7 @@ public class MemberServiceImpl { - **메서드별**: 데이터 수정 시에만 `@Transactional` 개별 적용 - **설정**: `spring.jpa.open-in-view=false` (성능 최적화) -### 6. 오류 등록 및 사용 +### 7. 오류 등록 및 사용 #### 오류 코드 등록 @@ -233,7 +248,7 @@ throw new ApiException(ApiResponseCode.USER_ID_DUPLICATE); - **예외 클래스**: `ApiException`으로 비즈니스 로직 예외 처리 - **자동 처리**: `GlobalExceptionHandler`가 일관된 응답 형태로 변환 -### 7. 로깅 시스템 +### 8. 로깅 시스템 #### @LogExecution 어노테이션 사용법 @@ -287,7 +302,7 @@ public OrderDto processOrder() { } **중요**: `@LogExecution` 어노테이션이 없으면 메서드 실행 로그가 출력되지 않습니다 -### 8. MapStruct +### 9. MapStruct **매퍼 인터페이스** @@ -311,7 +326,7 @@ Member entity = memberMapper.toEntity(dto); **자동 생성**: 컴파일 시 `MemberMapperImpl` 구현체 생성 -### 9. BaseEntity 상속 +### 10. BaseEntity 상속 **모든 엔티티는 `BaseEntity` 상속을 원칙으로 합니다.** diff --git a/build.gradle b/build.gradle index 303e893..0bdda77 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,9 @@ dependencies { // Validation implementation 'org.springframework.boot:spring-boot-starter-validation' + // Spring Boot Actuator + implementation 'org.springframework.boot:spring-boot-starter-actuator' + // MapStruct implementation 'org.mapstruct:mapstruct:1.5.5.Final' annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index cdd9eda..0edffa4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -114,7 +114,7 @@ springdoc.default-consumes-media-type=application/json # ======================================== # 보안 설정 - 허용할 경로 # ======================================== -security.permit-all-paths=/login,/members/register,/swagger-ui/**,/swagger-ui.html,/swagger-ui/index.html,/api-docs,/api-docs/**,/v3/api-docs,/v3/api-docs/**,/ws/** +security.permit-all-paths=/login,/members/register,/swagger-ui/**,/swagger-ui.html,/swagger-ui/index.html,/api-docs,/api-docs/**,/v3/api-docs,/v3/api-docs/**,/ws/**,/actuator/**,/actuator/health/**,/actuator/info # 파일 업로드 설정 # ======================================== @@ -124,4 +124,36 @@ spring.servlet.multipart.max-request-size=10MB spring.servlet.multipart.file-size-threshold=2KB # 파일 저장 경로 설정 -app.file.upload.path=./uploads/ \ No newline at end of file +app.file.upload.path=./uploads/ + +# ======================================== +# Spring Boot Actuator 설정 +# ======================================== +# Actuator 엔드포인트 활성화 +management.endpoints.web.exposure.include=health,info,metrics,env,configprops +management.endpoint.health.show-details=always +management.endpoint.health.show-components=always + +# Health 체크 상세 정보 표시 +management.health.db.enabled=true +management.health.diskspace.enabled=true +management.health.defaults.enabled=true + +# Actuator 기본 경로 설정 +management.endpoints.web.base-path=/actuator + +# Health 체크 타임아웃 설정 (밀리초) +management.health.defaults.timeout=10s + +# 커스텀 Health 체크 그룹 설정 +management.health.groups.readiness.include=db,diskSpace +management.health.groups.liveness.include=ping + +# ======================================== +# 애플리케이션 정보 설정 (Actuator info 엔드포인트용) +# ======================================== +info.app.name=Bio Backend Service +info.app.description=생물학 연구를 위한 백엔드 서비스 +info.app.version=@project.version@ +info.app.java.version=@java.version@ +info.app.spring-boot.version=@spring-boot.version@ \ No newline at end of file From 0c141eb397b231cf14a7432a3ffa2612cd48265c Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Tue, 26 Aug 2025 16:45:54 +0900 Subject: [PATCH 05/11] =?UTF-8?q?[=EA=B3=B5=ED=86=B5=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EA=B4=80=EB=A6=AC]=20=EA=B3=B5=ED=86=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EB=B0=8F=20=EA=B7=B8=EB=A3=B9=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20=EC=97=94=ED=8B=B0=ED=8B=B0,=20DTO,=20?= =?UTF-8?q?=EB=A7=A4=ED=8D=BC,=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=B0=8F?= =?UTF-8?q?=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EC=B6=94=EA=B0=80.?= =?UTF-8?q?=20=EA=B8=B0=EC=A1=B4=20=EB=A7=A4=ED=8D=BC=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EB=B0=8F=20=EC=99=B8=EB=9E=98=20=ED=82=A4=20=EC=A0=9C?= =?UTF-8?q?=EC=95=BD=20=EC=A1=B0=EA=B1=B4=20=EC=A0=9C=EA=B1=B0.=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=B2=A0=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=EC=8A=A4=ED=82=A4=EB=A7=88=20=EC=88=98=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddl/schema.sql | 10 --- .../CommonCode/mapper/CommonCodeMapper.java | 68 ------------------- .../mapper/CommonGroupCodeMapper.java | 67 ------------------ .../controller/CommonCodeController.java | 10 +-- .../dto/CommonCodeDto.java | 4 +- .../dto/CommonGroupCodeDto.java | 6 +- .../dto/CreateCommonCodeRequestDto.java | 2 +- .../dto/CreateCommonCodeResponseDto.java | 5 +- .../dto/CreateCommonGroupCodeRequestDto.java | 2 +- .../dto/CreateCommonGroupCodeResponseDto.java | 5 +- .../dto/UpdateCommonCodeRequestDto.java | 2 +- .../dto/UpdateCommonGroupCodeRequestDto.java | 2 +- .../entity/CommonCode.java | 14 ++-- .../entity/CommonGroupCode.java | 2 +- .../common_code/mapper/CommonCodeMapper.java | 57 ++++++++++++++++ .../mapper/CommonGroupCodeMapper.java | 55 +++++++++++++++ .../repository/CommonCodeRepository.java | 4 +- .../repository/CommonGroupCodeRepository.java | 4 +- .../service/CommonCodeService.java | 6 +- .../service/CommonCodeServiceImpl.java | 18 ++--- 20 files changed, 150 insertions(+), 193 deletions(-) delete mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonCodeMapper.java delete mode 100644 src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonGroupCodeMapper.java rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/controller/CommonCodeController.java (97%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/dto/CommonCodeDto.java (86%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/dto/CommonGroupCodeDto.java (76%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/dto/CreateCommonCodeRequestDto.java (96%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/dto/CreateCommonCodeResponseDto.java (82%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/dto/CreateCommonGroupCodeRequestDto.java (96%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/dto/CreateCommonGroupCodeResponseDto.java (81%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/dto/UpdateCommonCodeRequestDto.java (96%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/dto/UpdateCommonGroupCodeRequestDto.java (95%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/entity/CommonCode.java (84%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/entity/CommonGroupCode.java (95%) create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonCodeMapper.java create mode 100644 src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonGroupCodeMapper.java rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/repository/CommonCodeRepository.java (90%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/repository/CommonGroupCodeRepository.java (84%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/service/CommonCodeService.java (82%) rename src/main/java/com/bio/bio_backend/domain/admin/{CommonCode => common_code}/service/CommonCodeServiceImpl.java (91%) diff --git a/ddl/schema.sql b/ddl/schema.sql index 4c4c75d..13e2bb0 100644 --- a/ddl/schema.sql +++ b/ddl/schema.sql @@ -95,13 +95,3 @@ create index idx_member_user_id on st_member (user_id); - - alter table if exists st_common_code - add constraint FKdk30t67v5e2vo1k7gl5sk1jp9 - foreign key (group_code) - references st_common_group_code (code); - - alter table if exists st_common_code - add constraint FKgcyw9ydft76p31oox94ho93wf - foreign key (parent_code) - references st_common_code (code); diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonCodeMapper.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonCodeMapper.java deleted file mode 100644 index c4dd553..0000000 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonCodeMapper.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.bio.bio_backend.domain.admin.CommonCode.mapper; - -import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonCodeDto; -import com.bio.bio_backend.domain.admin.CommonCode.dto.CreateCommonCodeRequestDto; -import com.bio.bio_backend.domain.admin.CommonCode.dto.CreateCommonCodeResponseDto; -import com.bio.bio_backend.domain.admin.CommonCode.dto.UpdateCommonCodeRequestDto; -import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonCode; -import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper(componentModel = "spring") -public interface CommonCodeMapper { - - CommonCodeMapper INSTANCE = Mappers.getMapper(CommonCodeMapper.class); - - /** - * CommonCode 엔티티를 CommonCodeDto로 변환 - */ - CommonCodeDto toCommonCodeDto(CommonCode entity); - - /** - * CommonCodeDto를 CommonCode 엔티티로 변환 - */ - @Mapping(target = "commonGroupCode", ignore = true) - @Mapping(target = "parentCodeEntity", ignore = true) - CommonCode toCommonCode(CommonCodeDto dto); - - /** - * CommonCode 엔티티 리스트를 CommonCodeDto 리스트로 변환 - */ - List toCommonCodeDtoList(List entities); - - /** - * CommonCodeDto 리스트를 CommonCode 엔티티 리스트로 변환 - */ - List toCommonCodeList(List dtos); - - /** - * CommonCodeDto를 CreateCommonCodeResponseDto로 변환 - */ - @Mapping(target = "createdAt", ignore = true) - CreateCommonCodeResponseDto toCreateCommonCodeResponseDto(CommonCodeDto dto); - - /** - * CreateCommonCodeRequestDto를 CommonCodeDto로 변환 - */ - @Mapping(target = "oid", ignore = true) - CommonCodeDto toCommonCodeDto(CreateCommonCodeRequestDto requestDto); - - /** - * UpdateCommonCodeRequestDto를 CommonCodeDto로 변환 - */ - @Mapping(target = "code", ignore = true) - @Mapping(target = "oid", ignore = true) - CommonCodeDto toCommonCodeDto(UpdateCommonCodeRequestDto requestDto); - - /** - * CommonCodeDto의 값으로 CommonCode 엔티티를 업데이트 (null 값은 무시) - */ - @IgnoreBaseEntityMapping - @Mapping(target = "commonGroupCode", ignore = true) - @Mapping(target = "parentCodeEntity", ignore = true) - void updateCommonCodeFromDto(CommonCodeDto commonCodeDto, @org.mapstruct.MappingTarget CommonCode commonCode); -} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonGroupCodeMapper.java b/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonGroupCodeMapper.java deleted file mode 100644 index 038df71..0000000 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/mapper/CommonGroupCodeMapper.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.bio.bio_backend.domain.admin.CommonCode.mapper; - -import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonGroupCodeDto; -import com.bio.bio_backend.domain.admin.CommonCode.dto.CreateCommonGroupCodeRequestDto; -import com.bio.bio_backend.domain.admin.CommonCode.dto.CreateCommonGroupCodeResponseDto; -import com.bio.bio_backend.domain.admin.CommonCode.dto.UpdateCommonGroupCodeRequestDto; -import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonGroupCode; -import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper(componentModel = "spring") -public interface CommonGroupCodeMapper { - - CommonGroupCodeMapper INSTANCE = Mappers.getMapper(CommonGroupCodeMapper.class); - - /** - * CommonGroupCode 엔티티를 CommonGroupCodeDto로 변환 - */ - CommonGroupCodeDto toCommonGroupCodeDto(CommonGroupCode entity); - - /** - * CommonGroupCodeDto를 CommonGroupCode 엔티티로 변환 - */ - CommonGroupCode toCommonGroupCode(CommonGroupCodeDto dto); - - /** - * CommonGroupCode 엔티티 리스트를 CommonGroupCodeDto 리스트로 변환 - */ - List toCommonGroupCodeDtoList(List entities); - - /** - * CommonGroupCodeDto 리스트를 CommonGroupCode 엔티티 리스트로 변환 - */ - List toCommonGroupCodeList(List dtos); - - /** - * CommonGroupCodeDto를 CreateCommonGroupCodeResponseDto로 변환 - */ - CreateCommonGroupCodeResponseDto toCreateCommonGroupCodeResponseDto(CommonGroupCodeDto dto); - - /** - * CreateCommonGroupCodeRequestDto를 CommonGroupCodeDto로 변환 - */ - @Mapping(target = "oid", ignore = true) - @Mapping(target = "createdAt", ignore = true) - @Mapping(target = "updatedAt", ignore = true) - CommonGroupCodeDto toCommonGroupCodeDto(CreateCommonGroupCodeRequestDto requestDto); - - /** - * UpdateCommonGroupCodeRequestDto를 CommonGroupCodeDto로 변환 - */ - @Mapping(target = "oid", ignore = true) - @Mapping(target = "code", ignore = true) - @Mapping(target = "createdAt", ignore = true) - @Mapping(target = "updatedAt", ignore = true) - CommonGroupCodeDto toCommonGroupCodeDto(UpdateCommonGroupCodeRequestDto requestDto); - - /** - * CommonGroupCodeDto의 값으로 CommonGroupCode 엔티티를 업데이트 (null 값은 무시) - */ - @IgnoreBaseEntityMapping - void updateCommonGroupCodeFromDto(CommonGroupCodeDto groupCodeDto, @org.mapstruct.MappingTarget CommonGroupCode groupCode); -} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/controller/CommonCodeController.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/controller/CommonCodeController.java similarity index 97% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/controller/CommonCodeController.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/controller/CommonCodeController.java index b2fa801..dc62e7c 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/controller/CommonCodeController.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/controller/CommonCodeController.java @@ -1,9 +1,9 @@ -package com.bio.bio_backend.domain.admin.CommonCode.controller; +package com.bio.bio_backend.domain.admin.common_code.controller; -import com.bio.bio_backend.domain.admin.CommonCode.dto.*; -import com.bio.bio_backend.domain.admin.CommonCode.service.CommonCodeService; -import com.bio.bio_backend.domain.admin.CommonCode.mapper.CommonCodeMapper; -import com.bio.bio_backend.domain.admin.CommonCode.mapper.CommonGroupCodeMapper; +import com.bio.bio_backend.domain.admin.common_code.dto.*; +import com.bio.bio_backend.domain.admin.common_code.service.CommonCodeService; +import com.bio.bio_backend.domain.admin.common_code.mapper.CommonCodeMapper; +import com.bio.bio_backend.domain.admin.common_code.mapper.CommonGroupCodeMapper; import com.bio.bio_backend.global.dto.ApiResponseDto; import com.bio.bio_backend.global.constants.ApiResponseCode; import com.bio.bio_backend.global.annotation.LogExecution; diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonCodeDto.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CommonCodeDto.java similarity index 86% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonCodeDto.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CommonCodeDto.java index 4f72c12..902deee 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonCodeDto.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CommonCodeDto.java @@ -1,12 +1,10 @@ -package com.bio.bio_backend.domain.admin.CommonCode.dto; +package com.bio.bio_backend.domain.admin.common_code.dto; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; - @Data @Builder @NoArgsConstructor diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonGroupCodeDto.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CommonGroupCodeDto.java similarity index 76% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonGroupCodeDto.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CommonGroupCodeDto.java index 656bc21..7fbd919 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CommonGroupCodeDto.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CommonGroupCodeDto.java @@ -1,12 +1,10 @@ -package com.bio.bio_backend.domain.admin.CommonCode.dto; +package com.bio.bio_backend.domain.admin.common_code.dto; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; - @Data @Builder @NoArgsConstructor @@ -23,6 +21,4 @@ public class CommonGroupCodeDto { private String characterRef5Title; private Integer sortOrder; private Boolean useFlag; - private LocalDateTime createdAt; - private LocalDateTime updatedAt; } diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeRequestDto.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CreateCommonCodeRequestDto.java similarity index 96% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeRequestDto.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CreateCommonCodeRequestDto.java index e208395..4983197 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeRequestDto.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CreateCommonCodeRequestDto.java @@ -1,4 +1,4 @@ -package com.bio.bio_backend.domain.admin.CommonCode.dto; +package com.bio.bio_backend.domain.admin.common_code.dto; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeResponseDto.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CreateCommonCodeResponseDto.java similarity index 82% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeResponseDto.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CreateCommonCodeResponseDto.java index 4b9f3ff..e7bde3d 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonCodeResponseDto.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CreateCommonCodeResponseDto.java @@ -1,12 +1,10 @@ -package com.bio.bio_backend.domain.admin.CommonCode.dto; +package com.bio.bio_backend.domain.admin.common_code.dto; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; - @Data @Builder @NoArgsConstructor @@ -26,5 +24,4 @@ public class CreateCommonCodeResponseDto { private String characterRef5; private Integer sortOrder; private Boolean useFlag; - private LocalDateTime createdAt; } diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeRequestDto.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CreateCommonGroupCodeRequestDto.java similarity index 96% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeRequestDto.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CreateCommonGroupCodeRequestDto.java index 60df3d6..27126a1 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeRequestDto.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CreateCommonGroupCodeRequestDto.java @@ -1,4 +1,4 @@ -package com.bio.bio_backend.domain.admin.CommonCode.dto; +package com.bio.bio_backend.domain.admin.common_code.dto; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeResponseDto.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CreateCommonGroupCodeResponseDto.java similarity index 81% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeResponseDto.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CreateCommonGroupCodeResponseDto.java index fdab153..a764c87 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/CreateCommonGroupCodeResponseDto.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/CreateCommonGroupCodeResponseDto.java @@ -1,12 +1,10 @@ -package com.bio.bio_backend.domain.admin.CommonCode.dto; +package com.bio.bio_backend.domain.admin.common_code.dto; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; - @Data @Builder @NoArgsConstructor @@ -23,5 +21,4 @@ public class CreateCommonGroupCodeResponseDto { private String characterRef5Title; private Integer sortOrder; private Boolean useFlag; - private LocalDateTime createdAt; } diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonCodeRequestDto.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/UpdateCommonCodeRequestDto.java similarity index 96% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonCodeRequestDto.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/UpdateCommonCodeRequestDto.java index a4dd497..0d771c8 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonCodeRequestDto.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/UpdateCommonCodeRequestDto.java @@ -1,4 +1,4 @@ -package com.bio.bio_backend.domain.admin.CommonCode.dto; +package com.bio.bio_backend.domain.admin.common_code.dto; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonGroupCodeRequestDto.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/UpdateCommonGroupCodeRequestDto.java similarity index 95% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonGroupCodeRequestDto.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/UpdateCommonGroupCodeRequestDto.java index ec2d6ff..aafd626 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/dto/UpdateCommonGroupCodeRequestDto.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/dto/UpdateCommonGroupCodeRequestDto.java @@ -1,4 +1,4 @@ -package com.bio.bio_backend.domain.admin.CommonCode.dto; +package com.bio.bio_backend.domain.admin.common_code.dto; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonCode.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/entity/CommonCode.java similarity index 84% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonCode.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/entity/CommonCode.java index 4616d6e..8723cc6 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonCode.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/entity/CommonCode.java @@ -1,4 +1,4 @@ -package com.bio.bio_backend.domain.admin.CommonCode.entity; +package com.bio.bio_backend.domain.admin.common_code.entity; import com.bio.bio_backend.global.constants.AppConstants; import com.bio.bio_backend.global.entity.BaseEntity; @@ -64,10 +64,12 @@ public class CommonCode extends BaseEntity { // 관계 설정 @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "group_code", referencedColumnName = "code", insertable = false, updatable = false) + @JoinColumn( + name = "group_code", + referencedColumnName = "code", + insertable = false, + updatable = false, + foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT) + ) private CommonGroupCode commonGroupCode; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "parent_code", referencedColumnName = "code", insertable = false, updatable = false) - private CommonCode parentCodeEntity; } diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonGroupCode.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/entity/CommonGroupCode.java similarity index 95% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonGroupCode.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/entity/CommonGroupCode.java index 22ae60c..4cccf73 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/entity/CommonGroupCode.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/entity/CommonGroupCode.java @@ -1,4 +1,4 @@ -package com.bio.bio_backend.domain.admin.CommonCode.entity; +package com.bio.bio_backend.domain.admin.common_code.entity; import com.bio.bio_backend.global.constants.AppConstants; import com.bio.bio_backend.global.entity.BaseEntity; diff --git a/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonCodeMapper.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonCodeMapper.java new file mode 100644 index 0000000..373889b --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonCodeMapper.java @@ -0,0 +1,57 @@ +package com.bio.bio_backend.domain.admin.common_code.mapper; + +import com.bio.bio_backend.domain.admin.common_code.dto.CommonCodeDto; +import com.bio.bio_backend.domain.admin.common_code.dto.CreateCommonCodeRequestDto; +import com.bio.bio_backend.domain.admin.common_code.dto.CreateCommonCodeResponseDto; +import com.bio.bio_backend.domain.admin.common_code.dto.UpdateCommonCodeRequestDto; +import com.bio.bio_backend.domain.admin.common_code.entity.CommonCode; +import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +import java.util.List; + +@Mapper(componentModel = "spring") +public interface CommonCodeMapper { + + /** + * CommonCode 엔티티를 CommonCodeDto로 변환 + */ + CommonCodeDto toCommonCodeDto(CommonCode commonCode); + + /** + * CommonCodeDto를 CommonCode 엔티티로 변환 + */ + @Mapping(target = "commonGroupCode", ignore = true) + CommonCode toCommonCode(CommonCodeDto commonCodeDto); + + /** + * CommonCode 엔티티 리스트를 CommonCodeDto 리스트로 변환 + */ + List toCommonCodeDtoList(List commonCodes); + + /** + * CommonCodeDto를 CreateCommonCodeResponseDto로 변환 + */ + CreateCommonCodeResponseDto toCreateCommonCodeResponseDto(CommonCodeDto commonCodeDto); + + /** + * CreateCommonCodeRequestDto를 CommonCodeDto로 변환 + */ + @Mapping(target = "oid", ignore = true) + CommonCodeDto toCommonCodeDto(CreateCommonCodeRequestDto createRequestDto); + + /** + * UpdateCommonCodeRequestDto를 CommonCodeDto로 변환 + */ + @Mapping(target = "oid", ignore = true) + @Mapping(target = "code", ignore = true) + CommonCodeDto toCommonCodeDto(UpdateCommonCodeRequestDto updateRequestDto); + + /** + * CommonCodeDto의 값으로 CommonCode 엔티티를 업데이트 + */ + @IgnoreBaseEntityMapping + @Mapping(target = "commonGroupCode", ignore = true) + void updateCommonCodeFromDto(CommonCodeDto commonCodeDto, @org.mapstruct.MappingTarget CommonCode commonCode); +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonGroupCodeMapper.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonGroupCodeMapper.java new file mode 100644 index 0000000..e5f7f89 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonGroupCodeMapper.java @@ -0,0 +1,55 @@ +package com.bio.bio_backend.domain.admin.common_code.mapper; + +import com.bio.bio_backend.domain.admin.common_code.dto.CommonGroupCodeDto; +import com.bio.bio_backend.domain.admin.common_code.dto.CreateCommonGroupCodeRequestDto; +import com.bio.bio_backend.domain.admin.common_code.dto.CreateCommonGroupCodeResponseDto; +import com.bio.bio_backend.domain.admin.common_code.dto.UpdateCommonGroupCodeRequestDto; +import com.bio.bio_backend.domain.admin.common_code.entity.CommonGroupCode; +import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +import java.util.List; + +@Mapper(componentModel = "spring") +public interface CommonGroupCodeMapper { + + /** + * CommonGroupCode 엔티티를 CommonGroupCodeDto로 변환 + */ + CommonGroupCodeDto toCommonGroupCodeDto(CommonGroupCode commonGroupCode); + + /** + * CommonGroupCodeDto를 CommonGroupCode 엔티티로 변환 + */ + CommonGroupCode toCommonGroupCode(CommonGroupCodeDto commonGroupCodeDto); + + /** + * CommonGroupCode 엔티티 리스트를 CommonGroupCodeDto 리스트로 변환 + */ + List toCommonGroupCodeDtoList(List commonGroupCodes); + + /** + * CommonGroupCodeDto를 CreateCommonGroupCodeResponseDto로 변환 + */ + CreateCommonGroupCodeResponseDto toCreateCommonGroupCodeResponseDto(CommonGroupCodeDto commonGroupCodeDto); + + /** + * CreateCommonGroupCodeRequestDto를 CommonGroupCodeDto로 변환 + */ + @Mapping(target = "oid", ignore = true) + CommonGroupCodeDto toCommonGroupCodeDto(CreateCommonGroupCodeRequestDto createRequestDto); + + /** + * UpdateCommonGroupCodeRequestDto를 CommonGroupCodeDto로 변환 + */ + @Mapping(target = "oid", ignore = true) + @Mapping(target = "code", ignore = true) + CommonGroupCodeDto toCommonGroupCodeDto(UpdateCommonGroupCodeRequestDto updateRequestDto); + + /** + * CommonGroupCodeDto의 값으로 CommonGroupCode 엔티티를 업데이트 + */ + @IgnoreBaseEntityMapping + void updateCommonGroupCodeFromDto(CommonGroupCodeDto commonGroupCodeDto, @org.mapstruct.MappingTarget CommonGroupCode commonGroupCode); +} diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonCodeRepository.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/repository/CommonCodeRepository.java similarity index 90% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonCodeRepository.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/repository/CommonCodeRepository.java index 369153d..39445b4 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonCodeRepository.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/repository/CommonCodeRepository.java @@ -1,6 +1,6 @@ -package com.bio.bio_backend.domain.admin.CommonCode.repository; +package com.bio.bio_backend.domain.admin.common_code.repository; -import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonCode; +import com.bio.bio_backend.domain.admin.common_code.entity.CommonCode; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonGroupCodeRepository.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/repository/CommonGroupCodeRepository.java similarity index 84% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonGroupCodeRepository.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/repository/CommonGroupCodeRepository.java index 012c852..889d4a2 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/repository/CommonGroupCodeRepository.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/repository/CommonGroupCodeRepository.java @@ -1,6 +1,6 @@ -package com.bio.bio_backend.domain.admin.CommonCode.repository; +package com.bio.bio_backend.domain.admin.common_code.repository; -import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonGroupCode; +import com.bio.bio_backend.domain.admin.common_code.entity.CommonGroupCode; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeService.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/service/CommonCodeService.java similarity index 82% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeService.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/service/CommonCodeService.java index dd9ab88..d84e0ca 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeService.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/service/CommonCodeService.java @@ -1,7 +1,7 @@ -package com.bio.bio_backend.domain.admin.CommonCode.service; +package com.bio.bio_backend.domain.admin.common_code.service; -import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonCodeDto; -import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonGroupCodeDto; +import com.bio.bio_backend.domain.admin.common_code.dto.CommonCodeDto; +import com.bio.bio_backend.domain.admin.common_code.dto.CommonGroupCodeDto; import java.util.List; diff --git a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeServiceImpl.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/service/CommonCodeServiceImpl.java similarity index 91% rename from src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeServiceImpl.java rename to src/main/java/com/bio/bio_backend/domain/admin/common_code/service/CommonCodeServiceImpl.java index 8490ddc..832504c 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/CommonCode/service/CommonCodeServiceImpl.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/service/CommonCodeServiceImpl.java @@ -1,13 +1,13 @@ -package com.bio.bio_backend.domain.admin.CommonCode.service; +package com.bio.bio_backend.domain.admin.common_code.service; -import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonCodeDto; -import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonGroupCodeDto; -import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonCode; -import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonGroupCode; -import com.bio.bio_backend.domain.admin.CommonCode.mapper.CommonCodeMapper; -import com.bio.bio_backend.domain.admin.CommonCode.mapper.CommonGroupCodeMapper; -import com.bio.bio_backend.domain.admin.CommonCode.repository.CommonCodeRepository; -import com.bio.bio_backend.domain.admin.CommonCode.repository.CommonGroupCodeRepository; +import com.bio.bio_backend.domain.admin.common_code.dto.CommonCodeDto; +import com.bio.bio_backend.domain.admin.common_code.dto.CommonGroupCodeDto; +import com.bio.bio_backend.domain.admin.common_code.entity.CommonCode; +import com.bio.bio_backend.domain.admin.common_code.entity.CommonGroupCode; +import com.bio.bio_backend.domain.admin.common_code.mapper.CommonCodeMapper; +import com.bio.bio_backend.domain.admin.common_code.mapper.CommonGroupCodeMapper; +import com.bio.bio_backend.domain.admin.common_code.repository.CommonCodeRepository; +import com.bio.bio_backend.domain.admin.common_code.repository.CommonGroupCodeRepository; import com.bio.bio_backend.global.exception.ApiException; import com.bio.bio_backend.global.constants.ApiResponseCode; import lombok.RequiredArgsConstructor; From d29bc2dedda07e39537450e17c2e3d0f8788e6d4 Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Tue, 26 Aug 2025 18:45:01 +0900 Subject: [PATCH 06/11] =?UTF-8?q?[=ED=8C=8C=EC=9D=BC=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20=EA=B0=9C=EC=84=A0]=20FileUtils=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EC=97=90=EC=84=9C=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20import=20=EB=AC=B8=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?=EB=B0=8F=20=EC=BD=94=EB=93=9C=20=EC=A0=95=EB=A6=AC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/bio/bio_backend/global/utils/FileUtils.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/bio/bio_backend/global/utils/FileUtils.java b/src/main/java/com/bio/bio_backend/global/utils/FileUtils.java index ec06f9f..2829647 100644 --- a/src/main/java/com/bio/bio_backend/global/utils/FileUtils.java +++ b/src/main/java/com/bio/bio_backend/global/utils/FileUtils.java @@ -12,12 +12,10 @@ import java.util.UUID; import org.springframework.stereotype.Component; import lombok.RequiredArgsConstructor; import com.bio.bio_backend.domain.base.file.dto.FileUploadDto; -import com.bio.bio_backend.domain.base.file.dto.FileUploadResponseDto; import com.bio.bio_backend.domain.base.file.dto.MultipleFileUploadRequestDto; import com.bio.bio_backend.domain.base.file.dto.MultipleFileUploadResponseDto; import com.bio.bio_backend.domain.base.file.service.FileService; import java.util.List; -import com.bio.bio_backend.domain.base.file.dto.FileUploadRequestDto; /** * 파일 관련 유틸리티 클래스 From 3fc7debff42ac338fb22f906921c049bbc4686ce Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Tue, 26 Aug 2025 18:51:11 +0900 Subject: [PATCH 07/11] =?UTF-8?q?[ID=20=EC=83=9D=EC=84=B1=EA=B8=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95]=20CustomIdGenerator=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=9D=98=20generate=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20?= =?UTF-8?q?=EC=A3=BC=EC=84=9D=20=EC=A0=9C=EA=B1=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bio/bio_backend/global/utils/CustomIdGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/bio/bio_backend/global/utils/CustomIdGenerator.java b/src/main/java/com/bio/bio_backend/global/utils/CustomIdGenerator.java index acaa36d..7329dfd 100644 --- a/src/main/java/com/bio/bio_backend/global/utils/CustomIdGenerator.java +++ b/src/main/java/com/bio/bio_backend/global/utils/CustomIdGenerator.java @@ -11,6 +11,6 @@ public class CustomIdGenerator implements IdentifierGenerator { @Override public Serializable generate(SharedSessionContractImplementor session, Object object) { - return OidUtils.generateOid(); // 재사용 + return OidUtils.generateOid(); } } \ No newline at end of file From 9467a1edd01c9bd9b3403413d2f67fc67f23538f Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Tue, 26 Aug 2025 19:28:26 +0900 Subject: [PATCH 08/11] =?UTF-8?q?[=EC=97=94=ED=8B=B0=ED=8B=B0=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=EB=84=88=20=EC=B6=94=EA=B0=80]=20BaseEntityListener?= =?UTF-8?q?=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A5=BC=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=ED=95=98=EC=97=AC=20BaseEntity=EC=9D=98=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20=EB=B0=8F=20=EC=88=98=EC=A0=95=EC=9E=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20=EC=9E=90=EB=8F=99=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0.=20FileServiceImpl=20=EB=B0=8F=20MemberServiceImpl?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=88=98=EB=8F=99=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=ED=95=98=EB=8D=98=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/file/service/FileServiceImpl.java | 7 +-- .../member/service/MemberServiceImpl.java | 12 ++-- .../global/dto/ApiResponseDto.java | 6 +- .../bio_backend/global/entity/BaseEntity.java | 31 +--------- .../global/entity/BaseEntityListener.java | 61 +++++++++++++++++++ 5 files changed, 72 insertions(+), 45 deletions(-) create mode 100644 src/main/java/com/bio/bio_backend/global/entity/BaseEntityListener.java diff --git a/src/main/java/com/bio/bio_backend/domain/base/file/service/FileServiceImpl.java b/src/main/java/com/bio/bio_backend/domain/base/file/service/FileServiceImpl.java index 99b1af7..e2413fb 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/file/service/FileServiceImpl.java +++ b/src/main/java/com/bio/bio_backend/domain/base/file/service/FileServiceImpl.java @@ -144,7 +144,6 @@ public class FileServiceImpl implements FileService { // DB에 파일 정보 저장 File file = createFileEntity(originalFileName, storedFileName, targetLocation, multipartFile, description, groupOid); - file.setCreator(SecurityUtils.getCurrentUserOid(), SecurityUtils.getCurrentUserId()); return fileRepository.save(file); @@ -192,17 +191,13 @@ public class FileServiceImpl implements FileService { public void deleteFile(Long oid) { File file = fileRepository.findByOidAndUseFlagTrue(oid) .orElseThrow(() -> new ApiException(ApiResponseCode.FILE_NOT_FOUND)); - - Long currentUserOid = SecurityUtils.getCurrentUserOid(); + String currentUserId = SecurityUtils.getCurrentUserId(); // 현재 사용자가 파일 소유자인지 확인 if (currentUserId == null || !currentUserId.equals(file.getCreatedId())) { throw new ApiException(ApiResponseCode.COMMON_FORBIDDEN); } - // 수정자 정보 업데이트 - file.setUpdater(currentUserOid, currentUserId); - // 논리적 삭제: use_flag를 false로 변경 file.setUseFlag(false); fileRepository.save(file); diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/service/MemberServiceImpl.java b/src/main/java/com/bio/bio_backend/domain/base/member/service/MemberServiceImpl.java index 56d4e0e..55d1176 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/service/MemberServiceImpl.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/service/MemberServiceImpl.java @@ -8,6 +8,7 @@ import com.bio.bio_backend.domain.base.member.repository.MemberRepository; import com.bio.bio_backend.global.exception.ApiException; import com.bio.bio_backend.global.constants.ApiResponseCode; import com.bio.bio_backend.global.constants.AppConstants; + import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.userdetails.UserDetails; @@ -19,8 +20,6 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Map; -import static com.bio.bio_backend.global.utils.OidUtils.generateOid; - @Service @RequiredArgsConstructor @Slf4j @@ -53,10 +52,11 @@ public class MemberServiceImpl implements MemberService { .email(memberDto.getEmail()) .role(MemberRole.getDefault()) .build(); - - Long oid = generateOid(); - member.setOid(oid); - member.setCreator(AppConstants.ADMIN_OID, AppConstants.ADMIN_USER_ID); + + member.setCreatedOid(AppConstants.ADMIN_OID); + member.setCreatedId(AppConstants.ADMIN_USER_ID); + member.setUpdatedOid(AppConstants.ADMIN_OID); + member.setUpdatedId(AppConstants.ADMIN_USER_ID); Member savedMember = memberRepository.save(member); diff --git a/src/main/java/com/bio/bio_backend/global/dto/ApiResponseDto.java b/src/main/java/com/bio/bio_backend/global/dto/ApiResponseDto.java index d3538ee..105f20c 100644 --- a/src/main/java/com/bio/bio_backend/global/dto/ApiResponseDto.java +++ b/src/main/java/com/bio/bio_backend/global/dto/ApiResponseDto.java @@ -17,8 +17,6 @@ public class ApiResponseDto { private String description; private T data; - private static final int SUCCESS = 200; - private ApiResponseDto(int code, String message, String description, T data){ this.code = code; this.message = message; @@ -27,11 +25,11 @@ public class ApiResponseDto { } public static ApiResponseDto success(ApiResponseCode responseCode, T data) { - return new ApiResponseDto(SUCCESS, responseCode.name(), responseCode.getDescription(), data); + return new ApiResponseDto(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data); } public static ApiResponseDto success(ApiResponseCode responseCode) { - return new ApiResponseDto(SUCCESS, responseCode.name(), responseCode.getDescription(), null); + return new ApiResponseDto(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null); } public static ApiResponseDto fail(ApiResponseCode responseCode, T data) { diff --git a/src/main/java/com/bio/bio_backend/global/entity/BaseEntity.java b/src/main/java/com/bio/bio_backend/global/entity/BaseEntity.java index 402de9b..a4ae824 100644 --- a/src/main/java/com/bio/bio_backend/global/entity/BaseEntity.java +++ b/src/main/java/com/bio/bio_backend/global/entity/BaseEntity.java @@ -9,7 +9,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDateTime; -import static com.bio.bio_backend.global.utils.OidUtils.generateOid; + /** * 모든 엔티티가 상속받는 기본 엔티티 클래스 @@ -18,7 +18,7 @@ import static com.bio.bio_backend.global.utils.OidUtils.generateOid; @Getter @Setter @MappedSuperclass -@EntityListeners(AuditingEntityListener.class) +@EntityListeners({AuditingEntityListener.class, BaseEntityListener.class}) public abstract class BaseEntity { @Id @@ -45,31 +45,4 @@ public abstract class BaseEntity { @Column(name = "updated_id") private String updatedId; - @PrePersist - protected void onCreate() { - if(this.oid == null) this.oid = generateOid(); - if(this.createdOid != null && this.updatedOid == null) this.updatedOid = this.createdOid; - } - - /** - * 생성자 정보를 설정합니다. - * @param createdOid 생성자 OID - * @param createdId 생성자 ID - */ - public void setCreator(Long createdOid, String createdId) { - this.createdOid = createdOid; - this.createdId = createdId; - this.updatedOid = createdOid; - this.updatedId = createdId; - } - - /** - * 수정자 정보를 설정합니다. - * @param updatedOid 수정자 OID - * @param updatedId 수정자 ID - */ - public void setUpdater(Long updatedOid, String updatedId) { - this.updatedOid = updatedOid; - this.updatedId = updatedId; - } } diff --git a/src/main/java/com/bio/bio_backend/global/entity/BaseEntityListener.java b/src/main/java/com/bio/bio_backend/global/entity/BaseEntityListener.java new file mode 100644 index 0000000..91c7010 --- /dev/null +++ b/src/main/java/com/bio/bio_backend/global/entity/BaseEntityListener.java @@ -0,0 +1,61 @@ +package com.bio.bio_backend.global.entity; + +import com.bio.bio_backend.global.utils.SecurityUtils; +import jakarta.persistence.PrePersist; +import jakarta.persistence.PreUpdate; +import lombok.extern.slf4j.Slf4j; + +import static com.bio.bio_backend.global.utils.OidUtils.generateOid; + +/** + * BaseEntity의 createdOid와 updatedOid 필드를 자동으로 설정하는 엔티티 리스너 + */ +@Slf4j +public class BaseEntityListener { + + @PrePersist + public void prePersist(BaseEntity entity) { + if (entity.getOid() == null) { + entity.setOid(generateOid()); + } + + try { + String currentUserId = SecurityUtils.getCurrentUserId(); + Long currentUserOid = SecurityUtils.getCurrentUserOid(); + + if (currentUserOid != null) { + entity.setCreatedOid(currentUserOid); + entity.setUpdatedOid(currentUserOid); + } + + if (currentUserId != null) { + entity.setCreatedId(currentUserId); + entity.setUpdatedId(currentUserId); + } + } catch (SecurityException | IllegalStateException e) { + log.warn("등록자 정보 설정 실패: {}", e.getMessage()); + } catch (Exception e) { + log.error("등록자 정보 설정 오류: {}", e.getMessage(), e); + } + } + + @PreUpdate + public void preUpdate(BaseEntity entity) { + try { + String currentUserId = SecurityUtils.getCurrentUserId(); + Long currentUserOid = SecurityUtils.getCurrentUserOid(); + + if (currentUserOid != null) { + entity.setUpdatedOid(currentUserOid); + } + + if (currentUserId != null) { + entity.setUpdatedId(currentUserId); + } + } catch (SecurityException | IllegalStateException e) { + log.warn("수정자 정보 설정 실패: {}", e.getMessage()); + } catch (Exception e) { + log.error("수정자 정보 설정 오류: {}", e.getMessage(), e); + } + } +} From 5abe2932bc8a0559bf07e82584460bcebf21fb68 Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Wed, 27 Aug 2025 08:39:23 +0900 Subject: [PATCH 09/11] =?UTF-8?q?[API=20=EC=9D=91=EB=8B=B5=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0]=20ApiResponseDto=EC=97=90=20success=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80=EB=A1=9C=20=EC=84=B1=EA=B3=B5/?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=20=EC=97=AC=EB=B6=80=20=EB=AA=85=ED=99=95?= =?UTF-8?q?=ED=99=94.=20ApiResponseCode=EC=97=90=20COMMON=5FCODE=5FDUPLICA?= =?UTF-8?q?TE=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=88=98=EC=A0=95.=20CommonCodeS?= =?UTF-8?q?erviceImpl=EC=97=90=EC=84=9C=20=EC=A4=91=EB=B3=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 16 +++++++++++++++- .../service/CommonCodeServiceImpl.java | 3 ++- .../global/constants/ApiResponseCode.java | 3 ++- .../bio_backend/global/dto/ApiResponseDto.java | 15 ++++++++++----- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4e8c017..c79c734 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ src/main/java/com/bio/bio_backend/ ```java public class ApiResponseDto { + private boolean success; // 성공/실패 여부 (true/false) private int code; // HTTP 상태 코드 private String message; // 응답 메시지 (ApiResponseCode enum 값) private String description; // 응답 설명 @@ -56,12 +57,23 @@ public class ApiResponseDto { } ``` +#### 상수 정의 + +```java +public class ApiResponseDto { + private static final boolean SUCCESS = true; + private static final boolean FAIL = false; + // ... 필드들 +} +``` + #### 응답 예시 **성공 응답 (201 Created)** ```json { + "success": true, "code": 201, "message": "COMMON_SUCCESS_CREATED", "description": "Created successfully", @@ -77,6 +89,7 @@ public class ApiResponseDto { ```json { + "success": false, "code": 409, "message": "USER_ID_DUPLICATE", "description": "User ID already exists" @@ -131,7 +144,8 @@ public enum ApiResponseCode { - **모든 API 응답**: `ApiResponseDto`로 감싸서 반환 - **공용 응답 코드**: `COMMON_` 접두사로 시작하는 범용 코드 사용 -- **일관된 구조**: `code`, `message`, `description`, `data` 필드로 표준화 +- **일관된 구조**: `success`, `code`, `message`, `description`, `data` 필드로 표준화 +- **성공/실패 구분**: `success` 필드로 명확한 성공/실패 여부 전달 - **제네릭 활용**: ``를 통해 다양한 데이터 타입 지원 ### 3. JWT 인증 시스템 diff --git a/src/main/java/com/bio/bio_backend/domain/admin/common_code/service/CommonCodeServiceImpl.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/service/CommonCodeServiceImpl.java index 832504c..199b43c 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/common_code/service/CommonCodeServiceImpl.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/service/CommonCodeServiceImpl.java @@ -8,6 +8,7 @@ import com.bio.bio_backend.domain.admin.common_code.mapper.CommonCodeMapper; import com.bio.bio_backend.domain.admin.common_code.mapper.CommonGroupCodeMapper; import com.bio.bio_backend.domain.admin.common_code.repository.CommonCodeRepository; import com.bio.bio_backend.domain.admin.common_code.repository.CommonGroupCodeRepository; +import com.bio.bio_backend.global.constants.AppConstants; import com.bio.bio_backend.global.exception.ApiException; import com.bio.bio_backend.global.constants.ApiResponseCode; import lombok.RequiredArgsConstructor; @@ -33,7 +34,7 @@ public class CommonCodeServiceImpl implements CommonCodeService { @Transactional public CommonGroupCodeDto createGroupCode(CommonGroupCodeDto groupCodeDto) { if (commonGroupCodeRepository.existsByCode(groupCodeDto.getCode())) { - throw new ApiException(ApiResponseCode.USER_ID_DUPLICATE, "이미 존재하는 그룹 코드입니다: " + groupCodeDto.getCode()); + throw new ApiException(ApiResponseCode.COMMON_CODE_DUPLICATE); } CommonGroupCode groupCode = commonGroupCodeMapper.toCommonGroupCode(groupCodeDto); diff --git a/src/main/java/com/bio/bio_backend/global/constants/ApiResponseCode.java b/src/main/java/com/bio/bio_backend/global/constants/ApiResponseCode.java index 54f588d..fc5bb88 100644 --- a/src/main/java/com/bio/bio_backend/global/constants/ApiResponseCode.java +++ b/src/main/java/com/bio/bio_backend/global/constants/ApiResponseCode.java @@ -14,7 +14,7 @@ public enum ApiResponseCode { /*공통 Code*/ // 200 OK - COMMON_SUCCESS(HttpStatus.OK.value(), "요청 성공"), + COMMON_SUCCESS(HttpStatus.OK.value(), "요청을 성공하였습니다"), COMMON_SUCCESS_CREATED(HttpStatus.CREATED.value(), "성공적으로 생성되었습니다"), COMMON_SUCCESS_UPDATED(HttpStatus.OK.value(), "성공적으로 수정되었습니다"), COMMON_SUCCESS_DELETED(HttpStatus.OK.value(), "성공적으로 삭제되었습니다"), @@ -39,6 +39,7 @@ public enum ApiResponseCode { // 409 Conflict COMMON_CONFLICT(HttpStatus.CONFLICT.value(), "충돌이 발생했습니다"), + COMMON_CODE_DUPLICATE(HttpStatus.CONFLICT.value(), "동일한 코드가 존재합니다"), // 500 Internal Server Error COMMON_INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버에서 오류가 발생했습니다"), diff --git a/src/main/java/com/bio/bio_backend/global/dto/ApiResponseDto.java b/src/main/java/com/bio/bio_backend/global/dto/ApiResponseDto.java index 105f20c..8f1709f 100644 --- a/src/main/java/com/bio/bio_backend/global/dto/ApiResponseDto.java +++ b/src/main/java/com/bio/bio_backend/global/dto/ApiResponseDto.java @@ -12,12 +12,17 @@ import lombok.RequiredArgsConstructor; @JsonInclude(JsonInclude.Include.NON_NULL) public class ApiResponseDto { + private static final boolean SUCCESS = true; + private static final boolean FAIL = false; + + private boolean success; private int code; private String message; private String description; private T data; - private ApiResponseDto(int code, String message, String description, T data){ + private ApiResponseDto(boolean success, int code, String message, String description, T data){ + this.success = success; this.code = code; this.message = message; this.description = description; @@ -25,19 +30,19 @@ public class ApiResponseDto { } public static ApiResponseDto success(ApiResponseCode responseCode, T data) { - return new ApiResponseDto(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data); + return new ApiResponseDto(SUCCESS, responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data); } public static ApiResponseDto success(ApiResponseCode responseCode) { - return new ApiResponseDto(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null); + return new ApiResponseDto(SUCCESS, responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null); } public static ApiResponseDto fail(ApiResponseCode responseCode, T data) { - return new ApiResponseDto(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data); + return new ApiResponseDto(FAIL, responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data); } public static ApiResponseDto fail(ApiResponseCode responseCode) { - return new ApiResponseDto(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null); + return new ApiResponseDto(FAIL, responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null); } } From 75d827bf042fe5ec5cb6a65b346b85065467a7f6 Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Wed, 27 Aug 2025 08:40:00 +0900 Subject: [PATCH 10/11] =?UTF-8?q?README.md=EC=97=90=EC=84=9C=20ApiResponse?= =?UTF-8?q?Dto=EC=9D=98=20=EC=83=81=EC=88=98=20=EC=A0=95=EC=9D=98=20?= =?UTF-8?q?=EC=84=B9=EC=85=98=20=EC=A0=9C=EA=B1=B0=20=EB=B0=8F=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EC=98=88=EC=8B=9C=20=EC=84=B9=EC=85=98=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/README.md b/README.md index c79c734..aa95366 100644 --- a/README.md +++ b/README.md @@ -57,16 +57,6 @@ public class ApiResponseDto { } ``` -#### 상수 정의 - -```java -public class ApiResponseDto { - private static final boolean SUCCESS = true; - private static final boolean FAIL = false; - // ... 필드들 -} -``` - #### 응답 예시 **성공 응답 (201 Created)** From 8c5d7c6c3fa88639cb05885e3bd4a2c5024e21d4 Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Wed, 27 Aug 2025 09:42:10 +0900 Subject: [PATCH 11/11] =?UTF-8?q?[=EB=A7=A4=ED=8D=BC=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=EA=B0=9C=EC=84=A0]=20CommonCodeMapper,=20CommonGroupCodeMap?= =?UTF-8?q?per,=20MemberMapper=EC=97=90=EC=84=9C=20componentModel=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=EC=9D=84=20GlobalMapperConfig=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=ED=95=98=EC=97=AC=20=EB=A7=A4=ED=8D=BC=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=EC=9D=84=20=ED=86=B5=EC=9D=BC=ED=95=98?= =?UTF-8?q?=EA=B3=A0,=20GlobalMapperConfig=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EB=A5=BC=20=EC=83=88=EB=A1=9C=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EC=97=AC=20=EB=A7=A4=ED=95=91=20=EC=A0=84=EB=9E=B5=EC=9D=84=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common_code/mapper/CommonCodeMapper.java | 3 ++- .../mapper/CommonGroupCodeMapper.java | 3 ++- .../base/member/mapper/MemberMapper.java | 5 ++--- .../global/config/GlobalMapperConfig.java | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/bio/bio_backend/global/config/GlobalMapperConfig.java diff --git a/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonCodeMapper.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonCodeMapper.java index 373889b..801aff2 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonCodeMapper.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonCodeMapper.java @@ -6,12 +6,13 @@ import com.bio.bio_backend.domain.admin.common_code.dto.CreateCommonCodeResponse import com.bio.bio_backend.domain.admin.common_code.dto.UpdateCommonCodeRequestDto; import com.bio.bio_backend.domain.admin.common_code.entity.CommonCode; import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; +import com.bio.bio_backend.global.config.GlobalMapperConfig; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import java.util.List; -@Mapper(componentModel = "spring") +@Mapper(config = GlobalMapperConfig.class) public interface CommonCodeMapper { /** diff --git a/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonGroupCodeMapper.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonGroupCodeMapper.java index e5f7f89..9358fd4 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonGroupCodeMapper.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonGroupCodeMapper.java @@ -6,12 +6,13 @@ import com.bio.bio_backend.domain.admin.common_code.dto.CreateCommonGroupCodeRes import com.bio.bio_backend.domain.admin.common_code.dto.UpdateCommonGroupCodeRequestDto; import com.bio.bio_backend.domain.admin.common_code.entity.CommonGroupCode; import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; +import com.bio.bio_backend.global.config.GlobalMapperConfig; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import java.util.List; -@Mapper(componentModel = "spring") +@Mapper(config = GlobalMapperConfig.class) public interface CommonGroupCodeMapper { /** diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java b/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java index 73f3020..f5468d7 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java @@ -5,16 +5,15 @@ import com.bio.bio_backend.domain.base.member.dto.CreateMemberResponseDto; import com.bio.bio_backend.domain.base.member.dto.MemberDto; import com.bio.bio_backend.domain.base.member.entity.Member; import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; +import com.bio.bio_backend.global.config.GlobalMapperConfig; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; import java.util.List; -@Mapper(componentModel = "spring") +@Mapper(config = GlobalMapperConfig.class) public interface MemberMapper { - MemberMapper INSTANCE = Mappers.getMapper(MemberMapper.class); - /** * CreateMemberRequestDto를 MemberDto로 변환 * 기본값 설정: role = MemberRole.MEMBER, useFlag = true diff --git a/src/main/java/com/bio/bio_backend/global/config/GlobalMapperConfig.java b/src/main/java/com/bio/bio_backend/global/config/GlobalMapperConfig.java new file mode 100644 index 0000000..453a1da --- /dev/null +++ b/src/main/java/com/bio/bio_backend/global/config/GlobalMapperConfig.java @@ -0,0 +1,21 @@ +package com.bio.bio_backend.global.config; + +import org.mapstruct.*; + +@MapperConfig( + componentModel = "spring", + + // null 값은 매핑하지 않음 (부분 업데이트) + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, + + // NPE 방지용 null 체크 + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + + // 매핑 누락 시 컴파일 오류 + unmappedTargetPolicy = ReportingPolicy.ERROR, + + // 컬렉션 매핑 전략 + collectionMappingStrategy = CollectionMappingStrategy.ACCESSOR_ONLY +) +public interface GlobalMapperConfig { +}