Compare commits
122 Commits
2025081301
...
4b27f92bbf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b27f92bbf | ||
|
|
3bd836e5d8 | ||
|
|
630fa76786 | ||
| 1f0874cbc3 | |||
|
|
62daf51e57 | ||
| f5cd4aa873 | |||
|
|
6f707dcacd | ||
|
|
6d903dea2c | ||
|
|
be3ff66110 | ||
| 6ac9689693 | |||
| a1e3d41dcd | |||
| 6183ae350e | |||
| 0b996c5941 | |||
| 979547d2ce | |||
|
|
5c3b867888 | ||
| fc4770679c | |||
| 235ee5e29b | |||
| 4248a9a0a3 | |||
| 31d3402db8 | |||
| 3ddc8bc76e | |||
| 6dfc8279a8 | |||
| f6f6be31ea | |||
| 1b150af17d | |||
|
|
64d355507e | ||
|
|
50e0a007a3 | ||
| 29f8596f2b | |||
|
|
e62d7a3f1c | ||
|
|
4be71e53ec | ||
| 2b01629d12 | |||
| c640bef2b9 | |||
|
|
8687f009df | ||
|
|
fe0db8e701 | ||
| 4aa3375f57 | |||
| cd689211ec | |||
| f489fa3e51 | |||
| 26350425f5 | |||
| 0e6eb8a64d | |||
| 230ef022c5 | |||
| 4fac74b6a5 | |||
| 51fe350c6d | |||
| 470a5c8add | |||
| 3972a77c85 | |||
|
|
e2025621d6 | ||
| 24934e4a54 | |||
| 35cf8203ba | |||
| e1283792c3 | |||
| ff7d69f0b6 | |||
| 072f782652 | |||
| 47a59c39ca | |||
| 063bd7cc74 | |||
| ed4d386d53 | |||
| 64fd834c50 | |||
| 791d748cc1 | |||
| 2058dc9793 | |||
| 49b0815765 | |||
| 61b4b05682 | |||
| d7646d2c1c | |||
| 499fbc6afb | |||
| e78e98ad37 | |||
| f10b028e04 | |||
| cc2a34403d | |||
| e8a785a20d | |||
| afef6dfa80 | |||
| a0ffeb236e | |||
| fa1df19f64 | |||
| b0398fccee | |||
| 92be6caf80 | |||
| 31aed4bda0 | |||
| 438bfc3bc5 | |||
|
|
c07e7511d3 | ||
|
|
0617347395 | ||
| 8c5d7c6c3f | |||
| 75d827bf04 | |||
| 5abe2932bc | |||
|
|
9467a1edd0 | ||
|
|
3fc7debff4 | ||
|
|
d29bc2dedd | ||
| 0c141eb397 | |||
| 6df8409e96 | |||
| 88a508bd54 | |||
| d37986558e | |||
| eb2efbb0ea | |||
| 12aa3ae5a3 | |||
|
|
1bd499fe10 | ||
|
|
71bcbbb396 | ||
| f9472d1ccd | |||
| 56c8893f9e | |||
| 690724c77c | |||
| b5d6d213f3 | |||
| e7105215b8 | |||
| d8fe8399f7 | |||
| 8cee267f36 | |||
| b1218ab9bb | |||
| 7ae5871ae0 | |||
| 1ce08cb981 | |||
| a4c14c69f0 | |||
| 9e7929da6b | |||
| f9cd84f740 | |||
| 224006b6cb | |||
| dbac9f4702 | |||
| 2a1f211159 | |||
|
|
7430f1606f | ||
|
|
1153f164fc | ||
|
|
1850227d24 | ||
| 09e06cd10b | |||
| 6d1b89609b | |||
| baaa003d9a | |||
| d9d3be86a9 | |||
| 1b46b95ad5 | |||
| 8aa96d5fbd | |||
| 0dc32f2b39 | |||
| bfb87b8e33 | |||
|
|
33b33ef7a3 | ||
|
|
331d242ac3 | ||
| eff011f9fd | |||
|
|
0f1c5443ea | ||
| baab0352d5 | |||
| 21f121c490 | |||
| 77bc400888 | |||
| d0612b61e9 | |||
| d1c82848a2 | |||
|
|
45f3aa0f2c |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -39,8 +39,12 @@ jacoco.exec
|
|||||||
.classpath
|
.classpath
|
||||||
.settings/
|
.settings/
|
||||||
bin/
|
bin/
|
||||||
|
.metadata/
|
||||||
|
|
||||||
# Temporary files created by the OS
|
# Temporary files created by the OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
/nginx-1.28.0/logs/nginx.pid
|
/nginx-1.28.0/logs/nginx.pid
|
||||||
|
|
||||||
|
# Upload files
|
||||||
|
uploads/
|
||||||
|
|||||||
40
Dockerfile
40
Dockerfile
@@ -1,25 +1,19 @@
|
|||||||
# ./my-spring-app/Dockerfile
|
# --- build stage ---
|
||||||
|
FROM gradle:8.10.2-jdk17-alpine AS build
|
||||||
|
WORKDIR /workspace
|
||||||
|
COPY . .
|
||||||
|
# 테스트는 생략(필요시 제거)
|
||||||
|
RUN ./gradlew --no-daemon clean bootJar -x test
|
||||||
|
|
||||||
# 공식 OpenJDK 이미지를 기반으로 사용
|
# --- run stage ---
|
||||||
FROM openjdk:17-jdk-slim
|
FROM eclipse-temurin:17-jre-alpine
|
||||||
|
|
||||||
# 컨테이너의 작업 디렉터리를 설정
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
RUN apk add --no-cache tzdata && cp /usr/share/zoneinfo/Asia/Seoul /etc/localtime
|
||||||
# Gradle Wrapper와 빌드 파일을 컨테이너에 복사
|
# 로그 디렉터리 생성 및 권한 설정
|
||||||
COPY gradlew .
|
RUN mkdir -p /app/logs && chown -R 1000:1000 /app
|
||||||
COPY gradle ./gradle
|
RUN addgroup -S app && adduser -S app -G app -u 1000
|
||||||
|
USER app
|
||||||
# 프로젝트 설정 파일들을 복사
|
COPY --from=build /workspace/build/libs/*.jar /app/app.jar
|
||||||
COPY build.gradle .
|
EXPOSE 8080
|
||||||
COPY settings.gradle .
|
ENV JAVA_OPTS="-Xms256m -Xmx512m"
|
||||||
|
ENTRYPOINT ["sh","-c","java $JAVA_OPTS -jar /app/app.jar"]
|
||||||
# 의존성을 미리 다운로드
|
|
||||||
RUN ./gradlew dependencies
|
|
||||||
|
|
||||||
# 소스 파일들을 복사
|
|
||||||
COPY src ./src
|
|
||||||
|
|
||||||
# Gradle Wrapper를 사용하여 애플리케이션을 실행
|
|
||||||
# 이 명령어는 docker-compose.yml에서 개발용 명령으로 덮어쓸 것입니다.
|
|
||||||
CMD ["./gradlew", "bootRun"]
|
|
||||||
331
README.md
331
README.md
@@ -10,6 +10,28 @@
|
|||||||
- **Container**: Docker + Kubernetes
|
- **Container**: Docker + Kubernetes
|
||||||
- **API Documentation**: Swagger (SpringDoc OpenAPI)
|
- **API Documentation**: Swagger (SpringDoc OpenAPI)
|
||||||
|
|
||||||
|
## 개발 환경 설정
|
||||||
|
|
||||||
|
### Eclipse/STS 사용 시 필수 설정
|
||||||
|
|
||||||
|
**Annotation Processing 설정이 필요합니다.**
|
||||||
|
|
||||||
|
STS에서 프로젝트를 열었을 때 컴파일 오류가 발생하는 경우, 다음 설정을 확인하세요:
|
||||||
|
|
||||||
|
1. **프로젝트 우클릭** → **Properties** 선택
|
||||||
|
2. **Java Compiler** → **Annotation Processing** 선택
|
||||||
|
3. 다음 설정을 확인/적용:
|
||||||
|
- **Enable project specific settings** 체크
|
||||||
|
- **Enable annotation processing** 체크
|
||||||
|
- **Enable processing in editor** 체크 해제 (선택사항)
|
||||||
|
- **Generated source directory**: `build/generated/sources/annotationProcessor/java/main`
|
||||||
|
- **Generated test source directory**: `build/generated/sources/annotationProcessor/java/test`
|
||||||
|
|
||||||
|
**설정 이유:**
|
||||||
|
- MapStruct 매퍼 인터페이스의 구현체가 자동 생성됩니다
|
||||||
|
- QueryDSL Q클래스들이 자동 생성됩니다
|
||||||
|
- 이 설정이 없으면 컴파일 오류가 발생할 수 있습니다
|
||||||
|
|
||||||
## 개발 가이드
|
## 개발 가이드
|
||||||
|
|
||||||
### 1. 프로젝트 구조
|
### 1. 프로젝트 구조
|
||||||
@@ -17,28 +39,171 @@
|
|||||||
```
|
```
|
||||||
src/main/java/com/bio/bio_backend/
|
src/main/java/com/bio/bio_backend/
|
||||||
├── domain/ # 도메인별 패키지
|
├── domain/ # 도메인별 패키지
|
||||||
│ └── user/
|
│ └── base/ # 기본 도메인
|
||||||
│ └── member/ # 회원 도메인
|
│ └── member/ # 회원 도메인
|
||||||
│ ├── controller/ # API 엔드포인트
|
│ ├── controller/ # API 엔드포인트
|
||||||
│ ├── service/ # 비즈니스 로직
|
│ ├── service/ # 비즈니스 로직
|
||||||
│ ├── repository/ # 데이터 접근
|
│ ├── repository/ # 데이터 접근
|
||||||
│ ├── entity/ # JPA 엔티티
|
│ ├── entity/ # JPA 엔티티
|
||||||
│ └── dto/ # 데이터 전송 객체
|
│ ├── dto/ # 데이터 전송 객체
|
||||||
|
│ ├── mapper/ # MapStruct 매퍼
|
||||||
|
│ └── enums/ # 도메인 열거형
|
||||||
├── global/ # 공통 설정
|
├── global/ # 공통 설정
|
||||||
│ ├── config/ # 설정 클래스
|
│ ├── config/ # 설정 클래스
|
||||||
│ ├── security/ # 보안 설정
|
│ ├── security/ # 보안 설정
|
||||||
│ ├── exception/ # 예외 처리
|
│ ├── exception/ # 예외 처리
|
||||||
│ └── utils/ # 유틸리티
|
│ ├── aop/ # AOP 로깅
|
||||||
└── BioBackendApplication.java
|
│ ├── filter/ # HTTP 로깅 필터
|
||||||
|
│ ├── utils/ # 유틸리티
|
||||||
|
│ ├── constants/ # 상수 정의
|
||||||
|
│ ├── dto/ # 공통 DTO
|
||||||
|
│ ├── entity/ # 공통 엔티티
|
||||||
|
│ └── annotation/ # 커스텀 어노테이션
|
||||||
|
├── BioBackendApplication.java
|
||||||
|
└── ServletInitializer.java
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. API 문서화 (Swagger)
|
### 2. API 응답 표준화 (ApiResponseDto)
|
||||||
|
|
||||||
|
#### 응답 구조
|
||||||
|
|
||||||
|
모든 API 응답은 `ApiResponseDto<T>` 형태로 표준화되어 있습니다.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class ApiResponseDto<T> {
|
||||||
|
private boolean success; // 성공/실패 여부 (true/false)
|
||||||
|
private int code; // HTTP 상태 코드
|
||||||
|
private String message; // 응답 메시지 (ApiResponseCode enum 값)
|
||||||
|
private String description; // 응답 설명
|
||||||
|
private T data; // 실제 데이터 (제네릭 타입)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 응답 예시
|
||||||
|
|
||||||
|
**성공 응답 (201 Created)**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"code": 201,
|
||||||
|
"message": "COMMON_SUCCESS_CREATED",
|
||||||
|
"description": "성공적으로 생성되었습니다",
|
||||||
|
"data": {
|
||||||
|
"seq": 1,
|
||||||
|
"userId": "user123",
|
||||||
|
"name": "홍길동"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**실패 응답 (409 Conflict)**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"code": 409,
|
||||||
|
"message": "USER_ID_DUPLICATE",
|
||||||
|
"description": "이미 존재하는 사용자 ID입니다"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 사용 방법
|
||||||
|
|
||||||
|
**Controller에서 응답 생성**
|
||||||
|
|
||||||
|
```java
|
||||||
|
@PostMapping("/members")
|
||||||
|
public ResponseEntity<ApiResponseDto<CreateMemberResponseDto>> createMember(@RequestBody CreateMemberRequestDto requestDto) {
|
||||||
|
// ... 비즈니스 로직 ...
|
||||||
|
|
||||||
|
// 성공 응답
|
||||||
|
ApiResponseDto<CreateMemberResponseDto> apiResponse =
|
||||||
|
ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_CREATED, responseDto);
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).body(apiResponse);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**공용 응답 코드 사용**
|
||||||
|
|
||||||
|
```java
|
||||||
|
// ApiResponseCode.java
|
||||||
|
public enum ApiResponseCode {
|
||||||
|
// 공용 성공 코드
|
||||||
|
COMMON_SUCCESS(HttpStatus.OK.value(), "요청 성공"),
|
||||||
|
COMMON_SUCCESS_CREATED(HttpStatus.CREATED.value(), "성공적으로 생성되었습니다"),
|
||||||
|
COMMON_SUCCESS_UPDATED(HttpStatus.OK.value(), "성공적으로 수정되었습니다"),
|
||||||
|
COMMON_SUCCESS_DELETED(HttpStatus.OK.value(), "성공적으로 삭제되었습니다"),
|
||||||
|
COMMON_SUCCESS_RETRIEVED(HttpStatus.OK.value(), "성공적으로 조회되었습니다"),
|
||||||
|
|
||||||
|
// 공용 오류 코드
|
||||||
|
COMMON_BAD_REQUEST(HttpStatus.BAD_REQUEST.value(), "필수 요청 본문이 누락되었거나 오류가 발생했습니다"),
|
||||||
|
COMMON_UNAUTHORIZED(HttpStatus.UNAUTHORIZED.value(), "인증에 실패했습니다"),
|
||||||
|
COMMON_FORBIDDEN(HttpStatus.FORBIDDEN.value(), "접근이 거부되었습니다"),
|
||||||
|
COMMON_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "리소스를 찾을 수 없습니다"),
|
||||||
|
COMMON_CONFLICT(HttpStatus.CONFLICT.value(), "충돌이 발생했습니다"),
|
||||||
|
COMMON_INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버에서 오류가 발생했습니다"),
|
||||||
|
|
||||||
|
// 사용자 관련 코드
|
||||||
|
USER_ID_DUPLICATE(HttpStatus.CONFLICT.value(), "이미 존재하는 사용자 ID입니다"),
|
||||||
|
USER_NOT_FOUND(HttpStatus.UNAUTHORIZED.value(), "사용자를 찾을 수 없습니다. 인증에 실패했습니다"),
|
||||||
|
USER_PASSWORD_INVALID(HttpStatus.UNAUTHORIZED.value(), "비밀번호가 올바르지 않습니다")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 핵심 규칙
|
||||||
|
|
||||||
|
- **모든 API 응답**: `ApiResponseDto<T>`로 감싸서 반환
|
||||||
|
- **공용 응답 코드**: `COMMON_` 접두사로 시작하는 범용 코드 사용
|
||||||
|
- **일관된 구조**: `success`, `code`, `message`, `description`, `data` 필드로 표준화
|
||||||
|
- **성공/실패 구분**: `success` 필드로 명확한 성공/실패 여부 전달
|
||||||
|
- **제네릭 활용**: `<T>`를 통해 다양한 데이터 타입 지원
|
||||||
|
|
||||||
|
### 3. JWT 인증 시스템
|
||||||
|
|
||||||
|
#### 토큰 구성
|
||||||
|
|
||||||
|
- **Access Token** - 쿠키에 저장, 자동 갱신
|
||||||
|
- **Refresh Token** - 쿠키에 저장, 자동 갱신
|
||||||
|
|
||||||
|
#### 자동 토큰 갱신
|
||||||
|
|
||||||
|
**모든 API 요청마다 자동으로 처리됩니다:**
|
||||||
|
|
||||||
|
1. **Access Token 유효**: 정상 요청 처리
|
||||||
|
2. **Access Token 만료**: Refresh Token으로 자동 갱신
|
||||||
|
3. **새 Access Token 발급**: 응답 헤더에 자동 설정
|
||||||
|
4. **Refresh Token 갱신**: 보안을 위해 매번 새로운 토큰 발급
|
||||||
|
|
||||||
|
#### 주요 컴포넌트
|
||||||
|
|
||||||
|
- **`JwtTokenIssuanceFilter`**: 로그인 시 토큰 발급
|
||||||
|
- **`JwtTokenValidationFilter`**: 요청마다 토큰 검증 및 갱신
|
||||||
|
- **`JwtUtils`**: 토큰 생성, 검증, 갱신 유틸리티
|
||||||
|
|
||||||
|
### 4. API 문서화 (Swagger)
|
||||||
|
|
||||||
#### Swagger UI 접속
|
#### Swagger UI 접속
|
||||||
|
|
||||||
- **URL**: `http://localhost:8080/service/swagger-ui.html`
|
- **URL**: `http://localhost:8080/service/swagger-ui.html`
|
||||||
- **API Docs**: `http://localhost:8080/service/api-docs`
|
- **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
|
```java
|
||||||
@@ -46,7 +211,8 @@ src/main/java/com/bio/bio_backend/
|
|||||||
@Operation(summary = "회원 가입", description = "새로운 회원을 등록합니다.")
|
@Operation(summary = "회원 가입", description = "새로운 회원을 등록합니다.")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "201", description = "회원 가입 성공"),
|
@ApiResponse(responseCode = "201", description = "회원 가입 성공"),
|
||||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터")
|
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||||
|
@ApiResponse(responseCode = "409", description = "중복된 사용자 정보", content = @Content)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -55,7 +221,7 @@ src/main/java/com/bio/bio_backend/
|
|||||||
- **SwaggerConfig.java**: OpenAPI 기본 정보 설정
|
- **SwaggerConfig.java**: OpenAPI 기본 정보 설정
|
||||||
- **application.properties**: Swagger UI 커스터마이징
|
- **application.properties**: Swagger UI 커스터마이징
|
||||||
|
|
||||||
### 3. 트랜잭션 관리
|
### 6. 트랜잭션 관리
|
||||||
|
|
||||||
#### 기본 설정
|
#### 기본 설정
|
||||||
|
|
||||||
@@ -79,14 +245,14 @@ public class MemberServiceImpl {
|
|||||||
- **메서드별**: 데이터 수정 시에만 `@Transactional` 개별 적용
|
- **메서드별**: 데이터 수정 시에만 `@Transactional` 개별 적용
|
||||||
- **설정**: `spring.jpa.open-in-view=false` (성능 최적화)
|
- **설정**: `spring.jpa.open-in-view=false` (성능 최적화)
|
||||||
|
|
||||||
### 4. 오류 등록 및 사용
|
### 7. 오류 등록 및 사용
|
||||||
|
|
||||||
#### 오류 코드 등록
|
#### 오류 코드 등록
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// ApiResponseCode.java
|
// ApiResponseCode.java
|
||||||
public enum ApiResponseCode {
|
public enum ApiResponseCode {
|
||||||
USER_ID_DUPLICATE("400", "이미 존재하는 사용자 ID입니다."),
|
USER_ID_DUPLICATE(HttpStatus.CONFLICT.value(), "User ID already exists"),
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -105,3 +271,150 @@ throw new ApiException(ApiResponseCode.USER_ID_DUPLICATE);
|
|||||||
- **오류 코드**: `ApiResponseCode` enum에 모든 오류 정의
|
- **오류 코드**: `ApiResponseCode` enum에 모든 오류 정의
|
||||||
- **예외 클래스**: `ApiException`으로 비즈니스 로직 예외 처리
|
- **예외 클래스**: `ApiException`으로 비즈니스 로직 예외 처리
|
||||||
- **자동 처리**: `GlobalExceptionHandler`가 일관된 응답 형태로 변환
|
- **자동 처리**: `GlobalExceptionHandler`가 일관된 응답 형태로 변환
|
||||||
|
|
||||||
|
### 8. 로깅 시스템
|
||||||
|
|
||||||
|
#### @LogExecution 어노테이션 사용법
|
||||||
|
|
||||||
|
**메서드 실행 로깅을 위한 필수 어노테이션입니다.**
|
||||||
|
|
||||||
|
##### 기본 사용법
|
||||||
|
|
||||||
|
```java
|
||||||
|
@LogExecution("회원 등록")
|
||||||
|
@PostMapping("/register")
|
||||||
|
public ResponseEntity<ApiResponseDto<CreateMemberResponseDto>> createMember(@RequestBody CreateMemberRequestDto requestDto) {
|
||||||
|
// 메서드 실행 시 자동으로 로그 출력
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### 로그 출력 예시
|
||||||
|
|
||||||
|
**메서드 시작 시:**
|
||||||
|
|
||||||
|
```
|
||||||
|
[START] 회원 등록 | 호출경로: MemberController.createMember | 사용자: 고명빈(kmbin92)
|
||||||
|
```
|
||||||
|
|
||||||
|
**메서드 성공 시:**
|
||||||
|
|
||||||
|
```
|
||||||
|
[SUCCESS] 회원 등록 | 호출경로: MemberController.createMember | 사용자: 고명빈(kmbin92) | 시간: 200ms
|
||||||
|
```
|
||||||
|
|
||||||
|
**메서드 실패 시:**
|
||||||
|
|
||||||
|
```
|
||||||
|
[FAILED] 회원 등록 | 호출경로: MemberController.createMember | 사용자: 고명빈(kmbin92) | 시간: 23ms | 오류: 이미 존재하는 사용자 ID입니다
|
||||||
|
```
|
||||||
|
|
||||||
|
##### 어노테이션 설정
|
||||||
|
|
||||||
|
```java
|
||||||
|
@LogExecution("사용자 정보 조회")
|
||||||
|
public UserDto getUserInfo() { }
|
||||||
|
|
||||||
|
@LogExecution("주문 처리")
|
||||||
|
public OrderDto processOrder() { }
|
||||||
|
```
|
||||||
|
|
||||||
|
##### 로깅 시스템 구성
|
||||||
|
|
||||||
|
1. **MethodExecutionLoggingAspect**: 메서드 실행 로깅 (AOP)
|
||||||
|
2. **HttpLoggingFilter**: HTTP 요청/응답 로깅 (필터)
|
||||||
|
3. **logback-spring.xml**: 로그 파일 관리 및 설정
|
||||||
|
|
||||||
|
**중요**: `@LogExecution` 어노테이션이 없으면 메서드 실행 로그가 출력되지 않습니다
|
||||||
|
|
||||||
|
### 9. MapStruct
|
||||||
|
|
||||||
|
**매퍼 인터페이스**
|
||||||
|
|
||||||
|
```java
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface MemberMapper {
|
||||||
|
MemberDto toDto(Member member);
|
||||||
|
Member toEntity(MemberDto dto);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**사용 예시**
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Entity → DTO
|
||||||
|
MemberDto dto = memberMapper.toDto(member);
|
||||||
|
|
||||||
|
// DTO → Entity
|
||||||
|
Member entity = memberMapper.toEntity(dto);
|
||||||
|
```
|
||||||
|
|
||||||
|
**자동 생성**: 컴파일 시 `MemberMapperImpl` 구현체 생성
|
||||||
|
|
||||||
|
### 10. BaseEntity 상속
|
||||||
|
|
||||||
|
**모든 엔티티는 `BaseEntity` 상속을 원칙으로 합니다.**
|
||||||
|
|
||||||
|
#### 자동 생성 필드
|
||||||
|
|
||||||
|
- **OID**: `@PrePersist`에서 자동 생성 (고유 식별자)
|
||||||
|
- **생성일시**: `@CreatedDate`로 자동 설정
|
||||||
|
- **수정일시**: `@LastModifiedDate`로 자동 갱신
|
||||||
|
- **생성자/수정자 OID**: 사용자 추적용
|
||||||
|
|
||||||
|
#### 사용 예시
|
||||||
|
|
||||||
|
```java
|
||||||
|
@Entity
|
||||||
|
@Table(name = "st_members")
|
||||||
|
public class Member extends BaseEntity {
|
||||||
|
// OID, 생성일시, 수정일시 등이 자동으로 관리됨
|
||||||
|
private String userId;
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 11. DTO 네이밍 규칙
|
||||||
|
|
||||||
|
#### 기본 원칙
|
||||||
|
|
||||||
|
- **API 계층**: `Dto` 접미사 유지
|
||||||
|
- **Service 계층**: 역할에 따라 `Dto` 접미사 결정
|
||||||
|
|
||||||
|
#### 사용 예시
|
||||||
|
|
||||||
|
```java
|
||||||
|
// API 계층 (Dto 유지)
|
||||||
|
CreateMemberRequestDto, GetMemberResponseDto
|
||||||
|
|
||||||
|
// Service 계층 - 비즈니스 핵심 (Dto 유지)
|
||||||
|
MemberDto
|
||||||
|
|
||||||
|
// Service 계층 - 내부 전달 (Dto 제거)
|
||||||
|
MemberSearchCondition
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 핵심 규칙
|
||||||
|
|
||||||
|
- **API 노출**: `Dto` 유지
|
||||||
|
- **비즈니스 핵심**: `Dto` 유지
|
||||||
|
- **내부 전달**: `Dto` 제거
|
||||||
|
|
||||||
|
### 12. 데이터베이스 스키마
|
||||||
|
|
||||||
|
**데이터베이스 테이블 구조는 `ddl/schema_entity.sql`에 정의되어 있습니다.**
|
||||||
|
|
||||||
|
#### 스키마 파일
|
||||||
|
|
||||||
|
- **위치**: `ddl/schema_entity.sql`
|
||||||
|
- **내용**: 모든 엔티티 테이블의 CREATE TABLE DDL 스크립트
|
||||||
|
|
||||||
|
#### 초기화 스크립트
|
||||||
|
|
||||||
|
- **위치**: `src/main/resources/schema_initial.sql`
|
||||||
|
- **내용**: 서버 부팅 시 자동 실행되는 초기화 스크립트 (예: shedlock 테이블 등)
|
||||||
|
|
||||||
|
#### 사용 방법
|
||||||
|
|
||||||
|
- **자동 생성**: 애플리케이션 시작 시 `schema_entity.sql`로 엔티티 테이블 자동 생성
|
||||||
|
- **초기화**: 서버 부팅 시 `schema_initial.sql`로 시스템 테이블 자동 생성
|
||||||
|
- **설정**: `spring.jpa.hibernate.ddl-auto=none`으로 Hibernate 자동 스키마 생성 비활성화
|
||||||
|
|||||||
60
build.gradle
60
build.gradle
@@ -2,6 +2,7 @@ plugins {
|
|||||||
id 'java'
|
id 'java'
|
||||||
id 'org.springframework.boot' version '3.5.4'
|
id 'org.springframework.boot' version '3.5.4'
|
||||||
id 'io.spring.dependency-management' version '1.1.7'
|
id 'io.spring.dependency-management' version '1.1.7'
|
||||||
|
id 'com.google.cloud.tools.jib' version '3.4.0' // Jib 플러그인 추가
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'com.bio'
|
group = 'com.bio'
|
||||||
@@ -26,6 +27,7 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
|
|
||||||
// PostgreSQL JDBC
|
// PostgreSQL JDBC
|
||||||
runtimeOnly 'org.postgresql:postgresql'
|
runtimeOnly 'org.postgresql:postgresql'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
@@ -36,6 +38,9 @@ dependencies {
|
|||||||
// Validation
|
// Validation
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||||
|
|
||||||
|
// Spring Boot Actuator
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||||
|
|
||||||
// MapStruct
|
// MapStruct
|
||||||
implementation 'org.mapstruct:mapstruct:1.5.5.Final'
|
implementation 'org.mapstruct:mapstruct:1.5.5.Final'
|
||||||
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final'
|
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final'
|
||||||
@@ -43,8 +48,12 @@ dependencies {
|
|||||||
// MyBatis
|
// MyBatis
|
||||||
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3'
|
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3'
|
||||||
|
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||||
|
|
||||||
// jwt
|
// jwt
|
||||||
implementation 'io.jsonwebtoken:jjwt-api:0.12.5'
|
implementation 'io.jsonwebtoken:jjwt-api:0.12.5'
|
||||||
|
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.5'
|
||||||
|
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.5'
|
||||||
|
|
||||||
// lombok
|
// lombok
|
||||||
compileOnly 'org.projectlombok:lombok'
|
compileOnly 'org.projectlombok:lombok'
|
||||||
@@ -53,28 +62,69 @@ dependencies {
|
|||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||||
|
|
||||||
// querydsl
|
// QueryDSL
|
||||||
implementation 'io.github.openfeign.querydsl:querydsl-jpa:6.11'
|
implementation 'io.github.openfeign.querydsl:querydsl-jpa:6.11'
|
||||||
annotationProcessor 'io.github.openfeign.querydsl:querydsl-apt:6.11:jpa'
|
annotationProcessor 'io.github.openfeign.querydsl:querydsl-apt:6.11:jpa'
|
||||||
annotationProcessor 'jakarta.annotation:jakarta.annotation-api'
|
annotationProcessor 'jakarta.annotation:jakarta.annotation-api'
|
||||||
annotationProcessor 'jakarta.persistence:jakarta.persistence-api'
|
annotationProcessor 'jakarta.persistence:jakarta.persistence-api'
|
||||||
|
|
||||||
// p6spy
|
// p6spy
|
||||||
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'
|
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.12.0'
|
||||||
|
|
||||||
// SpringDoc OpenAPI (Swagger)
|
// SpringDoc OpenAPI (Swagger)
|
||||||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.9'
|
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.9'
|
||||||
|
|
||||||
|
// ShedLock for distributed scheduling
|
||||||
|
implementation 'net.javacrumbs.shedlock:shedlock-spring:5.10.2'
|
||||||
|
implementation 'net.javacrumbs.shedlock:shedlock-provider-jdbc-template:5.10.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named('test') {
|
tasks.named('test') {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|
||||||
// querydsl
|
// annotationProcessor(QueryDSL, MapStruct)
|
||||||
def generatedSrcDir = 'build/generated/sources/annotation-processor'
|
// * Annotation Processing 설정이 필요한경우 "build/generated/sources/annotationProcessor/java/main" 경로 등록
|
||||||
|
def generatedSrcDir = layout.buildDirectory.dir("generated/sources/annotationProcessor/java/main").get().asFile
|
||||||
|
|
||||||
clean {
|
clean {
|
||||||
delete file(generatedSrcDir)
|
delete file(generatedSrcDir)
|
||||||
}
|
}
|
||||||
tasks.withType(JavaCompile).configureEach {
|
tasks.withType(JavaCompile).configureEach {
|
||||||
options.generatedSourceOutputDirectory = file(generatedSrcDir)
|
options.annotationProcessorGeneratedSourcesDirectory = file(generatedSrcDir)
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
}
|
||||||
|
|
||||||
|
jib {
|
||||||
|
from {
|
||||||
|
image = 'demo.stam.kr/leejisun9/eclipse-temurin:17-jre' // 가벼운 JRE 베이스
|
||||||
|
// (선택) 인증서 추가/회사 CA 필요 시 extraDirectories 사용
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
image = 'demo.stam.kr/leejisun9/bio-backend'; //tags = ['1.0.0'] // 기본 대상 레지스트리
|
||||||
|
// tags는 skaffold가 자동 주입. 로컬 단독 빌드시 -Djib.to.tags=로 지정 가능
|
||||||
|
}
|
||||||
|
container {
|
||||||
|
// Spring Boot 컨테이너 런타임 옵션
|
||||||
|
ports = ['8080']
|
||||||
|
jvmFlags = [
|
||||||
|
'-XX:+UseContainerSupport',
|
||||||
|
'-Dserver.port=8080',
|
||||||
|
'-XX:InitialRAMPercentage=50.0',
|
||||||
|
'-XX:MaxRAMPercentage=75.0'
|
||||||
|
]
|
||||||
|
environment = [ 'SPRING_PROFILES_ACTIVE': 'dev' ]
|
||||||
|
// (선택) non-root 권장 (권한 필요한 리소스 없는 경우)
|
||||||
|
// user = '65532:65532'
|
||||||
|
// workingDirectory = '/app'
|
||||||
|
}
|
||||||
|
// (선택) 계층 최적화/추가 파일
|
||||||
|
// extraDirectories {
|
||||||
|
// paths {
|
||||||
|
// path {
|
||||||
|
// from = file('docker/extra') // 예: CA cert, 설정 템플릿
|
||||||
|
// into = '/opt/extra'
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
|
|
||||||
create table st_member (
|
|
||||||
use_flag boolean not null,
|
|
||||||
created_at timestamp(6) not null,
|
|
||||||
created_oid bigint,
|
|
||||||
last_login_at timestamp(6),
|
|
||||||
oid bigint not null,
|
|
||||||
updated_at timestamp(6) not null,
|
|
||||||
updated_oid bigint,
|
|
||||||
role varchar(40) not null check (role in ('MEMBER','ADMIN','USER','SYSTEM_ADMIN')),
|
|
||||||
password varchar(100) not null,
|
|
||||||
user_id varchar(100) not null,
|
|
||||||
refresh_token varchar(200),
|
|
||||||
primary key (oid)
|
|
||||||
);
|
|
||||||
|
|
||||||
create index idx_member_user_id
|
|
||||||
on st_member (user_id);
|
|
||||||
491
ddl/schema_entity.sql
Normal file
491
ddl/schema_entity.sql
Normal file
@@ -0,0 +1,491 @@
|
|||||||
|
|
||||||
|
create table st_auth_group (
|
||||||
|
created_at timestamp(6) not null,
|
||||||
|
created_oid bigint,
|
||||||
|
oid bigint not null,
|
||||||
|
updated_at timestamp(6) not null,
|
||||||
|
updated_oid bigint,
|
||||||
|
name varchar(100),
|
||||||
|
created_id varchar(255),
|
||||||
|
updated_id varchar(255),
|
||||||
|
primary key (oid)
|
||||||
|
);
|
||||||
|
|
||||||
|
comment on column st_auth_group.created_at is
|
||||||
|
'생성일시';
|
||||||
|
|
||||||
|
comment on column st_auth_group.created_oid is
|
||||||
|
'생성자 OID';
|
||||||
|
|
||||||
|
comment on column st_auth_group.oid is
|
||||||
|
'OID';
|
||||||
|
|
||||||
|
comment on column st_auth_group.updated_at is
|
||||||
|
'수정일시';
|
||||||
|
|
||||||
|
comment on column st_auth_group.updated_oid is
|
||||||
|
'수정자 OID';
|
||||||
|
|
||||||
|
comment on column st_auth_group.name is
|
||||||
|
'권한 그룹명';
|
||||||
|
|
||||||
|
comment on column st_auth_group.created_id is
|
||||||
|
'생성자 ID';
|
||||||
|
|
||||||
|
comment on column st_auth_group.updated_id is
|
||||||
|
'수정자 ID';
|
||||||
|
|
||||||
|
create table st_auth_group_resource (
|
||||||
|
auth_group_oid bigint,
|
||||||
|
created_at timestamp(6) not null,
|
||||||
|
created_oid bigint,
|
||||||
|
oid bigint not null,
|
||||||
|
resource_oid bigint,
|
||||||
|
updated_at timestamp(6) not null,
|
||||||
|
updated_oid bigint,
|
||||||
|
created_id varchar(255),
|
||||||
|
updated_id varchar(255),
|
||||||
|
primary key (oid)
|
||||||
|
);
|
||||||
|
|
||||||
|
comment on column st_auth_group_resource.auth_group_oid is
|
||||||
|
'권한 그룹 OID';
|
||||||
|
|
||||||
|
comment on column st_auth_group_resource.created_at is
|
||||||
|
'생성일시';
|
||||||
|
|
||||||
|
comment on column st_auth_group_resource.created_oid is
|
||||||
|
'생성자 OID';
|
||||||
|
|
||||||
|
comment on column st_auth_group_resource.oid is
|
||||||
|
'OID';
|
||||||
|
|
||||||
|
comment on column st_auth_group_resource.resource_oid is
|
||||||
|
'리소스 OID';
|
||||||
|
|
||||||
|
comment on column st_auth_group_resource.updated_at is
|
||||||
|
'수정일시';
|
||||||
|
|
||||||
|
comment on column st_auth_group_resource.updated_oid is
|
||||||
|
'수정자 OID';
|
||||||
|
|
||||||
|
comment on column st_auth_group_resource.created_id is
|
||||||
|
'생성자 ID';
|
||||||
|
|
||||||
|
comment on column st_auth_group_resource.updated_id is
|
||||||
|
'수정자 ID';
|
||||||
|
|
||||||
|
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)
|
||||||
|
);
|
||||||
|
|
||||||
|
comment on column st_common_code.sort_order is
|
||||||
|
'정렬 순번';
|
||||||
|
|
||||||
|
comment on column st_common_code.use_flag is
|
||||||
|
'사용 여부';
|
||||||
|
|
||||||
|
comment on column st_common_code.created_at is
|
||||||
|
'생성일시';
|
||||||
|
|
||||||
|
comment on column st_common_code.created_oid is
|
||||||
|
'생성자 OID';
|
||||||
|
|
||||||
|
comment on column st_common_code.oid is
|
||||||
|
'OID';
|
||||||
|
|
||||||
|
comment on column st_common_code.updated_at is
|
||||||
|
'수정일시';
|
||||||
|
|
||||||
|
comment on column st_common_code.updated_oid is
|
||||||
|
'수정자 OID';
|
||||||
|
|
||||||
|
comment on column st_common_code.code is
|
||||||
|
'코드';
|
||||||
|
|
||||||
|
comment on column st_common_code.group_code is
|
||||||
|
'그룹 코드';
|
||||||
|
|
||||||
|
comment on column st_common_code.parent_code is
|
||||||
|
'부모 코드';
|
||||||
|
|
||||||
|
comment on column st_common_code.character_ref1 is
|
||||||
|
'문자 참조1';
|
||||||
|
|
||||||
|
comment on column st_common_code.character_ref2 is
|
||||||
|
'문자 참조2';
|
||||||
|
|
||||||
|
comment on column st_common_code.character_ref3 is
|
||||||
|
'문자 참조3';
|
||||||
|
|
||||||
|
comment on column st_common_code.character_ref4 is
|
||||||
|
'문자 참조4';
|
||||||
|
|
||||||
|
comment on column st_common_code.character_ref5 is
|
||||||
|
'문자 참조5';
|
||||||
|
|
||||||
|
comment on column st_common_code.name is
|
||||||
|
'코드명';
|
||||||
|
|
||||||
|
comment on column st_common_code.description is
|
||||||
|
'설명';
|
||||||
|
|
||||||
|
comment on column st_common_code.created_id is
|
||||||
|
'생성자 ID';
|
||||||
|
|
||||||
|
comment on column st_common_code.updated_id is
|
||||||
|
'수정자 ID';
|
||||||
|
|
||||||
|
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)
|
||||||
|
);
|
||||||
|
|
||||||
|
comment on column st_common_group_code.sort_order is
|
||||||
|
'정렬 순번';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.use_flag is
|
||||||
|
'사용 여부';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.created_at is
|
||||||
|
'생성일시';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.created_oid is
|
||||||
|
'생성자 OID';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.oid is
|
||||||
|
'OID';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.updated_at is
|
||||||
|
'수정일시';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.updated_oid is
|
||||||
|
'수정자 OID';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.code is
|
||||||
|
'코드';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.character_ref1_title is
|
||||||
|
'문자 참조 타이틀1';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.character_ref2_title is
|
||||||
|
'문자 참조 타이틀2';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.character_ref3_title is
|
||||||
|
'문자 참조 타이틀3';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.character_ref4_title is
|
||||||
|
'문자 참조 타이틀4';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.character_ref5_title is
|
||||||
|
'문자 참조 타이틀5';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.name is
|
||||||
|
'코드명';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.created_id is
|
||||||
|
'생성자 ID';
|
||||||
|
|
||||||
|
comment on column st_common_group_code.updated_id is
|
||||||
|
'수정자 ID';
|
||||||
|
|
||||||
|
create table st_file (
|
||||||
|
use_flag boolean not null,
|
||||||
|
created_at timestamp(6) not null,
|
||||||
|
created_oid bigint,
|
||||||
|
file_size bigint not null,
|
||||||
|
group_oid bigint,
|
||||||
|
oid bigint not null,
|
||||||
|
updated_at timestamp(6) not null,
|
||||||
|
updated_oid bigint,
|
||||||
|
content_type varchar(255) not null,
|
||||||
|
created_id varchar(255),
|
||||||
|
description varchar(255),
|
||||||
|
file_path varchar(255) not null,
|
||||||
|
original_file_name varchar(255) not null,
|
||||||
|
stored_file_name varchar(255) not null,
|
||||||
|
updated_id varchar(255),
|
||||||
|
primary key (oid)
|
||||||
|
);
|
||||||
|
|
||||||
|
comment on column st_file.use_flag is
|
||||||
|
'사용 여부';
|
||||||
|
|
||||||
|
comment on column st_file.created_at is
|
||||||
|
'생성일시';
|
||||||
|
|
||||||
|
comment on column st_file.created_oid is
|
||||||
|
'생성자 OID';
|
||||||
|
|
||||||
|
comment on column st_file.file_size is
|
||||||
|
'파일 크기';
|
||||||
|
|
||||||
|
comment on column st_file.group_oid is
|
||||||
|
'그룹 OID';
|
||||||
|
|
||||||
|
comment on column st_file.oid is
|
||||||
|
'OID';
|
||||||
|
|
||||||
|
comment on column st_file.updated_at is
|
||||||
|
'수정일시';
|
||||||
|
|
||||||
|
comment on column st_file.updated_oid is
|
||||||
|
'수정자 OID';
|
||||||
|
|
||||||
|
comment on column st_file.content_type is
|
||||||
|
'콘텐츠 타입';
|
||||||
|
|
||||||
|
comment on column st_file.created_id is
|
||||||
|
'생성자 ID';
|
||||||
|
|
||||||
|
comment on column st_file.description is
|
||||||
|
'설명';
|
||||||
|
|
||||||
|
comment on column st_file.file_path is
|
||||||
|
'파일 경로';
|
||||||
|
|
||||||
|
comment on column st_file.original_file_name is
|
||||||
|
'원본 파일명';
|
||||||
|
|
||||||
|
comment on column st_file.stored_file_name is
|
||||||
|
'저장 파일명';
|
||||||
|
|
||||||
|
comment on column st_file.updated_id is
|
||||||
|
'수정자 ID';
|
||||||
|
|
||||||
|
create table st_member (
|
||||||
|
use_flag boolean not null,
|
||||||
|
created_at timestamp(6) not null,
|
||||||
|
created_oid bigint,
|
||||||
|
last_login_at timestamp(6),
|
||||||
|
oid bigint not null,
|
||||||
|
updated_at timestamp(6) not null,
|
||||||
|
updated_oid bigint,
|
||||||
|
login_ip varchar(45),
|
||||||
|
name varchar(100) not null,
|
||||||
|
password varchar(100) not null,
|
||||||
|
user_id varchar(100) not null,
|
||||||
|
refresh_token varchar(1024),
|
||||||
|
created_id varchar(255),
|
||||||
|
email varchar(255) not null,
|
||||||
|
updated_id varchar(255),
|
||||||
|
primary key (oid)
|
||||||
|
);
|
||||||
|
|
||||||
|
comment on column st_member.use_flag is
|
||||||
|
'사용 여부';
|
||||||
|
|
||||||
|
comment on column st_member.created_at is
|
||||||
|
'생성일시';
|
||||||
|
|
||||||
|
comment on column st_member.created_oid is
|
||||||
|
'생성자 OID';
|
||||||
|
|
||||||
|
comment on column st_member.last_login_at is
|
||||||
|
'마지막 로그인 일시';
|
||||||
|
|
||||||
|
comment on column st_member.oid is
|
||||||
|
'OID';
|
||||||
|
|
||||||
|
comment on column st_member.updated_at is
|
||||||
|
'수정일시';
|
||||||
|
|
||||||
|
comment on column st_member.updated_oid is
|
||||||
|
'수정자 OID';
|
||||||
|
|
||||||
|
comment on column st_member.login_ip is
|
||||||
|
'로그인 IP';
|
||||||
|
|
||||||
|
comment on column st_member.name is
|
||||||
|
'이름';
|
||||||
|
|
||||||
|
comment on column st_member.password is
|
||||||
|
'비밀번호';
|
||||||
|
|
||||||
|
comment on column st_member.user_id is
|
||||||
|
'사용자 ID';
|
||||||
|
|
||||||
|
comment on column st_member.refresh_token is
|
||||||
|
'리프레시 토큰';
|
||||||
|
|
||||||
|
comment on column st_member.created_id is
|
||||||
|
'생성자 ID';
|
||||||
|
|
||||||
|
comment on column st_member.email is
|
||||||
|
'이메일';
|
||||||
|
|
||||||
|
comment on column st_member.updated_id is
|
||||||
|
'수정자 ID';
|
||||||
|
|
||||||
|
create table st_member_auth_group (
|
||||||
|
auth_group_oid bigint,
|
||||||
|
created_at timestamp(6) not null,
|
||||||
|
created_oid bigint,
|
||||||
|
member_oid bigint,
|
||||||
|
oid bigint not null,
|
||||||
|
updated_at timestamp(6) not null,
|
||||||
|
updated_oid bigint,
|
||||||
|
created_id varchar(255),
|
||||||
|
updated_id varchar(255),
|
||||||
|
primary key (oid)
|
||||||
|
);
|
||||||
|
|
||||||
|
comment on column st_member_auth_group.auth_group_oid is
|
||||||
|
'권한 그룹 OID';
|
||||||
|
|
||||||
|
comment on column st_member_auth_group.created_at is
|
||||||
|
'생성일시';
|
||||||
|
|
||||||
|
comment on column st_member_auth_group.created_oid is
|
||||||
|
'생성자 OID';
|
||||||
|
|
||||||
|
comment on column st_member_auth_group.member_oid is
|
||||||
|
'사용자 OID';
|
||||||
|
|
||||||
|
comment on column st_member_auth_group.oid is
|
||||||
|
'OID';
|
||||||
|
|
||||||
|
comment on column st_member_auth_group.updated_at is
|
||||||
|
'수정일시';
|
||||||
|
|
||||||
|
comment on column st_member_auth_group.updated_oid is
|
||||||
|
'수정자 OID';
|
||||||
|
|
||||||
|
comment on column st_member_auth_group.created_id is
|
||||||
|
'생성자 ID';
|
||||||
|
|
||||||
|
comment on column st_member_auth_group.updated_id is
|
||||||
|
'수정자 ID';
|
||||||
|
|
||||||
|
create table st_resource (
|
||||||
|
menu_yn boolean,
|
||||||
|
sort_order integer,
|
||||||
|
created_at timestamp(6) not null,
|
||||||
|
created_oid bigint,
|
||||||
|
oid bigint not null,
|
||||||
|
parent_code bigint,
|
||||||
|
updated_at timestamp(6) not null,
|
||||||
|
updated_oid bigint,
|
||||||
|
type varchar(50),
|
||||||
|
code varchar(100),
|
||||||
|
name varchar(100),
|
||||||
|
path varchar(100),
|
||||||
|
created_id varchar(255),
|
||||||
|
description varchar(255),
|
||||||
|
updated_id varchar(255),
|
||||||
|
primary key (oid)
|
||||||
|
);
|
||||||
|
|
||||||
|
comment on column st_resource.menu_yn is
|
||||||
|
'메뉴여부';
|
||||||
|
|
||||||
|
comment on column st_resource.sort_order is
|
||||||
|
'정렬 순서';
|
||||||
|
|
||||||
|
comment on column st_resource.created_at is
|
||||||
|
'생성일시';
|
||||||
|
|
||||||
|
comment on column st_resource.created_oid is
|
||||||
|
'생성자 OID';
|
||||||
|
|
||||||
|
comment on column st_resource.oid is
|
||||||
|
'OID';
|
||||||
|
|
||||||
|
comment on column st_resource.parent_code is
|
||||||
|
'부모 코드';
|
||||||
|
|
||||||
|
comment on column st_resource.updated_at is
|
||||||
|
'수정일시';
|
||||||
|
|
||||||
|
comment on column st_resource.updated_oid is
|
||||||
|
'수정자 OID';
|
||||||
|
|
||||||
|
comment on column st_resource.type is
|
||||||
|
'리소스 유형(메뉴, 페이지, 컴포넌트)';
|
||||||
|
|
||||||
|
comment on column st_resource.code is
|
||||||
|
'코드';
|
||||||
|
|
||||||
|
comment on column st_resource.name is
|
||||||
|
'리소스명';
|
||||||
|
|
||||||
|
comment on column st_resource.path is
|
||||||
|
'주소';
|
||||||
|
|
||||||
|
comment on column st_resource.created_id is
|
||||||
|
'생성자 ID';
|
||||||
|
|
||||||
|
comment on column st_resource.description is
|
||||||
|
'설명';
|
||||||
|
|
||||||
|
comment on column st_resource.updated_id is
|
||||||
|
'수정자 ID';
|
||||||
|
|
||||||
|
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_auth_group_resource
|
||||||
|
add constraint FKqw6aih072qipjh1r88f0dbfd6
|
||||||
|
foreign key (auth_group_oid)
|
||||||
|
references st_auth_group;
|
||||||
|
|
||||||
|
alter table if exists st_auth_group_resource
|
||||||
|
add constraint FKrvq0ta0bwef2kt6ahklo7f3k4
|
||||||
|
foreign key (resource_oid)
|
||||||
|
references st_resource;
|
||||||
|
|
||||||
|
alter table if exists st_member_auth_group
|
||||||
|
add constraint FKob027cxsjfyvewjb8xp6hjkbm
|
||||||
|
foreign key (auth_group_oid)
|
||||||
|
references st_auth_group;
|
||||||
|
|
||||||
|
alter table if exists st_member_auth_group
|
||||||
|
add constraint FKqew1t81hap15dmn78p8xhunhj
|
||||||
|
foreign key (member_oid)
|
||||||
|
references st_member;
|
||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
distributionUrl=http\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
BIN
jpa-curd-0.0.1.vsix
Normal file
BIN
jpa-curd-0.0.1.vsix
Normal file
Binary file not shown.
BIN
jpa-curd.zip
Normal file
BIN
jpa-curd.zip
Normal file
Binary file not shown.
@@ -1,21 +0,0 @@
|
|||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: bio-backend-deployment
|
|
||||||
labels:
|
|
||||||
app: bio-backend
|
|
||||||
spec:
|
|
||||||
replicas: 1
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: bio-backend
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: bio-backend
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: bio-backend
|
|
||||||
image: backend-0.0.1:latest # 여기에 Skaffold가 빌드할 이미지 이름을 사용합니다.
|
|
||||||
ports:
|
|
||||||
- containerPort: 8081
|
|
||||||
@@ -4,6 +4,7 @@ events {
|
|||||||
}
|
}
|
||||||
|
|
||||||
http {
|
http {
|
||||||
|
|
||||||
include mime.types;
|
include mime.types;
|
||||||
default_type application/octet-stream;
|
default_type application/octet-stream;
|
||||||
sendfile on;
|
sendfile on;
|
||||||
@@ -30,6 +31,7 @@ http {
|
|||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection $connection_upgrade;
|
proxy_set_header Connection $connection_upgrade;
|
||||||
}
|
}
|
||||||
@@ -40,6 +42,7 @@ http {
|
|||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
# (선택) 업로드 크게 받을 때
|
# (선택) 업로드 크게 받을 때
|
||||||
|
|||||||
51
nginx-1.28.0/conf/nginx_docker_bak.conf
Normal file
51
nginx-1.28.0/conf/nginx_docker_bak.conf
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
|
||||||
|
include mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
sendfile on;
|
||||||
|
keepalive_timeout 65;
|
||||||
|
|
||||||
|
# (선택) 로그 위치
|
||||||
|
access_log /var/log/nginx/access.log;
|
||||||
|
error_log /var/log/nginx/error.log warn;
|
||||||
|
|
||||||
|
# 웹소켓용
|
||||||
|
map $http_upgrade $connection_upgrade {
|
||||||
|
default upgrade;
|
||||||
|
'' close;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
# Nuxt(개발서버 3000)
|
||||||
|
location / {
|
||||||
|
proxy_pass http://frontend:3000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection $connection_upgrade;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Spring Boot(8080)
|
||||||
|
location /service/ {
|
||||||
|
proxy_pass http://backend:8080;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
# (선택) 업로드 크게 받을 때
|
||||||
|
# client_max_body_size 50m;
|
||||||
|
}
|
||||||
|
}
|
||||||
0
nginx-1.28.0/logs/.gitkeep
Normal file
0
nginx-1.28.0/logs/.gitkeep
Normal file
0
nginx-1.28.0/temp/.gitkeep
Normal file
0
nginx-1.28.0/temp/.gitkeep
Normal file
@@ -1,12 +0,0 @@
|
|||||||
apiVersion: skaffold/v4beta13
|
|
||||||
kind: Config
|
|
||||||
metadata:
|
|
||||||
name: bio-backend
|
|
||||||
build:
|
|
||||||
artifacts:
|
|
||||||
- image: backend-0.0.1
|
|
||||||
docker:
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
manifests:
|
|
||||||
rawYaml:
|
|
||||||
- k8s/deployment.yaml
|
|
||||||
@@ -2,10 +2,12 @@ package com.bio.bio_backend;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableJpaAuditing
|
@EnableJpaAuditing
|
||||||
|
@EnableConfigurationProperties
|
||||||
public class BioBackendApplication {
|
public class BioBackendApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -0,0 +1,208 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.controller;
|
||||||
|
|
||||||
|
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;
|
||||||
|
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-codes")
|
||||||
|
@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),
|
||||||
|
@ApiResponse(responseCode = "409", description = "중복된 그룹 코드", content = @Content)
|
||||||
|
})
|
||||||
|
@PostMapping("/group")
|
||||||
|
public ResponseEntity<ApiResponseDto<CreateCommonGroupCodeResponseDto>> createGroupCode(@RequestBody @Valid CreateCommonGroupCodeRequestDto requestDto) {
|
||||||
|
CommonGroupCodeDto groupCodeDto = commonGroupCodeMapper.toCommonGroupCodeDto(requestDto);
|
||||||
|
CommonGroupCodeDto createdGroupCode = commonCodeService.createGroupCode(groupCodeDto);
|
||||||
|
CreateCommonGroupCodeResponseDto responseDto = commonGroupCodeMapper.toCreateCommonGroupCodeResponseDto(createdGroupCode);
|
||||||
|
ApiResponseDto<CreateCommonGroupCodeResponseDto> 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),
|
||||||
|
@ApiResponse(responseCode = "404", description = "그룹 코드를 찾을 수 없음", content = @Content)
|
||||||
|
})
|
||||||
|
@PutMapping("/group/{code}")
|
||||||
|
public ResponseEntity<ApiResponseDto<String>> 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),
|
||||||
|
@ApiResponse(responseCode = "404", description = "그룹 코드를 찾을 수 없음", content = @Content)
|
||||||
|
})
|
||||||
|
@DeleteMapping("/group/{code}")
|
||||||
|
public ResponseEntity<ApiResponseDto<Void>> 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)
|
||||||
|
})
|
||||||
|
@GetMapping("/group/{code}")
|
||||||
|
public ResponseEntity<ApiResponseDto<CommonGroupCodeDto>> 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<ApiResponseDto<List<CommonGroupCodeDto>>> getAllGroupCodes() {
|
||||||
|
List<CommonGroupCodeDto> 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<ApiResponseDto<List<CommonGroupCodeDto>>> getActiveGroupCodes() {
|
||||||
|
List<CommonGroupCodeDto> 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),
|
||||||
|
@ApiResponse(responseCode = "409", description = "중복된 공통 코드", content = @Content)
|
||||||
|
})
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<ApiResponseDto<CreateCommonCodeResponseDto>> createCode(@RequestBody @Valid CreateCommonCodeRequestDto requestDto) {
|
||||||
|
CommonCodeDto commonCodeDto = commonCodeMapper.toCommonCodeDto(requestDto);
|
||||||
|
CommonCodeDto createdCommonCode = commonCodeService.createCode(commonCodeDto);
|
||||||
|
CreateCommonCodeResponseDto responseDto = commonCodeMapper.toCreateCommonCodeResponseDto(createdCommonCode);
|
||||||
|
ApiResponseDto<CreateCommonCodeResponseDto> 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),
|
||||||
|
@ApiResponse(responseCode = "404", description = "공통 코드를 찾을 수 없음", content = @Content)
|
||||||
|
})
|
||||||
|
@PutMapping("/{code}")
|
||||||
|
public ResponseEntity<ApiResponseDto<String>> 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),
|
||||||
|
@ApiResponse(responseCode = "404", description = "공통 코드를 찾을 수 없음", content = @Content)
|
||||||
|
})
|
||||||
|
@DeleteMapping("/{code}")
|
||||||
|
public ResponseEntity<ApiResponseDto<Void>> 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)
|
||||||
|
})
|
||||||
|
@GetMapping("/{code}")
|
||||||
|
public ResponseEntity<ApiResponseDto<GetCommonCodeResponseDto>> getCode(@PathVariable String code) {
|
||||||
|
GetCommonCodeResponseDto commonCode = commonCodeService.getCodeWithJoinInfo(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<ApiResponseDto<List<CommonCodeDto>>> getCodesByGroupCode(@PathVariable String groupCode) {
|
||||||
|
List<CommonCodeDto> 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<ApiResponseDto<List<CommonCodeDto>>> getCodesByParentCode(@PathVariable String parentCode) {
|
||||||
|
List<CommonCodeDto> 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<ApiResponseDto<List<CommonCodeDto>>> getAllCodes() {
|
||||||
|
List<CommonCodeDto> commonCodes = commonCodeService.getAllCodes();
|
||||||
|
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, commonCodes));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.dto;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 공통 코드 조회용 Response DTO
|
||||||
|
* CommonGroupCode의 name과 Member의 name을 join을 통해 함께 조회
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@SqlResultSetMapping(
|
||||||
|
name = "GetCommonCodeResponseDtoMapping",
|
||||||
|
classes = @ConstructorResult(
|
||||||
|
targetClass = GetCommonCodeResponseDto.class,
|
||||||
|
columns = {
|
||||||
|
@ColumnResult(name = "code", type = String.class),
|
||||||
|
@ColumnResult(name = "name", type = String.class),
|
||||||
|
@ColumnResult(name = "description", type = String.class),
|
||||||
|
@ColumnResult(name = "group_code", type = String.class),
|
||||||
|
@ColumnResult(name = "parent_code", type = String.class),
|
||||||
|
@ColumnResult(name = "character_ref1", type = String.class),
|
||||||
|
@ColumnResult(name = "character_ref2", type = String.class),
|
||||||
|
@ColumnResult(name = "character_ref3", type = String.class),
|
||||||
|
@ColumnResult(name = "character_ref4", type = String.class),
|
||||||
|
@ColumnResult(name = "character_ref5", type = String.class),
|
||||||
|
@ColumnResult(name = "sort_order", type = Integer.class),
|
||||||
|
@ColumnResult(name = "use_flag", type = Boolean.class),
|
||||||
|
@ColumnResult(name = "created_at", type = LocalDateTime.class),
|
||||||
|
@ColumnResult(name = "updated_at", type = LocalDateTime.class),
|
||||||
|
@ColumnResult(name = "group_code_name", type = String.class),
|
||||||
|
@ColumnResult(name = "created_by_name", type = String.class),
|
||||||
|
@ColumnResult(name = "updated_by_name", type = String.class)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
public class GetCommonCodeResponseDto {
|
||||||
|
|
||||||
|
// CommonCode 기본 정보
|
||||||
|
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;
|
||||||
|
|
||||||
|
// BaseEntity 정보
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
// Join을 통해 가져올 정보
|
||||||
|
private String groupCodeName; // CommonGroupCode의 name
|
||||||
|
private String createdByName; // 생성자 Member의 name
|
||||||
|
private String updatedByName; // 수정자 Member의 name
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
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;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
|
|
||||||
|
@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)
|
||||||
|
@Comment("코드")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@Column(name = "name", nullable = false, length = 100)
|
||||||
|
@Comment("코드명")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "description", length = 500)
|
||||||
|
@Comment("설명")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "group_code", nullable = false, length = 50)
|
||||||
|
@Comment("그룹 코드")
|
||||||
|
private String groupCode;
|
||||||
|
|
||||||
|
@Column(name = "parent_code", length = 50)
|
||||||
|
@Comment("부모 코드")
|
||||||
|
private String parentCode;
|
||||||
|
|
||||||
|
@Column(name = "character_ref1", length = 100)
|
||||||
|
@Comment("문자 참조1")
|
||||||
|
private String characterRef1;
|
||||||
|
|
||||||
|
@Column(name = "character_ref2", length = 100)
|
||||||
|
@Comment("문자 참조2")
|
||||||
|
private String characterRef2;
|
||||||
|
|
||||||
|
@Column(name = "character_ref3", length = 100)
|
||||||
|
@Comment("문자 참조3")
|
||||||
|
private String characterRef3;
|
||||||
|
|
||||||
|
@Column(name = "character_ref4", length = 100)
|
||||||
|
@Comment("문자 참조4")
|
||||||
|
private String characterRef4;
|
||||||
|
|
||||||
|
@Column(name = "character_ref5", length = 100)
|
||||||
|
@Comment("문자 참조5")
|
||||||
|
private String characterRef5;
|
||||||
|
|
||||||
|
@Column(name = "sort_order", nullable = false)
|
||||||
|
@Comment("정렬 순번")
|
||||||
|
@Builder.Default
|
||||||
|
private Integer sortOrder = 0;
|
||||||
|
|
||||||
|
@Column(name = "use_flag", nullable = false)
|
||||||
|
@Comment("사용 여부")
|
||||||
|
@Builder.Default
|
||||||
|
private Boolean useFlag = true;
|
||||||
|
|
||||||
|
// 관계 설정
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(
|
||||||
|
name = "group_code",
|
||||||
|
referencedColumnName = "code",
|
||||||
|
insertable = false,
|
||||||
|
updatable = false,
|
||||||
|
foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT)
|
||||||
|
)
|
||||||
|
private CommonGroupCode commonGroupCode;
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
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;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
|
|
||||||
|
@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)
|
||||||
|
@Comment("코드")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@Column(name = "name", nullable = false, length = 100)
|
||||||
|
@Comment("코드명")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "character_ref1_title", length = 100)
|
||||||
|
@Comment("문자 참조 타이틀1")
|
||||||
|
private String characterRef1Title;
|
||||||
|
|
||||||
|
@Column(name = "character_ref2_title", length = 100)
|
||||||
|
@Comment("문자 참조 타이틀2")
|
||||||
|
private String characterRef2Title;
|
||||||
|
|
||||||
|
@Column(name = "character_ref3_title", length = 100)
|
||||||
|
@Comment("문자 참조 타이틀3")
|
||||||
|
private String characterRef3Title;
|
||||||
|
|
||||||
|
@Column(name = "character_ref4_title", length = 100)
|
||||||
|
@Comment("문자 참조 타이틀4")
|
||||||
|
private String characterRef4Title;
|
||||||
|
|
||||||
|
@Column(name = "character_ref5_title", length = 100)
|
||||||
|
@Comment("문자 참조 타이틀5")
|
||||||
|
private String characterRef5Title;
|
||||||
|
|
||||||
|
@Column(name = "sort_order", nullable = false)
|
||||||
|
@Comment("정렬 순번")
|
||||||
|
@Builder.Default
|
||||||
|
private Integer sortOrder = 0;
|
||||||
|
|
||||||
|
@Column(name = "use_flag", nullable = false)
|
||||||
|
@Comment("사용 여부")
|
||||||
|
@Builder.Default
|
||||||
|
private Boolean useFlag = true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
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 com.bio.bio_backend.global.config.GlobalMapperConfig;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper(config = GlobalMapperConfig.class)
|
||||||
|
public interface CommonCodeMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CommonCode 엔티티를 CommonCodeDto로 변환
|
||||||
|
*/
|
||||||
|
CommonCodeDto toCommonCodeDto(CommonCode commonCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CommonCodeDto를 CommonCode 엔티티로 변환
|
||||||
|
*/
|
||||||
|
@Mapping(target = "commonGroupCode", ignore = true)
|
||||||
|
CommonCode toCommonCode(CommonCodeDto commonCodeDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CommonCode 엔티티 리스트를 CommonCodeDto 리스트로 변환
|
||||||
|
*/
|
||||||
|
List<CommonCodeDto> toCommonCodeDtoList(List<CommonCode> 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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
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 com.bio.bio_backend.global.config.GlobalMapperConfig;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper(config = GlobalMapperConfig.class)
|
||||||
|
public interface CommonGroupCodeMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CommonGroupCode 엔티티를 CommonGroupCodeDto로 변환
|
||||||
|
*/
|
||||||
|
CommonGroupCodeDto toCommonGroupCodeDto(CommonGroupCode commonGroupCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CommonGroupCodeDto를 CommonGroupCode 엔티티로 변환
|
||||||
|
*/
|
||||||
|
CommonGroupCode toCommonGroupCode(CommonGroupCodeDto commonGroupCodeDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CommonGroupCode 엔티티 리스트를 CommonGroupCodeDto 리스트로 변환
|
||||||
|
*/
|
||||||
|
List<CommonGroupCodeDto> toCommonGroupCodeDtoList(List<CommonGroupCode> 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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.admin.common_code.entity.CommonCode;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface CommonCodeRepository extends JpaRepository<CommonCode, Long>, CommonCodeRepositoryCustom {
|
||||||
|
|
||||||
|
Optional<CommonCode> findByCode(String code);
|
||||||
|
|
||||||
|
boolean existsByCode(String code);
|
||||||
|
|
||||||
|
boolean existsByGroupCode(String groupCode);
|
||||||
|
|
||||||
|
boolean existsByParentCode(String parentCode);
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.admin.common_code.dto.GetCommonCodeResponseDto;
|
||||||
|
import com.bio.bio_backend.domain.admin.common_code.entity.CommonCode;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryDSL을 활용한 커스텀 쿼리 메서드들을 정의하는 인터페이스
|
||||||
|
* 복잡한 쿼리나 동적 쿼리가 필요한 경우 이 인터페이스를 구현하여 사용합니다.
|
||||||
|
*/
|
||||||
|
public interface CommonCodeRepositoryCustom {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 그룹 코드로 활성화된 공통 코드들을 정렬 순서대로 조회합니다.
|
||||||
|
*
|
||||||
|
* @param groupCode 그룹 코드
|
||||||
|
* @return List<CommonCode> 활성화된 공통 코드 목록
|
||||||
|
*/
|
||||||
|
List<CommonCode> findByGroupCode(String groupCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 부모 코드로 활성화된 공통 코드들을 정렬 순서대로 조회합니다.
|
||||||
|
*
|
||||||
|
* @param parentCode 부모 코드
|
||||||
|
* @return List<CommonCode> 활성화된 공통 코드 목록
|
||||||
|
*/
|
||||||
|
List<CommonCode> findByParentCode(String parentCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 특정 공통 코드를 조회하며 CommonGroupCode와 Member 정보를 join하여 함께 조회합니다.
|
||||||
|
* QueryDSL을 사용하여 성능 최적화된 쿼리를 실행합니다.
|
||||||
|
*
|
||||||
|
* @param code 조회할 공통 코드
|
||||||
|
* @return Optional<GetCommonCodeResponseDto> 조회된 공통 코드 정보 (없으면 empty)
|
||||||
|
*/
|
||||||
|
Optional<GetCommonCodeResponseDto> findCodeWithJoinInfo(String code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 특정 공통 코드를 조회하며 CommonGroupCode와 Member 정보를 join하여 함께 조회합니다.
|
||||||
|
* Native Query를 사용한 버전 (사용하지 않음, 참고용)
|
||||||
|
*
|
||||||
|
* @param code 조회할 공통 코드
|
||||||
|
* @return Optional<GetCommonCodeResponseDto> 조회된 공통 코드 정보 (없으면 empty)
|
||||||
|
*/
|
||||||
|
Optional<GetCommonCodeResponseDto> findCodeWithJoinInfoNative(String code);
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.admin.common_code.dto.GetCommonCodeResponseDto;
|
||||||
|
import com.bio.bio_backend.domain.admin.common_code.entity.CommonCode;
|
||||||
|
import com.bio.bio_backend.domain.admin.common_code.entity.QCommonCode;
|
||||||
|
import com.bio.bio_backend.domain.admin.common_code.entity.QCommonGroupCode;
|
||||||
|
import com.bio.bio_backend.domain.base.member.entity.QMember;
|
||||||
|
import com.querydsl.core.types.Projections;
|
||||||
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class CommonCodeRepositoryImpl implements CommonCodeRepositoryCustom {
|
||||||
|
|
||||||
|
private final JPAQueryFactory queryFactory;
|
||||||
|
private final EntityManager entityManager;
|
||||||
|
|
||||||
|
private final QCommonCode commonCode = QCommonCode.commonCode;
|
||||||
|
private final QCommonGroupCode commonGroupCode = QCommonGroupCode.commonGroupCode;
|
||||||
|
private final QMember member = QMember.member;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CommonCode> findByGroupCode(String groupCode) {
|
||||||
|
return queryFactory
|
||||||
|
.selectFrom(commonCode)
|
||||||
|
.where(commonCode.groupCode.eq(groupCode)
|
||||||
|
.and(commonCode.useFlag.eq(true)))
|
||||||
|
.orderBy(commonCode.sortOrder.asc())
|
||||||
|
.fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CommonCode> findByParentCode(String parentCode) {
|
||||||
|
return queryFactory
|
||||||
|
.selectFrom(commonCode)
|
||||||
|
.where(commonCode.parentCode.eq(parentCode)
|
||||||
|
.and(commonCode.useFlag.eq(true)))
|
||||||
|
.orderBy(commonCode.sortOrder.asc())
|
||||||
|
.fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<GetCommonCodeResponseDto> findCodeWithJoinInfo(String code) {
|
||||||
|
return Optional.ofNullable(
|
||||||
|
queryFactory
|
||||||
|
.select(Projections.constructor(GetCommonCodeResponseDto.class,
|
||||||
|
commonCode.code, commonCode.name, commonCode.description,
|
||||||
|
commonCode.groupCode, commonCode.parentCode,
|
||||||
|
commonCode.characterRef1, commonCode.characterRef2, commonCode.characterRef3,
|
||||||
|
commonCode.characterRef4, commonCode.characterRef5,
|
||||||
|
commonCode.sortOrder, commonCode.useFlag,
|
||||||
|
commonCode.createdAt, commonCode.updatedAt,
|
||||||
|
commonGroupCode.name, member.name, member.name
|
||||||
|
))
|
||||||
|
.from(commonCode)
|
||||||
|
.leftJoin(commonGroupCode).on(commonCode.groupCode.eq(commonGroupCode.code))
|
||||||
|
.leftJoin(member).on(commonCode.createdOid.eq(member.oid))
|
||||||
|
.leftJoin(member).on(commonCode.updatedOid.eq(member.oid))
|
||||||
|
.where(commonCode.code.eq(code))
|
||||||
|
.fetchOne()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<GetCommonCodeResponseDto> findCodeWithJoinInfoNative(String code) {
|
||||||
|
String nativeQuery = """
|
||||||
|
SELECT cc.code, cc.name, cc.description, cc.group_code, cc.parent_code,
|
||||||
|
cc.character_ref1, cc.character_ref2, cc.character_ref3, cc.character_ref4, cc.character_ref5,
|
||||||
|
cc.sort_order, cc.use_flag, cc.created_at, cc.updated_at,
|
||||||
|
cgc.name as group_code_name, cm1.name as created_by_name, cm2.name as updated_by_name
|
||||||
|
FROM st_common_code cc
|
||||||
|
LEFT JOIN st_common_group_code cgc ON cc.group_code = cgc.code
|
||||||
|
LEFT JOIN st_member cm1 ON cc.created_oid = cm1.oid
|
||||||
|
LEFT JOIN st_member cm2 ON cc.updated_oid = cm2.oid
|
||||||
|
WHERE cc.code = :code
|
||||||
|
""";
|
||||||
|
|
||||||
|
try {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<GetCommonCodeResponseDto> results = entityManager
|
||||||
|
.createNativeQuery(nativeQuery, "GetCommonCodeResponseDtoMapping")
|
||||||
|
.setParameter("code", code)
|
||||||
|
.getResultList();
|
||||||
|
|
||||||
|
return results.isEmpty() ? Optional.empty() : Optional.of(results.get(0));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.admin.common_code.entity.CommonGroupCode;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface CommonGroupCodeRepository extends JpaRepository<CommonGroupCode, Long> {
|
||||||
|
|
||||||
|
Optional<CommonGroupCode> findByCode(String code);
|
||||||
|
|
||||||
|
List<CommonGroupCode> findByUseFlagOrderBySortOrderAsc(Boolean useFlag);
|
||||||
|
|
||||||
|
boolean existsByCode(String code);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.service;
|
||||||
|
|
||||||
|
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.dto.GetCommonCodeResponseDto;
|
||||||
|
|
||||||
|
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<CommonGroupCodeDto> getAllGroupCodes();
|
||||||
|
List<CommonGroupCodeDto> getActiveGroupCodes();
|
||||||
|
|
||||||
|
// 공통 코드 관련
|
||||||
|
CommonCodeDto createCode(CommonCodeDto codeDto);
|
||||||
|
void updateCode(String code, CommonCodeDto codeDto);
|
||||||
|
void deleteCode(String code);
|
||||||
|
CommonCodeDto getCode(String code);
|
||||||
|
GetCommonCodeResponseDto getCodeWithJoinInfo(String code);
|
||||||
|
List<CommonCodeDto> getActiveCodesByGroupCode(String groupCode);
|
||||||
|
List<CommonCodeDto> getActiveCodesByParentCode(String parentCode);
|
||||||
|
List<CommonCodeDto> getAllCodes();
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
package com.bio.bio_backend.domain.admin.common_code.service;
|
||||||
|
|
||||||
|
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.dto.GetCommonCodeResponseDto;
|
||||||
|
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;
|
||||||
|
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.COMMON_CODE_DUPLICATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
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_TARGET_NOT_FOUND));
|
||||||
|
|
||||||
|
commonGroupCodeMapper.updateCommonGroupCodeFromDto(groupCodeDto, existingGroupCode);
|
||||||
|
commonGroupCodeRepository.save(existingGroupCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void deleteGroupCode(String code) {
|
||||||
|
CommonGroupCode groupCode = commonGroupCodeRepository.findByCode(code)
|
||||||
|
.orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_TARGET_NOT_FOUND));
|
||||||
|
|
||||||
|
// 하위 공통 코드가 있는지 확인
|
||||||
|
if (commonCodeRepository.existsByGroupCode(code)) {
|
||||||
|
throw new ApiException(ApiResponseCode.COMMON_CODE_ERROR_001);
|
||||||
|
}
|
||||||
|
|
||||||
|
commonGroupCodeRepository.delete(groupCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonGroupCodeDto getGroupCode(String code) {
|
||||||
|
CommonGroupCode groupCode = commonGroupCodeRepository.findByCode(code)
|
||||||
|
.orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND));
|
||||||
|
return commonGroupCodeMapper.toCommonGroupCodeDto(groupCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CommonGroupCodeDto> getAllGroupCodes() {
|
||||||
|
List<CommonGroupCode> groupCodes = commonGroupCodeRepository.findAll();
|
||||||
|
return commonGroupCodeMapper.toCommonGroupCodeDtoList(groupCodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CommonGroupCodeDto> getActiveGroupCodes() {
|
||||||
|
List<CommonGroupCode> groupCodes = commonGroupCodeRepository.findByUseFlagOrderBySortOrderAsc(true);
|
||||||
|
return commonGroupCodeMapper.toCommonGroupCodeDtoList(groupCodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 공통 코드 관련 메서드들
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public CommonCodeDto createCode(CommonCodeDto commonCodeDto) {
|
||||||
|
if (commonCodeRepository.existsByCode(commonCodeDto.getCode())) {
|
||||||
|
throw new ApiException(ApiResponseCode.COMMON_CODE_DUPLICATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 그룹 코드 존재 여부 확인
|
||||||
|
if (!commonGroupCodeRepository.existsByCode(commonCodeDto.getGroupCode())) {
|
||||||
|
throw new ApiException(ApiResponseCode.COMMON_CODE_ERROR_002);
|
||||||
|
}
|
||||||
|
|
||||||
|
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_CODE_ERROR_003));
|
||||||
|
|
||||||
|
commonCodeMapper.updateCommonCodeFromDto(commonCodeDto, existingCommonCode);
|
||||||
|
commonCodeRepository.save(existingCommonCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void deleteCode(String code) {
|
||||||
|
CommonCode commonCode = commonCodeRepository.findByCode(code)
|
||||||
|
.orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_CODE_ERROR_003));
|
||||||
|
|
||||||
|
// 하위 공통 코드가 있는지 확인
|
||||||
|
if (commonCodeRepository.existsByParentCode(code)) {
|
||||||
|
throw new ApiException(ApiResponseCode.COMMON_CODE_ERROR_001);
|
||||||
|
}
|
||||||
|
|
||||||
|
commonCodeRepository.delete(commonCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonCodeDto getCode(String code) {
|
||||||
|
CommonCode commonCode = commonCodeRepository.findByCode(code)
|
||||||
|
.orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_CODE_ERROR_003));
|
||||||
|
return commonCodeMapper.toCommonCodeDto(commonCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GetCommonCodeResponseDto getCodeWithJoinInfo(String code) {
|
||||||
|
return commonCodeRepository.findCodeWithJoinInfo(code)
|
||||||
|
.orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_CODE_ERROR_003));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CommonCodeDto> getActiveCodesByGroupCode(String groupCode) {
|
||||||
|
List<CommonCode> commonCodes = commonCodeRepository.findByGroupCode(groupCode);
|
||||||
|
return commonCodeMapper.toCommonCodeDtoList(commonCodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CommonCodeDto> getActiveCodesByParentCode(String parentCode) {
|
||||||
|
List<CommonCode> commonCodes = commonCodeRepository.findByParentCode(parentCode);
|
||||||
|
return commonCodeMapper.toCommonCodeDtoList(commonCodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CommonCodeDto> getAllCodes() {
|
||||||
|
List<CommonCode> commonCodes = commonCodeRepository.findAll();
|
||||||
|
return commonCodeMapper.toCommonCodeDtoList(commonCodes);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroup.controller;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.dto.AuthGroupDto;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.service.AuthGroupService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/auth_group")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Tag(name = "AuthGroup", description = "")
|
||||||
|
@Slf4j
|
||||||
|
public class AuthGroupController {
|
||||||
|
|
||||||
|
private final AuthGroupService authGroupService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
public AuthGroupDto create(@RequestBody AuthGroupDto authGroupDto) {
|
||||||
|
return authGroupService.create(authGroupDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public AuthGroupDto getById(@PathVariable Long id) {
|
||||||
|
return authGroupService.getById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<AuthGroupDto> getAll() {
|
||||||
|
return authGroupService.getAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public AuthGroupDto update(@PathVariable Long id, @RequestBody AuthGroupDto dto) {
|
||||||
|
return authGroupService.update(id, dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public void delete(@PathVariable Long id) {
|
||||||
|
authGroupService.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroup.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class AuthGroupDto {
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroup.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;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Table(name = AppConstants.TABLE_PREFIX + "auth_group")
|
||||||
|
public class AuthGroup extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(name = "name", length = 100)
|
||||||
|
@Comment("권한 그룹명")
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroup.mapper;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.global.config.GlobalMapperConfig;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.entity.AuthGroup;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.dto.AuthGroupDto;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
@Mapper(config = GlobalMapperConfig.class)
|
||||||
|
public interface AuthGroupMapper {
|
||||||
|
AuthGroup toEntity(AuthGroupDto dto);
|
||||||
|
|
||||||
|
AuthGroupDto toDto(AuthGroup entity);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroup.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.entity.AuthGroup;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface AuthGroupRepository extends JpaRepository<AuthGroup, Long>, AuthGroupRepositoryCustom {
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroup.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.entity.AuthGroup;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryDSL을 활용한 커스텀 쿼리 메서드들을 정의하는 인터페이스
|
||||||
|
* 복잡한 쿼리나 동적 쿼리가 필요한 경우 이 인터페이스를 구현하여 사용합니다.
|
||||||
|
*/
|
||||||
|
public interface AuthGroupRepositoryCustom {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroup.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.entity.AuthGroup;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.entity.QAuthGroup;
|
||||||
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryDSL을 활용하여 AuthGroupRepositoryCustom 인터페이스를 구현하는 클래스
|
||||||
|
* 복잡한 쿼리나 동적 쿼리를 QueryDSL로 작성하여 성능과 가독성을 향상시킵니다.
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AuthGroupRepositoryImpl implements AuthGroupRepositoryCustom {
|
||||||
|
|
||||||
|
private final JPAQueryFactory queryFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QAuthGroup 인스턴스를 생성하여 쿼리에서 사용합니다.
|
||||||
|
* QueryDSL의 Q클래스를 통해 타입 안전한 쿼리 작성이 가능합니다.
|
||||||
|
*/
|
||||||
|
private final QAuthGroup authGroup = QAuthGroup.authGroup;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroup.service;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.dto.AuthGroupDto;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface AuthGroupService {
|
||||||
|
AuthGroupDto create(AuthGroupDto dto);
|
||||||
|
|
||||||
|
AuthGroupDto getById(Long id);
|
||||||
|
|
||||||
|
List<AuthGroupDto> getAll();
|
||||||
|
|
||||||
|
AuthGroupDto update(Long id, AuthGroupDto dto);
|
||||||
|
|
||||||
|
void delete(Long id);
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroup.service;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.dto.AuthGroupDto;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.entity.AuthGroup;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.repository.AuthGroupRepository;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.mapper.AuthGroupMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class AuthGroupServiceImpl implements AuthGroupService {
|
||||||
|
|
||||||
|
private final AuthGroupRepository repository;
|
||||||
|
private final AuthGroupMapper mapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public AuthGroupDto create(AuthGroupDto dto) {
|
||||||
|
AuthGroup entity = mapper.toEntity(dto);
|
||||||
|
return mapper.toDto(repository.save(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthGroupDto getById(Long id) {
|
||||||
|
return repository.findById(id).map(mapper::toDto).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AuthGroupDto> getAll() {
|
||||||
|
return repository.findAll().stream().map(mapper::toDto).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public AuthGroupDto update(Long id, AuthGroupDto dto) {
|
||||||
|
AuthGroup entity = repository.findById(id).orElseThrow();
|
||||||
|
// TODO: update fields
|
||||||
|
return mapper.toDto(repository.save(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void delete(Long id) {
|
||||||
|
repository.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroupresource.controller;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.dto.AuthGroupResourceDto;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.dto.ReplaceAuthGroupResourcesRequest;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.service.AuthGroupResourceService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/auth_group_resource")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Tag(name = "AuthGroupResource", description = "")
|
||||||
|
@Slf4j
|
||||||
|
public class AuthGroupResourceController {
|
||||||
|
|
||||||
|
private final AuthGroupResourceService service;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
public AuthGroupResourceDto create(@RequestBody AuthGroupResourceDto dto) {
|
||||||
|
return service.create(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public AuthGroupResourceDto getById(@PathVariable Long id) {
|
||||||
|
return service.getById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<AuthGroupResourceDto> getAll() {
|
||||||
|
return service.getAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public AuthGroupResourceDto update(@PathVariable Long id, @RequestBody AuthGroupResourceDto dto) {
|
||||||
|
return service.update(id, dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public void delete(@PathVariable Long id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/replace")
|
||||||
|
public void replaceAuthGroupResources(@RequestBody ReplaceAuthGroupResourcesRequest request) {
|
||||||
|
service.replaceAuthGroupResources(request.getAuthGroupOid(), request.getResourceOids());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroupresource.dto;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.entity.AuthGroup;
|
||||||
|
import com.bio.bio_backend.domain.base.resource.entity.Resource;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class AuthGroupResourceDto {
|
||||||
|
private AuthGroup authGroupOid;
|
||||||
|
private Resource resourceOid;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroupresource.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ReplaceAuthGroupResourcesRequest {
|
||||||
|
private Long authGroupOid;
|
||||||
|
private List<Long> resourceOids;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroupresource.entity;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.entity.AuthGroup;
|
||||||
|
import com.bio.bio_backend.domain.base.resource.entity.Resource;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Table(name = AppConstants.TABLE_PREFIX + "auth_group_resource")
|
||||||
|
|
||||||
|
public class AuthGroupResource extends BaseEntity {
|
||||||
|
|
||||||
|
@JoinColumn(name = "auth_group_oid")
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@Comment("권한 그룹 OID")
|
||||||
|
private AuthGroup authGroupOid;
|
||||||
|
|
||||||
|
@JoinColumn(name = "resource_oid")
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@Comment("리소스 OID")
|
||||||
|
private Resource resourceOid;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroupresource.mapper;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.global.config.GlobalMapperConfig;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.entity.AuthGroupResource;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.dto.AuthGroupResourceDto;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
@Mapper(config = GlobalMapperConfig.class)
|
||||||
|
public interface AuthGroupResourceMapper {
|
||||||
|
AuthGroupResource toEntity(AuthGroupResourceDto dto);
|
||||||
|
|
||||||
|
AuthGroupResourceDto toDto(AuthGroupResource entity);
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroupresource.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.entity.AuthGroupResource;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface AuthGroupResourceRepository
|
||||||
|
extends JpaRepository<AuthGroupResource, Long>, AuthGroupResourceRepositoryCustom {
|
||||||
|
|
||||||
|
@Modifying
|
||||||
|
@Query("delete from AuthGroupResource agr where agr.authGroupOid.oid = :authGroupOid")
|
||||||
|
void deleteByAuthGroupOid(@Param("authGroupOid") Long authGroupOid);
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroupresource.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.entity.AuthGroupResource;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryDSL을 활용한 커스텀 쿼리 메서드들을 정의하는 인터페이스
|
||||||
|
* 복잡한 쿼리나 동적 쿼리가 필요한 경우 이 인터페이스를 구현하여 사용합니다.
|
||||||
|
*/
|
||||||
|
public interface AuthGroupResourceRepositoryCustom {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroupresource.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.entity.AuthGroupResource;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.entity.QAuthGroupResource;
|
||||||
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryDSL을 활용하여 AuthGroupResourceRepositoryCustom 인터페이스를 구현하는 클래스
|
||||||
|
* 복잡한 쿼리나 동적 쿼리를 QueryDSL로 작성하여 성능과 가독성을 향상시킵니다.
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AuthGroupResourceRepositoryImpl implements AuthGroupResourceRepositoryCustom {
|
||||||
|
|
||||||
|
private final JPAQueryFactory queryFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QAuthGroupResource 인스턴스를 생성하여 쿼리에서 사용합니다.
|
||||||
|
* QueryDSL의 Q클래스를 통해 타입 안전한 쿼리 작성이 가능합니다.
|
||||||
|
*/
|
||||||
|
private final QAuthGroupResource authGroupResource = QAuthGroupResource.authGroupResource;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroupresource.service;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.dto.AuthGroupResourceDto;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface AuthGroupResourceService {
|
||||||
|
AuthGroupResourceDto create(AuthGroupResourceDto dto);
|
||||||
|
|
||||||
|
AuthGroupResourceDto getById(Long id);
|
||||||
|
|
||||||
|
List<AuthGroupResourceDto> getAll();
|
||||||
|
|
||||||
|
AuthGroupResourceDto update(Long id, AuthGroupResourceDto dto);
|
||||||
|
|
||||||
|
void delete(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 특정 authGroupOid의 기존 매핑을 모두 삭제하고, 전달된 resourceOid 목록으로 재등록
|
||||||
|
*/
|
||||||
|
void replaceAuthGroupResources(Long authGroupOid, List<Long> resourceOids);
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.authgroupresource.service;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.dto.AuthGroupResourceDto;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.entity.AuthGroupResource;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.repository.AuthGroupResourceRepository;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroupresource.mapper.AuthGroupResourceMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.entity.AuthGroup;
|
||||||
|
import com.bio.bio_backend.domain.base.resource.entity.Resource;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class AuthGroupResourceServiceImpl implements AuthGroupResourceService {
|
||||||
|
|
||||||
|
private final AuthGroupResourceRepository repository;
|
||||||
|
private final AuthGroupResourceMapper mapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public AuthGroupResourceDto create(AuthGroupResourceDto dto) {
|
||||||
|
AuthGroupResource entity = mapper.toEntity(dto);
|
||||||
|
return mapper.toDto(repository.save(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthGroupResourceDto getById(Long id) {
|
||||||
|
return repository.findById(id).map(mapper::toDto).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AuthGroupResourceDto> getAll() {
|
||||||
|
return repository.findAll().stream().map(mapper::toDto).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public AuthGroupResourceDto update(Long id, AuthGroupResourceDto dto) {
|
||||||
|
AuthGroupResource entity = repository.findById(id).orElseThrow();
|
||||||
|
// TODO: update fields
|
||||||
|
return mapper.toDto(repository.save(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void delete(Long id) {
|
||||||
|
repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void replaceAuthGroupResources(Long authGroupOid, List<Long> resourceOids) {
|
||||||
|
repository.deleteByAuthGroupOid(authGroupOid);
|
||||||
|
|
||||||
|
if (resourceOids == null || resourceOids.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AuthGroup groupRef = new AuthGroup();
|
||||||
|
groupRef.setOid(authGroupOid);
|
||||||
|
|
||||||
|
for (Long resourceOid : resourceOids) {
|
||||||
|
Resource resourceRef = new Resource();
|
||||||
|
resourceRef.setOid(resourceOid);
|
||||||
|
|
||||||
|
AuthGroupResource entity = AuthGroupResource.builder()
|
||||||
|
.authGroupOid(groupRef)
|
||||||
|
.resourceOid(resourceRef)
|
||||||
|
.build();
|
||||||
|
repository.save(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.file.controller;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.file.dto.FileUploadRequestDto;
|
||||||
|
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 com.bio.bio_backend.global.dto.ApiResponseDto;
|
||||||
|
import com.bio.bio_backend.global.constants.ApiResponseCode;
|
||||||
|
import com.bio.bio_backend.global.annotation.LogExecution;
|
||||||
|
import com.bio.bio_backend.global.utils.FileUtils;
|
||||||
|
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.core.io.ByteArrayResource;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import com.bio.bio_backend.domain.base.file.entity.File;
|
||||||
|
|
||||||
|
|
||||||
|
@Tag(name = "File", description = "파일 업로드/다운로드 API")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/files")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class FileController {
|
||||||
|
|
||||||
|
private final FileService fileService;
|
||||||
|
|
||||||
|
@LogExecution("파일 업로드")
|
||||||
|
@Operation(summary = "파일 업로드", description = "단일 파일을 업로드합니다.")
|
||||||
|
@ApiResponses({
|
||||||
|
@ApiResponse(responseCode = "200", description = "파일 업로드 성공"),
|
||||||
|
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||||
|
@ApiResponse(responseCode = "500", description = "파일 업로드 실패", content = @Content)
|
||||||
|
})
|
||||||
|
@PostMapping("/upload")
|
||||||
|
public ResponseEntity<ApiResponseDto<FileUploadResponseDto>> uploadFile(
|
||||||
|
@ModelAttribute FileUploadRequestDto requestDto) {
|
||||||
|
|
||||||
|
FileUploadResponseDto responseDto = fileService.uploadFile(requestDto);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.FILE_UPLOAD_SUCCESS, responseDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@LogExecution("다중 파일 업로드")
|
||||||
|
@Operation(summary = "다중 파일 업로드", description = "여러 파일을 동시에 업로드합니다.")
|
||||||
|
@ApiResponses({
|
||||||
|
@ApiResponse(responseCode = "200", description = "다중 파일 업로드 성공"),
|
||||||
|
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||||
|
@ApiResponse(responseCode = "500", description = "다중 파일 업로드 실패", content = @Content)
|
||||||
|
})
|
||||||
|
@PostMapping("/upload-multiple")
|
||||||
|
public ResponseEntity<ApiResponseDto<MultipleFileUploadResponseDto>> uploadMultipleFiles(
|
||||||
|
@ModelAttribute MultipleFileUploadRequestDto requestDto) {
|
||||||
|
|
||||||
|
MultipleFileUploadResponseDto responseDto = fileService.uploadMultipleFiles(requestDto);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.FILE_UPLOAD_SUCCESS, responseDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@LogExecution("파일 다운로드")
|
||||||
|
@Operation(summary = "파일 다운로드", description = "파일 ID로 파일을 다운로드합니다.")
|
||||||
|
@ApiResponses({
|
||||||
|
@ApiResponse(responseCode = "200", description = "파일 다운로드 성공"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "파일을 찾을 수 없음", content = @Content),
|
||||||
|
@ApiResponse(responseCode = "500", description = "파일 다운로드 실패", content = @Content)
|
||||||
|
})
|
||||||
|
@GetMapping("/download/{oid}")
|
||||||
|
public ResponseEntity<ByteArrayResource> downloadFile(@PathVariable Long oid) {
|
||||||
|
// 파일 정보 먼저 조회
|
||||||
|
File file = fileService.getFileByOid(oid);
|
||||||
|
byte[] fileData = fileService.downloadFile(oid);
|
||||||
|
ByteArrayResource resource = new ByteArrayResource(fileData);
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||||
|
"attachment; filename=\"" + file.getOriginalFileName() + "\"")
|
||||||
|
.header(HttpHeaders.CONTENT_TYPE, file.getContentType())
|
||||||
|
.body(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@LogExecution("파일 논리적 삭제")
|
||||||
|
@Operation(summary = "파일 논리적 삭제", description = "파일 ID로 파일을 논리적으로 삭제합니다. (use_flag를 false로 변경)")
|
||||||
|
@ApiResponses({
|
||||||
|
@ApiResponse(responseCode = "200", description = "파일 논리적 삭제 성공"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "파일을 찾을 수 없음", content = @Content),
|
||||||
|
@ApiResponse(responseCode = "500", description = "파일 논리적 삭제 실패", content = @Content)
|
||||||
|
})
|
||||||
|
@DeleteMapping("/{oid}")
|
||||||
|
public ResponseEntity<ApiResponseDto<Void>> deleteFile(@PathVariable Long oid) {
|
||||||
|
fileService.deleteFile(oid);
|
||||||
|
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.FILE_DELETE_SUCCESS));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<FileUploadResponseDto> files; // 파일 정보들
|
||||||
|
private int totalCount;
|
||||||
|
private int successCount;
|
||||||
|
private int failureCount;
|
||||||
|
private List<String> errorMessages;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.file.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FileUploadRequestDto {
|
||||||
|
private MultipartFile file;
|
||||||
|
private String description;
|
||||||
|
}
|
||||||
@@ -0,0 +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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
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<MultipartFile> files;
|
||||||
|
private String description;
|
||||||
|
}
|
||||||
@@ -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 MultipleFileUploadResponseDto {
|
||||||
|
private List<FileUploadResponseDto> files;
|
||||||
|
private Long groupOid;
|
||||||
|
private int totalCount;
|
||||||
|
private int successCount;
|
||||||
|
private int failureCount;
|
||||||
|
private List<String> errorMessages;
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.file.entity;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.global.constants.AppConstants;
|
||||||
|
import com.bio.bio_backend.global.entity.BaseEntity;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = AppConstants.TABLE_PREFIX + "file")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class File extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Comment("원본 파일명")
|
||||||
|
private String originalFileName;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Comment("저장 파일명")
|
||||||
|
private String storedFileName;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Comment("파일 경로")
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Comment("파일 크기")
|
||||||
|
private Long fileSize;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Comment("콘텐츠 타입")
|
||||||
|
private String contentType;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@Comment("설명")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@Comment("그룹 OID")
|
||||||
|
private Long groupOid;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Comment("사용 여부")
|
||||||
|
@Builder.Default
|
||||||
|
private Boolean useFlag = true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.file.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.file.entity.File;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface FileRepository extends JpaRepository<File, Long> {
|
||||||
|
|
||||||
|
Optional<File> findByOidAndUseFlagTrue(Long id);
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.file.service;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.file.dto.FileUploadRequestDto;
|
||||||
|
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.entity.File;
|
||||||
|
|
||||||
|
public interface FileService {
|
||||||
|
FileUploadResponseDto uploadFile(FileUploadRequestDto requestDto);
|
||||||
|
MultipleFileUploadResponseDto uploadMultipleFiles(MultipleFileUploadRequestDto requestDto);
|
||||||
|
File getFileByOid(Long oid);
|
||||||
|
byte[] downloadFile(Long oid);
|
||||||
|
void deleteFile(Long oid); // 논리적 삭제 (use_flag를 false로 변경)
|
||||||
|
}
|
||||||
@@ -0,0 +1,206 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.file.service;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.file.dto.FileUploadRequestDto;
|
||||||
|
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.entity.File;
|
||||||
|
import com.bio.bio_backend.domain.base.file.repository.FileRepository;
|
||||||
|
import com.bio.bio_backend.global.exception.ApiException;
|
||||||
|
import com.bio.bio_backend.global.constants.ApiResponseCode;
|
||||||
|
import com.bio.bio_backend.global.utils.FileUtils;
|
||||||
|
import com.bio.bio_backend.global.utils.SecurityUtils;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
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.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.bio.bio_backend.global.utils.OidUtils.generateOid;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class FileServiceImpl implements FileService {
|
||||||
|
|
||||||
|
private final FileRepository fileRepository;
|
||||||
|
|
||||||
|
@Value("${app.file.upload.path}")
|
||||||
|
private String uploadPath;
|
||||||
|
|
||||||
|
@Value("${server.servlet.context-path}")
|
||||||
|
private String contextPath;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public FileUploadResponseDto uploadFile(FileUploadRequestDto requestDto) {
|
||||||
|
MultipartFile multipartFile = requestDto.getFile();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 파일 유효성 검사
|
||||||
|
FileUtils.validateFile(multipartFile);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new ApiException(ApiResponseCode.FILE_EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 파일 업로드 처리
|
||||||
|
File savedFile = processFileUpload(multipartFile, requestDto.getDescription(), generateOid());
|
||||||
|
|
||||||
|
// 응답 DTO 생성 및 반환
|
||||||
|
return FileUploadResponseDto.builder()
|
||||||
|
.oid(savedFile.getOid())
|
||||||
|
.groupOid(savedFile.getGroupOid())
|
||||||
|
.originalFileName(savedFile.getOriginalFileName())
|
||||||
|
.downloadUrl(contextPath + "/files/download/" + savedFile.getOid())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public MultipleFileUploadResponseDto uploadMultipleFiles(MultipleFileUploadRequestDto requestDto) {
|
||||||
|
List<MultipartFile> files = requestDto.getFiles();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 파일 리스트 유효성 검사
|
||||||
|
FileUtils.validateFileList(files);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new ApiException(ApiResponseCode.FILE_EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<FileUploadResponseDto> uploadedFiles = new ArrayList<>();
|
||||||
|
List<String> errorMessages = new ArrayList<>();
|
||||||
|
int successCount = 0;
|
||||||
|
int failureCount = 0;
|
||||||
|
|
||||||
|
Long groupOid = generateOid();
|
||||||
|
for (MultipartFile multipartFile : files) {
|
||||||
|
try {
|
||||||
|
// 개별 파일 유효성 검사
|
||||||
|
if (multipartFile.isEmpty()) {
|
||||||
|
String errorMsg = "파일 '" + multipartFile.getOriginalFilename() + "'이 비어있습니다.";
|
||||||
|
errorMessages.add(errorMsg);
|
||||||
|
failureCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 단일 파일 업로드 처리
|
||||||
|
File savedFile = processFileUpload(multipartFile, requestDto.getDescription(), groupOid);
|
||||||
|
FileUploadResponseDto uploadedFile = FileUploadResponseDto.builder()
|
||||||
|
.oid(savedFile.getOid())
|
||||||
|
.originalFileName(savedFile.getOriginalFileName())
|
||||||
|
.downloadUrl(contextPath + "/files/download/" + savedFile.getOid())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
uploadedFiles.add(uploadedFile);
|
||||||
|
successCount++;
|
||||||
|
|
||||||
|
log.info("파일 업로드 성공: {}", multipartFile.getOriginalFilename());
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
String fileName = multipartFile.getOriginalFilename() != null ? multipartFile.getOriginalFilename() : "알 수 없는 파일";
|
||||||
|
log.error("파일 업로드 실패: {}", fileName, ex);
|
||||||
|
errorMessages.add("파일 '" + fileName + "' 업로드 실패: " + ex.getMessage());
|
||||||
|
failureCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return MultipleFileUploadResponseDto.builder()
|
||||||
|
.groupOid(groupOid)
|
||||||
|
.files(uploadedFiles)
|
||||||
|
.totalCount(files.size())
|
||||||
|
.successCount(successCount)
|
||||||
|
.failureCount(failureCount)
|
||||||
|
.errorMessages(errorMessages)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 파일 업로드 처리
|
||||||
|
*/
|
||||||
|
private File processFileUpload(MultipartFile multipartFile, String description, Long groupOid) {
|
||||||
|
String originalFileName = FileUtils.cleanFileName(multipartFile.getOriginalFilename());
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 항상 년월일 기반으로 폴더 생성 (예: uploads/2024/01/15/)
|
||||||
|
Path uploadDir = FileUtils.createYearMonthUploadDirectory(uploadPath);
|
||||||
|
log.debug("년월 기반 폴더 사용: {}", uploadDir);
|
||||||
|
|
||||||
|
// 파일명 및 확장자 처리
|
||||||
|
String fileExtension = FileUtils.extractFileExtension(originalFileName);
|
||||||
|
String storedFileName = FileUtils.generateUniqueFileName(fileExtension);
|
||||||
|
|
||||||
|
// 파일 저장
|
||||||
|
Path targetLocation = FileUtils.saveFileToDisk(multipartFile, uploadDir, storedFileName);
|
||||||
|
|
||||||
|
// DB에 파일 정보 저장
|
||||||
|
File file = createFileEntity(originalFileName, storedFileName, targetLocation, multipartFile, description, groupOid);
|
||||||
|
|
||||||
|
return fileRepository.save(file);
|
||||||
|
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error("파일 업로드 실패: {}", originalFileName, ex);
|
||||||
|
throw new ApiException(ApiResponseCode.FILE_UPLOAD_FAILED, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private File createFileEntity(String originalFileName, String storedFileName, Path targetLocation,
|
||||||
|
MultipartFile multipartFile, String description, Long groupOid) {
|
||||||
|
return File.builder()
|
||||||
|
.originalFileName(originalFileName)
|
||||||
|
.storedFileName(storedFileName)
|
||||||
|
.filePath(targetLocation.toString())
|
||||||
|
.fileSize(multipartFile.getSize())
|
||||||
|
.contentType(multipartFile.getContentType())
|
||||||
|
.description(description)
|
||||||
|
.groupOid(groupOid)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getFileByOid(Long oid) {
|
||||||
|
return fileRepository.findByOidAndUseFlagTrue(oid)
|
||||||
|
.orElseThrow(() -> new ApiException(ApiResponseCode.FILE_NOT_FOUND));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] downloadFile(Long oid) {
|
||||||
|
File file = fileRepository.findByOidAndUseFlagTrue(oid)
|
||||||
|
.orElseThrow(() -> new ApiException(ApiResponseCode.FILE_NOT_FOUND));
|
||||||
|
|
||||||
|
try {
|
||||||
|
Path filePath = Paths.get(file.getFilePath());
|
||||||
|
return Files.readAllBytes(filePath);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error("파일 다운로드 실패: {}", file.getOriginalFileName(), ex);
|
||||||
|
throw new ApiException(ApiResponseCode.FILE_DOWNLOAD_FAILED, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void deleteFile(Long oid) {
|
||||||
|
File file = fileRepository.findByOidAndUseFlagTrue(oid)
|
||||||
|
.orElseThrow(() -> new ApiException(ApiResponseCode.FILE_NOT_FOUND));
|
||||||
|
|
||||||
|
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||||
|
// 현재 사용자가 파일 소유자인지 확인
|
||||||
|
if (currentUserId == null || !currentUserId.equals(file.getCreatedId())) {
|
||||||
|
throw new ApiException(ApiResponseCode.COMMON_FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 논리적 삭제: use_flag를 false로 변경
|
||||||
|
file.setUseFlag(false);
|
||||||
|
fileRepository.save(file);
|
||||||
|
|
||||||
|
log.info("파일 논리적 삭제 완료: oid={}, fileName={}", oid, file.getOriginalFileName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.member.controller;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.global.dto.ApiResponseDto;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.MemberDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.GetMemberResponseDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.CreateMemberRequestDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.CreateMemberResponseDto;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.MemberSearchCondition;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.GetMembersRequestDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.GetMembersPagedRequestDto;
|
||||||
|
import com.bio.bio_backend.global.dto.PagedResult;
|
||||||
|
import com.bio.bio_backend.domain.base.member.service.MemberService;
|
||||||
|
import com.bio.bio_backend.domain.base.member.mapper.MemberMapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
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 com.bio.bio_backend.global.constants.ApiResponseCode;
|
||||||
|
import com.bio.bio_backend.global.annotation.LogExecution;
|
||||||
|
import com.bio.bio_backend.global.utils.SecurityUtils;
|
||||||
|
import com.bio.bio_backend.global.utils.JwtUtils;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Tag(name = "Member", description = "회원 관련 API")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/members")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class MemberController {
|
||||||
|
|
||||||
|
private final MemberService memberService;
|
||||||
|
private final MemberMapper memberMapper;
|
||||||
|
private final JwtUtils jwtUtils;
|
||||||
|
|
||||||
|
@LogExecution("회원 등록")
|
||||||
|
@Operation(summary = "회원 등록", description = "새로운 회원을 등록합니다.")
|
||||||
|
@ApiResponses({
|
||||||
|
@ApiResponse(responseCode = "201", description = "회원 가입 성공"),
|
||||||
|
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||||
|
@ApiResponse(responseCode = "409", description = "중복된 사용자 정보", content = @Content)
|
||||||
|
})
|
||||||
|
@PostMapping("/register")
|
||||||
|
public ResponseEntity<ApiResponseDto<CreateMemberResponseDto>> createMember(@RequestBody @Valid CreateMemberRequestDto requestDto) {
|
||||||
|
MemberDto createdMember = memberService.createMember(memberMapper.toMemberDto(requestDto));
|
||||||
|
CreateMemberResponseDto responseDto = memberMapper.toCreateMemberResponseDto(createdMember);
|
||||||
|
ApiResponseDto<CreateMemberResponseDto> 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)
|
||||||
|
})
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<ApiResponseDto<List<GetMemberResponseDto>>> getMembers(@ModelAttribute GetMembersRequestDto requestDto) {
|
||||||
|
MemberSearchCondition condition = memberMapper.toSearchCondition(requestDto);
|
||||||
|
List<GetMemberResponseDto> members = memberService.getMembers(condition);
|
||||||
|
ApiResponseDto<List<GetMemberResponseDto>> apiResponse = ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS, members);
|
||||||
|
log.info("회원 목록 조회 완료: {}명", members.size());
|
||||||
|
|
||||||
|
return ResponseEntity.ok(apiResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@LogExecution("회원 목록 조회 (페이지네이션)")
|
||||||
|
@Operation(summary = "회원 목록 조회 (페이지네이션)", description = "페이지네이션을 적용한 회원 목록을 조회합니다.")
|
||||||
|
@ApiResponses({
|
||||||
|
@ApiResponse(responseCode = "200", description = "회원 목록 조회 성공"),
|
||||||
|
@ApiResponse(responseCode = "400", description = "잘못된 요청 파라미터", content = @Content)
|
||||||
|
})
|
||||||
|
@GetMapping("/paged")
|
||||||
|
public ResponseEntity<ApiResponseDto<PagedResult<GetMemberResponseDto>>> getMembersPaged(@ModelAttribute GetMembersPagedRequestDto requestDto) {
|
||||||
|
MemberSearchCondition condition = memberMapper.toSearchCondition(requestDto);
|
||||||
|
PagedResult<GetMemberResponseDto> pagedMembers = memberService.getMembersPaged(condition, requestDto.getPage(), requestDto.getSize());
|
||||||
|
ApiResponseDto<PagedResult<GetMemberResponseDto>> apiResponse = ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS, pagedMembers);
|
||||||
|
log.info("페이지네이션된 회원 목록 조회 완료: 페이지={}, 크기={}, 전체={}명", requestDto.getPage(), requestDto.getSize(), pagedMembers.getTotalElements());
|
||||||
|
|
||||||
|
return ResponseEntity.ok(apiResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@LogExecution("로그아웃")
|
||||||
|
@Operation(summary = "로그아웃", description = "사용자 로그아웃을 처리합니다.")
|
||||||
|
@ApiResponses({
|
||||||
|
@ApiResponse(responseCode = "200", description = "로그아웃 성공")
|
||||||
|
})
|
||||||
|
@PostMapping("/logout")
|
||||||
|
public ResponseEntity<ApiResponseDto<Void>> logout(HttpServletResponse response) {
|
||||||
|
String userId = SecurityUtils.getCurrentUserId();
|
||||||
|
memberService.deleteRefreshToken(userId);
|
||||||
|
// 모든 토큰 쿠키 삭제
|
||||||
|
jwtUtils.deleteAllTokenCookies(response);
|
||||||
|
log.info("사용자 로그아웃 완료: {}", userId);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.bio.bio_backend.domain.user.member.dto;
|
package com.bio.bio_backend.domain.base.member.dto;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -6,6 +6,7 @@ import lombok.Data;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.Email;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@@ -18,4 +19,11 @@ public class CreateMemberRequestDto {
|
|||||||
|
|
||||||
@NotBlank(message = "비밀번호는 필수입니다.")
|
@NotBlank(message = "비밀번호는 필수입니다.")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
@NotBlank(message = "사용자명은 필수입니다.")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@NotBlank(message = "이메일은 필수입니다.")
|
||||||
|
@Email(message = "올바른 이메일 형식이 아닙니다.")
|
||||||
|
private String email;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.bio.bio_backend.domain.user.member.dto;
|
package com.bio.bio_backend.domain.base.member.dto;
|
||||||
|
|
||||||
import com.bio.bio_backend.domain.user.member.enums.MemberRole;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -16,7 +15,6 @@ public class CreateMemberResponseDto {
|
|||||||
|
|
||||||
private Long oid;
|
private Long oid;
|
||||||
private String userId;
|
private String userId;
|
||||||
private MemberRole role;
|
|
||||||
private Boolean useFlag;
|
private Boolean useFlag;
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
private LocalDateTime updatedAt;
|
private LocalDateTime updatedAt;
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.member.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 회원 조회용 Response DTO
|
||||||
|
* 민감한 정보(password, refreshToken, loginIp)는 제외하고 안전한 정보만 포함
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class GetMemberResponseDto {
|
||||||
|
|
||||||
|
private Long oid;
|
||||||
|
private String userId;
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
private Boolean useFlag;
|
||||||
|
private LocalDateTime lastLoginAt;
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.member.dto;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.global.dto.BasePagedRequestDto;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 회원 목록 조회 요청용 DTO (검색 조건 + 페이지네이션 포함)
|
||||||
|
* GET /members/paged
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class GetMembersPagedRequestDto extends BasePagedRequestDto {
|
||||||
|
|
||||||
|
private String userId;
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
private String searchKeyword;
|
||||||
|
private String createdDateFrom;
|
||||||
|
private String createdDateTo;
|
||||||
|
private String lastLoginFrom;
|
||||||
|
private String lastLoginTo;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.member.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 회원 목록 조회 요청용 DTO (검색 조건만 포함)
|
||||||
|
* GET /members
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class GetMembersRequestDto {
|
||||||
|
|
||||||
|
private String userId;
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
private String searchKeyword;
|
||||||
|
private String createdDateFrom;
|
||||||
|
private String createdDateTo;
|
||||||
|
private String lastLoginFrom;
|
||||||
|
private String lastLoginTo;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.bio.bio_backend.domain.user.member.dto;
|
package com.bio.bio_backend.domain.base.member.dto;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.bio.bio_backend.domain.user.member.dto;
|
package com.bio.bio_backend.domain.base.member.dto;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -14,6 +14,6 @@ import java.time.LocalDateTime;
|
|||||||
public class LoginResponseDto {
|
public class LoginResponseDto {
|
||||||
|
|
||||||
private String userId;
|
private String userId;
|
||||||
private String role;
|
private String name;
|
||||||
private LocalDateTime lastLoginAt;
|
private LocalDateTime lastLoginAt;
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
package com.bio.bio_backend.domain.user.member.dto;
|
package com.bio.bio_backend.domain.base.member.dto;
|
||||||
|
|
||||||
import com.bio.bio_backend.domain.user.member.enums.MemberRole;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -22,16 +20,18 @@ public class MemberDto implements UserDetails {
|
|||||||
private Long oid;
|
private Long oid;
|
||||||
private String userId;
|
private String userId;
|
||||||
private String password;
|
private String password;
|
||||||
private MemberRole role;
|
private String name;
|
||||||
|
private String email;
|
||||||
private Boolean useFlag;
|
private Boolean useFlag;
|
||||||
private String refreshToken;
|
private String refreshToken;
|
||||||
|
private String loginIp;
|
||||||
private LocalDateTime lastLoginAt;
|
private LocalDateTime lastLoginAt;
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
private LocalDateTime updatedAt;
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
return Collections.singletonList(new SimpleGrantedAuthority("ROLE_" + this.role.getValue()));
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -39,21 +39,11 @@ public class MemberDto implements UserDetails {
|
|||||||
return this.userId;
|
return this.userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAccountNonExpired() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAccountNonLocked() {
|
public boolean isAccountNonLocked() {
|
||||||
return this.useFlag != null && this.useFlag;
|
return this.useFlag != null && this.useFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCredentialsNonExpired() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return this.useFlag != null && this.useFlag;
|
return this.useFlag != null && this.useFlag;
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.member.dto;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 회원 검색 조건
|
||||||
|
*/
|
||||||
|
@Builder
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class MemberSearchCondition {
|
||||||
|
|
||||||
|
private String userId;
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
private String searchKeyword;
|
||||||
|
private String createdDateFrom;
|
||||||
|
private String createdDateTo;
|
||||||
|
private String lastLoginFrom;
|
||||||
|
private String lastLoginTo;
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.bio.bio_backend.domain.user.member.entity;
|
package com.bio.bio_backend.domain.base.member.entity;
|
||||||
|
|
||||||
import com.bio.bio_backend.domain.user.member.enums.MemberRole;
|
import com.bio.bio_backend.global.constants.AppConstants;
|
||||||
import com.bio.bio_backend.global.entity.BaseEntity;
|
import com.bio.bio_backend.global.entity.BaseEntity;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -11,13 +11,15 @@ import lombok.Setter;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Builder
|
@Builder
|
||||||
@Table(
|
@Table(
|
||||||
name = "st_member",
|
name = AppConstants.TABLE_PREFIX + "member",
|
||||||
indexes = {
|
indexes = {
|
||||||
@Index(name = "idx_member_user_id", columnList = "user_id")
|
@Index(name = "idx_member_user_id", columnList = "user_id")
|
||||||
}
|
}
|
||||||
@@ -25,23 +27,36 @@ import java.time.LocalDateTime;
|
|||||||
public class Member extends BaseEntity {
|
public class Member extends BaseEntity {
|
||||||
|
|
||||||
@Column(name = "user_id", nullable = false, length = 100)
|
@Column(name = "user_id", nullable = false, length = 100)
|
||||||
|
@Comment("사용자 ID")
|
||||||
private String userId;
|
private String userId;
|
||||||
|
|
||||||
@Column(name = "password", nullable = false, length = 100)
|
@Column(name = "password", nullable = false, length = 100)
|
||||||
|
@Comment("비밀번호")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@Enumerated(EnumType.STRING)
|
@Column(name = "name", nullable = false, length = 100)
|
||||||
@Column(name = "role", nullable = false, length = 40)
|
@Comment("이름")
|
||||||
private MemberRole role;
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "email", nullable = false, length = 255)
|
||||||
|
@Comment("이메일")
|
||||||
|
private String email;
|
||||||
|
|
||||||
@Column(name = "use_flag", nullable = false)
|
@Column(name = "use_flag", nullable = false)
|
||||||
|
@Comment("사용 여부")
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private Boolean useFlag = true;
|
private Boolean useFlag = true;
|
||||||
|
|
||||||
@Column(name = "refresh_token", length = 200)
|
@Column(name = "refresh_token", length = 1024)
|
||||||
|
@Comment("리프레시 토큰")
|
||||||
private String refreshToken;
|
private String refreshToken;
|
||||||
|
|
||||||
|
@Column(name = "login_ip", length = 45) // IPv6 지원을 위해 45자
|
||||||
|
@Comment("로그인 IP")
|
||||||
|
private String loginIp;
|
||||||
|
|
||||||
@Column(name = "last_login_at")
|
@Column(name = "last_login_at")
|
||||||
|
@Comment("마지막 로그인 일시")
|
||||||
private LocalDateTime lastLoginAt;
|
private LocalDateTime lastLoginAt;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.member.mapper;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.CreateMemberRequestDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.CreateMemberResponseDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.LoginResponseDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.MemberDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.MemberSearchCondition;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.GetMembersRequestDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.GetMembersPagedRequestDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.GetMemberResponseDto;
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
|
@Mapper(config = GlobalMapperConfig.class)
|
||||||
|
public interface MemberMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CreateMemberRequestDto를 MemberDto로 변환
|
||||||
|
* 기본값 설정: useFlag = true
|
||||||
|
*/
|
||||||
|
@Mapping(target = "oid", ignore = true)
|
||||||
|
@Mapping(target = "useFlag", constant = "true")
|
||||||
|
@Mapping(target = "refreshToken", ignore = true)
|
||||||
|
@Mapping(target = "loginIp", ignore = true)
|
||||||
|
@Mapping(target = "lastLoginAt", ignore = true)
|
||||||
|
@Mapping(target = "createdAt", ignore = true)
|
||||||
|
@Mapping(target = "updatedAt", ignore = true)
|
||||||
|
MemberDto toMemberDto(CreateMemberRequestDto requestDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Member 엔티티를 MemberDto로 변환
|
||||||
|
*/
|
||||||
|
MemberDto toMemberDto(Member member);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MemberDto를 Member 엔티티로 변환
|
||||||
|
*/
|
||||||
|
Member toMember(MemberDto memberDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Member 엔티티 리스트를 MemberDto 리스트로 변환
|
||||||
|
*/
|
||||||
|
List<MemberDto> toMemberDtoList(List<Member> members);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MemberDto를 CreateMemberResponseDto로 변환
|
||||||
|
*/
|
||||||
|
CreateMemberResponseDto toCreateMemberResponseDto(MemberDto memberDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MemberDto의 값으로 기존 Member 엔티티 업데이트 (null이 아닌 필드만)
|
||||||
|
*/
|
||||||
|
@IgnoreBaseEntityMapping
|
||||||
|
void updateMemberFromDto(MemberDto memberDto, @org.mapstruct.MappingTarget Member member);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MemberDto를 LoginResponseDto로 변환
|
||||||
|
*/
|
||||||
|
LoginResponseDto toLoginResponseDto(MemberDto memberDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Member 엔티티를 GetMemberResponseDto로 변환 (민감한 정보 제외)
|
||||||
|
*/
|
||||||
|
GetMemberResponseDto toGetMemberResponseDto(Member member);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Member 엔티티 리스트를 GetMemberResponseDto 리스트로 변환 (민감한 정보 제외)
|
||||||
|
*/
|
||||||
|
List<GetMemberResponseDto> toGetMemberResponseDtoList(List<Member> members);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetMembersRequestDto를 MemberSearchCondition으로 변환
|
||||||
|
*/
|
||||||
|
MemberSearchCondition toSearchCondition(GetMembersRequestDto request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetMembersPagedRequestDto를 MemberSearchCondition으로 변환
|
||||||
|
*/
|
||||||
|
MemberSearchCondition toSearchCondition(GetMembersPagedRequestDto request);
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.member.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.member.entity.Member;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface MemberRepository extends JpaRepository<Member, Long>, MemberRepositoryCustom {
|
||||||
|
|
||||||
|
// 사용자 ID 존재 여부 확인
|
||||||
|
boolean existsByUserId(String userId);
|
||||||
|
|
||||||
|
// 활성화된 회원 목록 조회
|
||||||
|
List<Member> findByUseFlagTrue();
|
||||||
|
|
||||||
|
// 활성화된 회원 목록 조회 (페이지네이션)
|
||||||
|
Page<Member> findByUseFlagTrue(Pageable pageable);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.member.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.MemberSearchCondition;
|
||||||
|
import com.bio.bio_backend.domain.base.member.entity.Member;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface MemberRepositoryCustom {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 활성화된 사용자 중에서 사용자 ID로 검색하여 조회합니다.
|
||||||
|
*
|
||||||
|
* @param userId 사용자 ID
|
||||||
|
* @return Optional<Member> 회원 정보 (없으면 empty)
|
||||||
|
*/
|
||||||
|
Optional<Member> findActiveMemberByUserId(String userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryDSL을 사용한 회원 목록 조회 (검색 조건 + 페이징)
|
||||||
|
*
|
||||||
|
* @param condition 검색 조건
|
||||||
|
* @param pageable 페이징 정보
|
||||||
|
* @return Page<Member> 검색된 회원 목록
|
||||||
|
*/
|
||||||
|
Page<Member> findMembers(MemberSearchCondition condition, Pageable pageable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryDSL을 사용한 회원 목록 조회 (검색 조건)
|
||||||
|
*
|
||||||
|
* @param condition 검색 조건
|
||||||
|
* @return List<Member> 검색된 회원 목록
|
||||||
|
*/
|
||||||
|
List<Member> findMembers(MemberSearchCondition condition);
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.member.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.MemberSearchCondition;
|
||||||
|
import com.bio.bio_backend.domain.base.member.entity.Member;
|
||||||
|
import com.bio.bio_backend.domain.base.member.entity.QMember;
|
||||||
|
import com.querydsl.core.BooleanBuilder;
|
||||||
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryDSL을 활용하여 MemberRepositoryCustom 인터페이스를 구현하는 클래스
|
||||||
|
* 복잡한 쿼리나 동적 쿼리를 QueryDSL로 작성하여 성능과 가독성을 향상시킵니다.
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MemberRepositoryImpl implements MemberRepositoryCustom {
|
||||||
|
|
||||||
|
private final JPAQueryFactory queryFactory;
|
||||||
|
private final QMember member = QMember.member;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Member> findActiveMemberByUserId(String userId) {
|
||||||
|
// 활성화된 사용자 중에서 사용자 ID로 검색
|
||||||
|
Member foundMember = queryFactory
|
||||||
|
.selectFrom(member)
|
||||||
|
.where(member.userId.eq(userId)
|
||||||
|
.and(member.useFlag.eq(true)))
|
||||||
|
.fetchOne();
|
||||||
|
|
||||||
|
return Optional.ofNullable(foundMember);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<Member> findMembers(MemberSearchCondition condition, Pageable pageable) {
|
||||||
|
BooleanBuilder builder = buildSearchConditions(condition);
|
||||||
|
|
||||||
|
List<Member> members = queryFactory
|
||||||
|
.selectFrom(member)
|
||||||
|
.where(builder)
|
||||||
|
.orderBy(member.createdAt.desc())
|
||||||
|
.offset(pageable.getOffset())
|
||||||
|
.limit(pageable.getPageSize())
|
||||||
|
.fetch();
|
||||||
|
|
||||||
|
Long total = queryFactory
|
||||||
|
.select(member.count())
|
||||||
|
.from(member)
|
||||||
|
.where(builder)
|
||||||
|
.fetchOne();
|
||||||
|
|
||||||
|
return new PageImpl<>(members, pageable, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Member> findMembers(MemberSearchCondition condition) {
|
||||||
|
return queryFactory
|
||||||
|
.selectFrom(member)
|
||||||
|
.where(buildSearchConditions(condition))
|
||||||
|
.orderBy(member.createdAt.desc())
|
||||||
|
.fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 검색 조건들을 조합하여 BooleanBuilder 생성
|
||||||
|
*/
|
||||||
|
private BooleanBuilder buildSearchConditions(MemberSearchCondition condition) {
|
||||||
|
BooleanBuilder builder = new BooleanBuilder();
|
||||||
|
|
||||||
|
// 기본 조건: useFlag = true (활성화된 회원만 조회)
|
||||||
|
builder.and(member.useFlag.eq(true));
|
||||||
|
|
||||||
|
// 사용자 ID (정확 일치)
|
||||||
|
if (StringUtils.hasText(condition.getUserId())) {
|
||||||
|
builder.and(member.userId.eq(condition.getUserId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 이름 (부분 일치)
|
||||||
|
if (StringUtils.hasText(condition.getName())) {
|
||||||
|
builder.and(member.name.containsIgnoreCase(condition.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 이메일 (부분 일치)
|
||||||
|
if (StringUtils.hasText(condition.getEmail())) {
|
||||||
|
builder.and(member.email.containsIgnoreCase(condition.getEmail()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 통합 검색 키워드 (이름, 이메일, 사용자ID에서 검색)
|
||||||
|
if (StringUtils.hasText(condition.getSearchKeyword())) {
|
||||||
|
String keyword = condition.getSearchKeyword();
|
||||||
|
builder.and(member.name.containsIgnoreCase(keyword)
|
||||||
|
.or(member.email.containsIgnoreCase(keyword))
|
||||||
|
.or(member.userId.containsIgnoreCase(keyword)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 생성일 범위
|
||||||
|
if (StringUtils.hasText(condition.getCreatedDateFrom())) {
|
||||||
|
LocalDate fromDate = LocalDate.parse(condition.getCreatedDateFrom(), DateTimeFormatter.ISO_LOCAL_DATE);
|
||||||
|
builder.and(member.createdAt.goe(fromDate.atStartOfDay()));
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(condition.getCreatedDateTo())) {
|
||||||
|
LocalDate toDate = LocalDate.parse(condition.getCreatedDateTo(), DateTimeFormatter.ISO_LOCAL_DATE);
|
||||||
|
builder.and(member.createdAt.loe(toDate.atTime(23, 59, 59)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 마지막 로그인 범위
|
||||||
|
if (StringUtils.hasText(condition.getLastLoginFrom())) {
|
||||||
|
LocalDate fromDate = LocalDate.parse(condition.getLastLoginFrom(), DateTimeFormatter.ISO_LOCAL_DATE);
|
||||||
|
builder.and(member.lastLoginAt.goe(fromDate.atStartOfDay()));
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(condition.getLastLoginTo())) {
|
||||||
|
LocalDate toDate = LocalDate.parse(condition.getLastLoginTo(), DateTimeFormatter.ISO_LOCAL_DATE);
|
||||||
|
builder.and(member.lastLoginAt.loe(toDate.atTime(23, 59, 59)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.member.scheduler;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.MemberDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.service.MemberService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 멤버 동기화 스케줄러
|
||||||
|
* ShedLock을 사용하여 분산 환경에서 중복 실행을 방지합니다.
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class MemberSyncScheduler {
|
||||||
|
|
||||||
|
private final MemberService memberService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1시간마다 멤버 동기화를 실행합니다.
|
||||||
|
* 현재는 더미 데이터를 생성하지만, 추후 실제 조직도 연동으로 변경 예정입니다.
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 * * * *") // 1시간마다
|
||||||
|
@SchedulerLock(name = "memberSync", lockAtMostFor = "50m", lockAtLeastFor = "5m")
|
||||||
|
public void syncMembersAtTopOfHour() {
|
||||||
|
log.info("1시간마다 멤버 동기화 시작");
|
||||||
|
try {
|
||||||
|
int createdCount = createDummyMembers(5); // 1시간마다 5명씩 생성
|
||||||
|
log.info("1시간마다 멤버 동기화 완료: {}명 생성", createdCount);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("1시간마다 멤버 동기화 실패: {}", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 매일 새벽 2시에 대량 동기화를 실행합니다.
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 2 * * *") // 매일 새벽 2시
|
||||||
|
@SchedulerLock(name = "memberBulkSync", lockAtMostFor = "30m", lockAtLeastFor = "5m")
|
||||||
|
public void bulkSyncMembers() {
|
||||||
|
log.info("일일 대량 멤버 동기화 시작");
|
||||||
|
try {
|
||||||
|
int createdCount = createDummyMembers(20); // 새벽에 20명씩 생성
|
||||||
|
log.info("일일 대량 멤버 동기화 완료: {}명 생성", createdCount);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("일일 대량 멤버 동기화 실패: {}", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 더미 멤버를 생성합니다.
|
||||||
|
* 추후 실제 조직도 API 연동으로 변경될 예정입니다.
|
||||||
|
*
|
||||||
|
* @param count 생성할 멤버 수
|
||||||
|
* @return 실제 생성된 멤버 수
|
||||||
|
*/
|
||||||
|
private int createDummyMembers(int count) {
|
||||||
|
int createdCount = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
try {
|
||||||
|
String randomSuffix = String.valueOf(System.currentTimeMillis() + i);
|
||||||
|
|
||||||
|
MemberDto memberDto = MemberDto.builder()
|
||||||
|
.userId("user_" + randomSuffix)
|
||||||
|
.password("password123") // 실제로는 더 복잡한 패스워드 생성
|
||||||
|
.name(generateRandomName())
|
||||||
|
.email("user_" + randomSuffix + "@company.com")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
memberService.createMember(memberDto);
|
||||||
|
createdCount++;
|
||||||
|
|
||||||
|
log.debug("더미 멤버 생성 완료: {}", memberDto.getUserId());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("더미 멤버 생성 실패 ({}번째): {}", i + 1, e.getMessage());
|
||||||
|
// 개별 멤버 생성 실패는 전체 프로세스를 중단하지 않음
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return createdCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 랜덤한 이름을 생성합니다.
|
||||||
|
* 실제 환경에서는 조직도에서 가져온 실제 이름을 사용합니다.
|
||||||
|
*
|
||||||
|
* @return 생성된 랜덤 이름
|
||||||
|
*/
|
||||||
|
private String generateRandomName() {
|
||||||
|
String[] surnames = {"김", "이", "박", "최", "정", "강", "조", "윤", "장", "임"};
|
||||||
|
String[] givenNames = {"민수", "지영", "현우", "수진", "태현", "은지", "동훈", "예린", "준호", "서연"};
|
||||||
|
|
||||||
|
String surname = surnames[ThreadLocalRandom.current().nextInt(surnames.length)];
|
||||||
|
String givenName = givenNames[ThreadLocalRandom.current().nextInt(givenNames.length)];
|
||||||
|
|
||||||
|
return surname + givenName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.member.service;
|
||||||
|
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.MemberDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.GetMemberResponseDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.MemberSearchCondition;
|
||||||
|
import com.bio.bio_backend.global.dto.PagedResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface MemberService extends UserDetailsService {
|
||||||
|
|
||||||
|
UserDetails loadUserByUsername(String id);
|
||||||
|
|
||||||
|
MemberDto createMember(MemberDto memberDTO);
|
||||||
|
|
||||||
|
String getRefreshToken(String id);
|
||||||
|
|
||||||
|
void deleteRefreshToken(String id);
|
||||||
|
|
||||||
|
void updateMember(MemberDto member);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 검색 조건에 따른 회원 목록 조회
|
||||||
|
* @param condition 검색 조건
|
||||||
|
* @return GetMemberResponseDto 리스트
|
||||||
|
*/
|
||||||
|
List<GetMemberResponseDto> getMembers(MemberSearchCondition condition);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 페이지네이션된 회원 목록 조회
|
||||||
|
* @param condition 검색 조건
|
||||||
|
* @param page 페이지 번호
|
||||||
|
* @param size 페이지 크기
|
||||||
|
* @return PagedResult<GetMemberResponseDto> 페이지네이션된 회원 목록
|
||||||
|
*/
|
||||||
|
PagedResult<GetMemberResponseDto> getMembersPaged(MemberSearchCondition condition, int page, int size);
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.member.service;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.MemberDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.GetMemberResponseDto;
|
||||||
|
import com.bio.bio_backend.domain.base.member.dto.MemberSearchCondition;
|
||||||
|
import com.bio.bio_backend.global.dto.PagedResult;
|
||||||
|
import com.bio.bio_backend.domain.base.member.entity.Member;
|
||||||
|
import com.bio.bio_backend.domain.base.member.mapper.MemberMapper;
|
||||||
|
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;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class MemberServiceImpl implements MemberService {
|
||||||
|
|
||||||
|
private final MemberMapper memberMapper; // MapStruct Mapper 사용
|
||||||
|
private final MemberRepository memberRepository;
|
||||||
|
private final BCryptPasswordEncoder bCryptPasswordEncoder;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException {
|
||||||
|
Member member = memberRepository.findActiveMemberByUserId(id)
|
||||||
|
.orElseThrow(() -> new UsernameNotFoundException("사용자를 찾을 수 없습니다: " + id));
|
||||||
|
return memberMapper.toMemberDto(member);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public MemberDto createMember(MemberDto memberDto) {
|
||||||
|
// userId 중복 체크
|
||||||
|
if (memberRepository.existsByUserId(memberDto.getUserId())) {
|
||||||
|
throw new ApiException(ApiResponseCode.USER_ID_DUPLICATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
Member member = Member.builder()
|
||||||
|
.userId(memberDto.getUserId())
|
||||||
|
.password(bCryptPasswordEncoder.encode(memberDto.getPassword()))
|
||||||
|
.name(memberDto.getName())
|
||||||
|
.email(memberDto.getEmail())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
return memberMapper.toMemberDto(savedMember);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void updateMember(MemberDto memberDto) {
|
||||||
|
Member member = memberRepository.findActiveMemberByUserId(memberDto.getUserId())
|
||||||
|
.orElseThrow(() -> new ApiException(ApiResponseCode.USER_NOT_FOUND));
|
||||||
|
|
||||||
|
memberMapper.updateMemberFromDto(memberDto, member);
|
||||||
|
memberRepository.save(member);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRefreshToken(String id) {
|
||||||
|
Member member = memberRepository.findActiveMemberByUserId(id)
|
||||||
|
.orElseThrow(() -> new ApiException(ApiResponseCode.USER_NOT_FOUND));
|
||||||
|
|
||||||
|
return member.getRefreshToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void deleteRefreshToken(String id) {
|
||||||
|
Member member = memberRepository.findActiveMemberByUserId(id)
|
||||||
|
.orElseThrow(() -> new ApiException(ApiResponseCode.USER_NOT_FOUND));
|
||||||
|
|
||||||
|
member.setRefreshToken(null);
|
||||||
|
memberRepository.save(member);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GetMemberResponseDto> getMembers(MemberSearchCondition condition) {
|
||||||
|
List<Member> members = memberRepository.findMembers(condition);
|
||||||
|
|
||||||
|
return memberMapper.toGetMemberResponseDtoList(members);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PagedResult<GetMemberResponseDto> getMembersPaged(MemberSearchCondition condition, int page, int size) {
|
||||||
|
Pageable pageable = PageRequest.of(page, size);
|
||||||
|
Page<Member> memberPage = memberRepository.findMembers(condition, pageable);
|
||||||
|
List<GetMemberResponseDto> members = memberMapper.toGetMemberResponseDtoList(memberPage.getContent());
|
||||||
|
|
||||||
|
return PagedResult.of(memberPage, members);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.memberauthgroup.controller;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.memberauthgroup.dto.MemberAuthGroupDto;
|
||||||
|
import com.bio.bio_backend.domain.base.memberauthgroup.dto.ReplaceMemberAuthGroupsRequest;
|
||||||
|
import com.bio.bio_backend.domain.base.memberauthgroup.service.MemberAuthGroupService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/member_auth_group")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Tag(name = "MemberAuthGroup", description = "")
|
||||||
|
@Slf4j
|
||||||
|
public class MemberAuthGroupController {
|
||||||
|
|
||||||
|
private final MemberAuthGroupService service;
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public MemberAuthGroupDto create(@RequestBody MemberAuthGroupDto dto) {
|
||||||
|
return service.create(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public MemberAuthGroupDto getById(@PathVariable Long id) {
|
||||||
|
return service.getById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<MemberAuthGroupDto> getAll() {
|
||||||
|
return service.getAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public MemberAuthGroupDto update(@PathVariable Long id, @RequestBody MemberAuthGroupDto dto) {
|
||||||
|
return service.update(id, dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public void delete(@PathVariable Long id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/replace")
|
||||||
|
public void replaceMemberAuthGroups(@RequestBody ReplaceMemberAuthGroupsRequest request) {
|
||||||
|
service.replaceMemberAuthGroups(request.getMemberOid(), request.getAuthGroupOids());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.memberauthgroup.dto;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.entity.AuthGroup;
|
||||||
|
import com.bio.bio_backend.domain.base.member.entity.Member;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MemberAuthGroupDto {
|
||||||
|
private Member memberOid;
|
||||||
|
private AuthGroup authGroupOid;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.memberauthgroup.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ReplaceMemberAuthGroupsRequest {
|
||||||
|
private Long memberOid;
|
||||||
|
private List<Long> authGroupOids;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.memberauthgroup.entity;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.entity.AuthGroup;
|
||||||
|
import com.bio.bio_backend.domain.base.member.entity.Member;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Table(name = AppConstants.TABLE_PREFIX + "member_auth_group")
|
||||||
|
public class MemberAuthGroup extends BaseEntity {
|
||||||
|
|
||||||
|
@Comment("사용자 OID")
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "member_oid")
|
||||||
|
private Member memberOid;
|
||||||
|
|
||||||
|
@Comment("권한 그룹 OID")
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "auth_group_oid")
|
||||||
|
private AuthGroup authGroupOid;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.memberauthgroup.mapper;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.global.config.GlobalMapperConfig;
|
||||||
|
import com.bio.bio_backend.domain.base.memberauthgroup.entity.MemberAuthGroup;
|
||||||
|
import com.bio.bio_backend.domain.base.memberauthgroup.dto.MemberAuthGroupDto;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
@Mapper(config = GlobalMapperConfig.class)
|
||||||
|
public interface MemberAuthGroupMapper {
|
||||||
|
MemberAuthGroup toEntity(MemberAuthGroupDto dto);
|
||||||
|
|
||||||
|
MemberAuthGroupDto toDto(MemberAuthGroup entity);
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.memberauthgroup.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.memberauthgroup.entity.MemberAuthGroup;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface MemberAuthGroupRepository
|
||||||
|
extends JpaRepository<MemberAuthGroup, Long>, MemberAuthGroupRepositoryCustom {
|
||||||
|
|
||||||
|
@Modifying
|
||||||
|
@Query("delete from MemberAuthGroup mag where mag.memberOid.oid = :memberOid")
|
||||||
|
void deleteByMemberOid(@Param("memberOid") Long memberOid);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.memberauthgroup.repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryDSL을 활용한 커스텀 쿼리 메서드들을 정의하는 인터페이스
|
||||||
|
* 복잡한 쿼리나 동적 쿼리가 필요한 경우 이 인터페이스를 구현하여 사용합니다.
|
||||||
|
*/
|
||||||
|
public interface MemberAuthGroupRepositoryCustom {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.memberauthgroup.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.memberauthgroup.entity.QMemberAuthGroup;
|
||||||
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryDSL을 활용하여 MemberAuthGroupRepositoryCustom 인터페이스를 구현하는 클래스
|
||||||
|
* 복잡한 쿼리나 동적 쿼리를 QueryDSL로 작성하여 성능과 가독성을 향상시킵니다.
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MemberAuthGroupRepositoryImpl implements MemberAuthGroupRepositoryCustom {
|
||||||
|
|
||||||
|
private final JPAQueryFactory queryFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QMemberAuthGroup 인스턴스를 생성하여 쿼리에서 사용합니다.
|
||||||
|
* QueryDSL의 Q클래스를 통해 타입 안전한 쿼리 작성이 가능합니다.
|
||||||
|
*/
|
||||||
|
private final QMemberAuthGroup memberAuthGroup = QMemberAuthGroup.memberAuthGroup;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.memberauthgroup.service;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.memberauthgroup.dto.MemberAuthGroupDto;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface MemberAuthGroupService {
|
||||||
|
MemberAuthGroupDto create(MemberAuthGroupDto dto);
|
||||||
|
|
||||||
|
MemberAuthGroupDto getById(Long id);
|
||||||
|
|
||||||
|
List<MemberAuthGroupDto> getAll();
|
||||||
|
|
||||||
|
MemberAuthGroupDto update(Long id, MemberAuthGroupDto dto);
|
||||||
|
|
||||||
|
void delete(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 특정 memberOid의 기존 매핑을 모두 삭제하고, 전달된 authGroupOid 목록으로 재등록
|
||||||
|
*/
|
||||||
|
void replaceMemberAuthGroups(Long memberOid, List<Long> authGroupOids);
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.memberauthgroup.service;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.memberauthgroup.dto.MemberAuthGroupDto;
|
||||||
|
import com.bio.bio_backend.domain.base.memberauthgroup.entity.MemberAuthGroup;
|
||||||
|
import com.bio.bio_backend.domain.base.memberauthgroup.repository.MemberAuthGroupRepository;
|
||||||
|
import com.bio.bio_backend.domain.base.memberauthgroup.mapper.MemberAuthGroupMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import com.bio.bio_backend.domain.base.authgroup.entity.AuthGroup;
|
||||||
|
import com.bio.bio_backend.domain.base.member.entity.Member;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class MemberAuthGroupServiceImpl implements MemberAuthGroupService {
|
||||||
|
|
||||||
|
private final MemberAuthGroupRepository repository;
|
||||||
|
private final MemberAuthGroupMapper mapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public MemberAuthGroupDto create(MemberAuthGroupDto dto) {
|
||||||
|
MemberAuthGroup entity = mapper.toEntity(dto);
|
||||||
|
return mapper.toDto(repository.save(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MemberAuthGroupDto getById(Long id) {
|
||||||
|
return repository.findById(id).map(mapper::toDto).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MemberAuthGroupDto> getAll() {
|
||||||
|
return repository.findAll().stream().map(mapper::toDto).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public MemberAuthGroupDto update(Long id, MemberAuthGroupDto dto) {
|
||||||
|
MemberAuthGroup entity = repository.findById(id).orElseThrow();
|
||||||
|
// TODO: update fields
|
||||||
|
return mapper.toDto(repository.save(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void delete(Long id) {
|
||||||
|
repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void replaceMemberAuthGroups(Long memberOid, List<Long> authGroupOids) {
|
||||||
|
repository.deleteByMemberOid(memberOid);
|
||||||
|
|
||||||
|
if (authGroupOids == null || authGroupOids.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Member memberRef = new Member();
|
||||||
|
memberRef.setOid(memberOid);
|
||||||
|
|
||||||
|
for (Long groupOid : authGroupOids) {
|
||||||
|
AuthGroup groupRef = new AuthGroup();
|
||||||
|
groupRef.setOid(groupOid);
|
||||||
|
|
||||||
|
MemberAuthGroup entity = MemberAuthGroup.builder()
|
||||||
|
.memberOid(memberRef)
|
||||||
|
.authGroupOid(groupRef)
|
||||||
|
.build();
|
||||||
|
repository.save(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.resource.controller;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.resource.dto.ResourceDto;
|
||||||
|
import com.bio.bio_backend.domain.base.resource.service.ResourceService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/resource")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Tag(name = "Resource", description = "")
|
||||||
|
@Slf4j
|
||||||
|
public class ResourceController {
|
||||||
|
|
||||||
|
private final ResourceService service;
|
||||||
|
|
||||||
|
@PostMapping("")
|
||||||
|
public ResourceDto create(@RequestBody ResourceDto dto) {
|
||||||
|
return service.createResource(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/list")
|
||||||
|
public List<ResourceDto> createList(@RequestBody List<ResourceDto> list) {
|
||||||
|
return service.createResourceList(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResourceDto getById(@PathVariable Long id) {
|
||||||
|
return service.getById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<ResourceDto> getAll() {
|
||||||
|
return service.getAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public ResourceDto update(@PathVariable Long id, @RequestBody ResourceDto dto) {
|
||||||
|
return service.update(id, dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public void delete(@PathVariable Long id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.resource.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ResourceDto {
|
||||||
|
private String code;
|
||||||
|
private String name;
|
||||||
|
private long parentCode;
|
||||||
|
private String type;
|
||||||
|
private String path;
|
||||||
|
private int sortOrder;
|
||||||
|
private String description;
|
||||||
|
private boolean menuYn;
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.resource.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;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Table(name = AppConstants.TABLE_PREFIX + "resource")
|
||||||
|
public class Resource extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(name = "code", length = 100)
|
||||||
|
@Comment("코드")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@Column(name = "name", length = 100)
|
||||||
|
@Comment("리소스명")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "parent_code")
|
||||||
|
@Comment("부모 코드")
|
||||||
|
private long parentCode;
|
||||||
|
|
||||||
|
@Column(name = "type", length = 50)
|
||||||
|
@Comment("리소스 유형(메뉴, 페이지, 컴포넌트)")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@Column(name = "path", length = 100)
|
||||||
|
@Comment("주소")
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
@Column(name = "sort_order")
|
||||||
|
@Comment("정렬 순서")
|
||||||
|
private int sortOrder;
|
||||||
|
|
||||||
|
@Column(name = "description", length = 255)
|
||||||
|
@Comment("설명")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "menu_yn")
|
||||||
|
@Comment("메뉴여부")
|
||||||
|
private boolean menuYn;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.resource.mapper;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.global.config.GlobalMapperConfig;
|
||||||
|
import com.bio.bio_backend.domain.base.resource.entity.Resource;
|
||||||
|
import com.bio.bio_backend.domain.base.resource.dto.ResourceDto;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
@Mapper(config = GlobalMapperConfig.class)
|
||||||
|
public interface ResourceMapper {
|
||||||
|
Resource toEntity(ResourceDto dto);
|
||||||
|
|
||||||
|
ResourceDto toDto(Resource entity);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.resource.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.resource.entity.Resource;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ResourceRepository extends JpaRepository<Resource, Long>, ResourceRepositoryCustom {
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.bio.bio_backend.domain.base.resource.repository;
|
||||||
|
|
||||||
|
import com.bio.bio_backend.domain.base.resource.entity.Resource;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryDSL을 활용한 커스텀 쿼리 메서드들을 정의하는 인터페이스
|
||||||
|
* 복잡한 쿼리나 동적 쿼리가 필요한 경우 이 인터페이스를 구현하여 사용합니다.
|
||||||
|
*/
|
||||||
|
public interface ResourceRepositoryCustom {
|
||||||
|
|
||||||
|
List<Resource> findResourcesByMemberId(Long memberOId);
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user