-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/Sopo2023/SOPO_server_v2
- Loading branch information
Showing
15 changed files
with
298 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## Git Convention | ||
|
||
- feat: 새로운 기능에 대한 커밋 | ||
- fix: 버그 수정에 대한 커밋 | ||
- build: 빌드 관련 파일 수정에 대한 커밋 | ||
- chore: 그 외 자잘한 수정에 대한 커밋 | ||
- ci: CI 관련 설정 수정에 대한 커밋 | ||
- docs: 문서 수정에 대한 커밋 | ||
- style: 코드 스타일 혹은 포맷 등에 관한 커밋 | ||
- refactor: 코드 리팩토링에 대한 커밋 | ||
- test: 테스트 코드 수정에 대한 커밋 | ||
- remove: 코드 삭제에 대한 커밋 |
12 changes: 12 additions & 0 deletions
12
src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/member/entity/MemberEntity.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,12 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.domain.member.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
@Entity | ||
public class MemberEntity { | ||
@Id | ||
@Column(name = "member_id") | ||
private String memberId; | ||
} |
4 changes: 4 additions & 0 deletions
4
...ava/kr/hs/dgsw/SOPO_server_v2/domain/member/presentation/controller/MemberController.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,4 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.domain.member.presentation.controller; | ||
|
||
public class MemberController { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/member/repository/MemberRepository.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,4 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.domain.member.repository; | ||
|
||
public class MemberRepository { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/member/service/MemberService.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,4 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.domain.member.service; | ||
|
||
public class MemberService { | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/kr/hs/dgsw/SOPO_server_v2/global/common/entity/BaseTimeEntity.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,28 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.global.common.entity; | ||
|
||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@SuperBuilder | ||
@MappedSuperclass | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EntityListeners(AuditingEntityListener.class) | ||
public abstract class BaseTimeEntity { | ||
|
||
@CreatedDate | ||
private LocalDateTime createdAt; | ||
|
||
@LastModifiedDate | ||
private LocalDateTime modifiedAt; | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/ErrorResponse.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,38 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.global.error; | ||
|
||
import kr.hs.dgsw.SOPO_server_v2.global.error.exception.StatusEnum; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ErrorResponse { | ||
private String message; | ||
private Integer status; | ||
private LocalDateTime timestamp; | ||
private String description; | ||
|
||
public static ErrorResponse of(StatusEnum errorCode, String description) { | ||
return ErrorResponse.builder() | ||
.message(errorCode.getMessage()) | ||
.status(errorCode.getStatusCode()) | ||
.timestamp(LocalDateTime.now()) | ||
.description(description) | ||
.build(); | ||
} | ||
|
||
public static ErrorResponse of(int statusCode, String description) { | ||
return ErrorResponse.builder() | ||
.message(description) | ||
.status(statusCode) | ||
.timestamp(LocalDateTime.now()) | ||
.description(description) | ||
.build(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/GlobalExceptionFilter.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,44 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.global.error; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import kr.hs.dgsw.SOPO_server_v2.global.error.exception.BusinessException; | ||
import kr.hs.dgsw.SOPO_server_v2.global.error.exception.StatusEnum; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import java.io.IOException; | ||
|
||
@RequiredArgsConstructor | ||
public class GlobalExceptionFilter extends OncePerRequestFilter { | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
@Override | ||
protected void doFilterInternal( | ||
HttpServletRequest request, | ||
HttpServletResponse response, | ||
FilterChain filterChain | ||
)throws IOException { | ||
|
||
try { | ||
filterChain.doFilter(request,response); | ||
} catch (BusinessException e){ | ||
StatusEnum errorCode = e.getErrorCode(); | ||
writerErrorResponse(response, ErrorResponse.of(errorCode, errorCode.getMessage())); | ||
} catch (Exception e){ | ||
writerErrorResponse(response, ErrorResponse.of(response.getStatus(),e.getMessage())); | ||
} | ||
} | ||
|
||
private void writerErrorResponse(HttpServletResponse response, ErrorResponse errorResponse) throws IOException{ | ||
response.setStatus(errorResponse.getStatus()); | ||
response.setContentType(MediaType.APPLICATION_JSON_VALUE); | ||
response.setCharacterEncoding("UTF-8"); | ||
objectMapper.writeValue(response.getWriter(), errorResponse); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/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,51 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.global.error; | ||
|
||
import kr.hs.dgsw.SOPO_server_v2.global.error.exception.BusinessException; | ||
import kr.hs.dgsw.SOPO_server_v2.global.error.exception.StatusEnum; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.hibernate.exception.ConstraintViolationException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
//비즈니스 로직에서의 에러 | ||
@ExceptionHandler(BusinessException.class) | ||
public ResponseEntity<ErrorResponse> handleBusinessException(BusinessException e) { | ||
log.error("CustomException message : {}", e.getMessage()); | ||
|
||
StatusEnum errorCode = e.getErrorCode(); | ||
ErrorResponse response = ErrorResponse.of(errorCode, errorCode.getMessage()); | ||
e.printStackTrace(); | ||
|
||
return new ResponseEntity<>(response, HttpStatus.valueOf(errorCode.getStatusCode())); | ||
} | ||
|
||
// validation 에러 | ||
@ExceptionHandler(ConstraintViolationException.class) | ||
public ResponseEntity<ErrorResponse> handleConstraintViolationException(ConstraintViolationException e) { | ||
|
||
StatusEnum errorCode = StatusEnum.BAD_REQUEST; | ||
ErrorResponse response = ErrorResponse.of(errorCode, errorCode.getMessage()); | ||
e.printStackTrace(); | ||
|
||
return new ResponseEntity<>(response, HttpStatus.valueOf(errorCode.getStatusCode())); | ||
} | ||
|
||
|
||
//그 외 에러들 | ||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<ErrorResponse> handleException(Exception e) { | ||
log.error("에러", e); | ||
|
||
StatusEnum errorCode = StatusEnum.INTERNAL_SERVER_ERROR; | ||
ErrorResponse response = ErrorResponse.of(errorCode, e.getMessage()); | ||
|
||
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/custom/auth/ExpiredTokenException.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 kr.hs.dgsw.SOPO_server_v2.global.error.custom.auth; | ||
|
||
import kr.hs.dgsw.SOPO_server_v2.global.error.exception.BusinessException; | ||
import kr.hs.dgsw.SOPO_server_v2.global.error.exception.StatusEnum; | ||
|
||
public class ExpiredTokenException extends BusinessException { | ||
|
||
public static final BusinessException EXCEPTION = new ExpiredTokenException(); | ||
|
||
public ExpiredTokenException(){ | ||
super(StatusEnum.EXPIRED_TOKEN); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/exception/BusinessException.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,10 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.global.error.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class BusinessException extends RuntimeException { | ||
private final StatusEnum errorCode; | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/exception/StatusEnum.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,55 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.global.error.exception; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@JsonFormat(shape = JsonFormat.Shape.OBJECT) | ||
public enum StatusEnum { | ||
//smtp | ||
NOT_DUPLICATED_AUTH_CODE(400, "Not Duplicated AuthCode"), | ||
EXPIRED_TOKEN(401 , "Expired token"), | ||
INVALID_TOKEN(401, "Invalid token"), | ||
REFRESH_TOKEN_NOT_FOUND(401,"RefreshToken not found"), | ||
MALFORMED_JWT(400, "Jwt is malformed"), | ||
UNSUPPORTED_JWT(400, "Jwt is unsupported"), | ||
ILLEGAL_ARGUMENT(400, "IllegalArgumentException occurred"), | ||
|
||
// general | ||
OK(200,"OK"), | ||
CREATED(201,"Created"), | ||
BAD_REQUEST(400, "Bad request"), | ||
INTERNAL_SERVER_ERROR(500, "Internal server error"), | ||
|
||
//user | ||
MEMBER_NOT_EXISTS(403, "Member Not exists"), | ||
MEMBER_EXISTS(403, "Member exists"), | ||
USER_NOT_COINCIDE(401, "User not coincide"), | ||
USER_NOT_FOUND(404, "User not found"), | ||
NOT_AUTHENTICATED(401, "NotAuthenticated"), | ||
PERMISSION_DENIED(403, "Permission denied"), | ||
WITHDRAWAL_MEMBER(400, "Withdrawal member"), | ||
|
||
//file | ||
FILE_NOT_FOUND(404,"File not found"), | ||
FILE_EXISTS(403,"File exists"), | ||
|
||
UNABLE_TO_SEND_EMAIL(403,"Unable to send email"), | ||
|
||
CHILD_CODE_OVER_USE_TWO(400, "CHILD_CODE_OVER_USE_TWO"), | ||
CHILD_CODE_NOT_FOUND(404, "Child code not found"), | ||
CATEGORY_NOT_FOUND(404,"Category not found"), | ||
IS_NOT_PARENT(400, "is not parent account"), | ||
|
||
//fcm | ||
MESSAGE_SEND_FAILED(403,"Message send failed"), | ||
TOKEN_NOT_PROVIDED(400, "잘못된 토큰"), | ||
CLOUD_EXCEPTION(500,"클라우드 에러") | ||
; | ||
|
||
private final int statusCode; | ||
private final String message; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/kr/hs/dgsw/SOPO_server_v2/global/response/Response.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,9 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.global.response; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public record Response(int status, String message) { | ||
public static Response of(HttpStatus status, String message) { | ||
return new Response(status.value(), message); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/kr/hs/dgsw/SOPO_server_v2/global/response/ResponseData.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,13 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.global.response; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public record ResponseData<T>( | ||
int status, | ||
String message, | ||
T data | ||
) { | ||
public static <T> ResponseData<T> of(HttpStatus status, String message, T data) { | ||
return new ResponseData<>(status.value(), message, data); | ||
} | ||
} |