-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: body가 없는 응답을 noContent로 수정 * fix: /members 와 /members/details 로 엔드포인트 분리, 반환형 명시 * fix: Dto 변환 메서드명 수정 toDto -> from * feat: Admin 생성 기능 구현 * feat: Admin 전체 조회 기능 구현 * feat: Admin 정보 수정 기능 구현 * feat: Admin 삭제 기능 구현 (soft delete) * fix: AccountBaseEntity 필드 protected로 변경, 업데이트 메서드 추가 * fix: Admin 수정 시 Status를 포함하도록 수정 * fix: 비밀번호 확인 메서드 추출 * feat: CustomException, GlobalExceptionHandler 구현 * feat: 전체 조회 시 페이징 적용 * fix: ApiResponse 오타 수정
- Loading branch information
1 parent
f1d7c8c
commit 9ab3384
Showing
18 changed files
with
402 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
api/api-member/src/main/java/com/pgms/apimember/dto/request/AdminCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.pgms.apimember.dto.request; | ||
|
||
import com.pgms.coredomain.domain.member.Admin; | ||
import com.pgms.coredomain.domain.member.Role; | ||
|
||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Pattern; | ||
import jakarta.validation.constraints.Size; | ||
|
||
public record AdminCreateRequest( | ||
@NotBlank(message = "이름을 입력해주세요.") | ||
@Size(min = 2, max = 50, message = "이름은 2자 이상 50자 이하로 입력해주세요.") | ||
String name, | ||
|
||
@NotBlank(message = "비밀번호를 입력해주세요.") | ||
@Size(min = 6, message = "비밀번호는 6자 이상 입력해주세요.") | ||
String password, | ||
|
||
@NotBlank(message = "비밀번호 확인을 입력해주세요.") | ||
String passwordConfirm, | ||
|
||
@NotBlank(message = "전화번호를 입력해주세요.") | ||
@Pattern(regexp = "\\d+", message = "전화번호는 숫자만 입력해주세요.") | ||
String phoneNumber, | ||
|
||
@NotBlank(message = "이메일을 입력해주세요.") | ||
@Email(message = "이메일 형식에 맞지 않습니다.") | ||
String email, | ||
|
||
@NotBlank(message = "역할을 입력해주세요.") | ||
String roleName | ||
) { | ||
public static Admin toEntity(AdminCreateRequest requestDto, String encodedPassword, Role role) { | ||
return Admin.builder() | ||
.name(requestDto.name()) | ||
.password(encodedPassword) | ||
.phoneNumber(requestDto.phoneNumber()) | ||
.email(requestDto.email()) | ||
.role(role) | ||
.build(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
api/api-member/src/main/java/com/pgms/apimember/dto/request/AdminUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.pgms.apimember.dto.request; | ||
|
||
import com.pgms.coredomain.domain.member.enums.AccountStatus; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Pattern; | ||
import jakarta.validation.constraints.Size; | ||
|
||
public record AdminUpdateRequest( | ||
@NotBlank(message = "이름을 입력해주세요.") | ||
@Size(min = 2, max = 50, message = "이름은 2자 이상 50자 이하로 입력해주세요.") | ||
String name, | ||
|
||
@NotBlank(message = "비밀번호를 입력해주세요.") | ||
@Size(min = 6, message = "비밀번호는 6자 이상 입력해주세요.") | ||
String password, | ||
|
||
@NotBlank(message = "비밀번호 확인을 입력해주세요.") | ||
String passwordConfirm, | ||
|
||
@NotBlank(message = "전화번호를 입력해주세요.") | ||
@Pattern(regexp = "\\d+", message = "전화번호는 숫자만 입력해주세요.") | ||
String phoneNumber, | ||
|
||
@NotBlank(message = "계정 상태를 입력해주세요.") | ||
AccountStatus status, | ||
|
||
@NotBlank(message = "역할을 입력해주세요.") | ||
String roleName | ||
) { | ||
} |
25 changes: 25 additions & 0 deletions
25
api/api-member/src/main/java/com/pgms/apimember/dto/request/PageCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.pgms.apimember.dto.request; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class PageCondition { | ||
private static final Integer DEFAULT_PAGE = 1; | ||
private static final Integer DEFAULT_SIZE = 10; | ||
|
||
private final Integer page; | ||
private final Integer size; | ||
|
||
public PageCondition(Integer page, Integer size) { | ||
this.page = isValidPage(page) ? page : DEFAULT_PAGE; | ||
this.size = isValidSize(size) ? size : DEFAULT_SIZE; | ||
} | ||
|
||
private Boolean isValidPage(Integer page) { | ||
return page != null && page > 0; | ||
} | ||
|
||
private Boolean isValidSize(Integer size) { | ||
return size != null && size > 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
api/api-member/src/main/java/com/pgms/apimember/exception/AdminException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.pgms.apimember.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class AdminException extends CustomException { | ||
|
||
public AdminException(CustomErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
api/api-member/src/main/java/com/pgms/apimember/exception/CustomErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.pgms.apimember.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum CustomErrorCode { | ||
// ADMIN | ||
ADMIN_NOT_FOUND("NOT FOUND", HttpStatus.NOT_FOUND, "존재하지 않는 관리자입니다."), | ||
DUPLICATED_ADMIN_EMAIL("DUPLICATED ADMIN EMAIL", HttpStatus.BAD_REQUEST, "이미 존재하는 관리자 이메일입니다."), | ||
NOT_AUTHORIZED("NOT AUTHORIZED", HttpStatus.UNAUTHORIZED, "접근 권한이 없습니다."), | ||
ADMIN_ROLE_NOT_FOUND("ADMIN ROLE NOT FOUND", HttpStatus.NOT_FOUND, "존재하지 않는 관리자 역할입니다."), | ||
ADMIN_PERMISSION_NOT_FOUND("ADMIN PERMISSION NOT FOUND", HttpStatus.NOT_FOUND, "존재하지 않는 관리자 권한입니다."), | ||
|
||
// MEMBER | ||
MEMBER_NOT_FOUND("NOT FOUND", HttpStatus.NOT_FOUND, "존재하지 않는 회원입니다."), | ||
DUPLICATED_MEMBER_EMAIL("DUPLICATED MEMBER EMAIL", HttpStatus.BAD_REQUEST, "이미 존재하는 회원 이메일입니다."), | ||
NOT_MATCH_PASSWORD("NOT MATCH PASSWORD", HttpStatus.BAD_REQUEST, "비밀번호가 일치하지 않습니다."), | ||
NOT_MATCH_PASSWORD_CONFIRM("NOT MATCH PASSWORD CONFIRM", HttpStatus.BAD_REQUEST, "비밀번호 확인이 일치하지 않습니다."), | ||
VALIDATION_FAILED("VALIDATION FAILED", HttpStatus.BAD_REQUEST, "입력값에 대한 검증에 실패했습니다."); | ||
|
||
private final String errorCode; | ||
private final HttpStatus status; | ||
private final String message; | ||
|
||
CustomErrorCode(String errorCode, HttpStatus status, String message) { | ||
this.errorCode = errorCode; | ||
this.status = status; | ||
this.message = message; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
api/api-member/src/main/java/com/pgms/apimember/exception/CustomException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.pgms.apimember.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CustomException extends RuntimeException { | ||
|
||
protected final CustomErrorCode errorCode; | ||
|
||
public CustomException(CustomErrorCode errorCode) { | ||
super(errorCode.getMessage()); | ||
this.errorCode = errorCode; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
api/api-member/src/main/java/com/pgms/apimember/exception/GlobalExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.pgms.apimember.exception; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.validation.FieldError; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import com.pgms.coredomain.response.ErrorResponse; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(Exception.class) | ||
protected ResponseEntity<ErrorResponse> handleGlobalException(Exception ex) { | ||
log.error(">>>>> Internal Server Error : {}", ex); | ||
ErrorResponse errorResponse = new ErrorResponse("INTERNAL SERVER ERROR", ex.getMessage()); | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); | ||
} | ||
|
||
@ExceptionHandler(CustomException.class) | ||
protected ResponseEntity<ErrorResponse> handleEventCustomException(CustomException ex) { | ||
log.warn(">>>>> Custom Exception : {}", ex); | ||
CustomErrorCode errorCode = ex.getErrorCode(); | ||
ErrorResponse errorResponse = new ErrorResponse(errorCode.getErrorCode(), errorCode.getMessage()); | ||
return ResponseEntity.status(errorCode.getStatus()).body(errorResponse); | ||
} | ||
|
||
@ExceptionHandler(MethodArgumentNotValidException.class) | ||
protected ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(MethodArgumentNotValidException ex) { | ||
log.warn(">>>>> validation Failed : {}", ex); | ||
BindingResult bindingResult = ex.getBindingResult(); | ||
String errorMessage = Objects.requireNonNull(bindingResult.getFieldError()) | ||
.getDefaultMessage(); | ||
|
||
List<FieldError> fieldErrors = bindingResult.getFieldErrors(); | ||
ErrorResponse errorResponse = new ErrorResponse(CustomErrorCode.VALIDATION_FAILED.getErrorCode(), errorMessage); | ||
fieldErrors.forEach(error -> errorResponse.addValidation(error.getField(), error.getDefaultMessage())); | ||
return ResponseEntity.status(ex.getStatusCode()).body(errorResponse); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
api/api-member/src/main/java/com/pgms/apimember/exception/MemberException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.pgms.apimember.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class MemberException extends CustomException { | ||
|
||
public MemberException(CustomErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
Oops, something went wrong.