-
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 pull request #25 from Central-MakeUs/feature/kakao-login
feat: 카카오 로그인, 회원탈퇴, JWT 재발급 API 구현
- Loading branch information
Showing
21 changed files
with
353 additions
and
191 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
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
8 changes: 4 additions & 4 deletions
8
packy-api/src/main/java/com/dilly/auth/dto/request/SignupRequest.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
80 changes: 46 additions & 34 deletions
80
packy-api/src/main/java/com/dilly/global/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 |
---|---|---|
@@ -1,48 +1,60 @@ | ||
package com.dilly.global.exception; | ||
|
||
import com.dilly.global.response.ErrorCode; | ||
import com.dilly.global.response.ErrorResponseDto; | ||
import java.sql.SQLException; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import org.springframework.dao.DataIntegrityViolationException; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.HttpRequestMethodNotSupportedException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import org.springframework.web.servlet.resource.NoResourceFoundException; | ||
|
||
import com.dilly.global.response.ErrorCode; | ||
import com.dilly.global.response.ErrorResponseDto; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@RestControllerAdvice | ||
@Slf4j | ||
public class GlobalExceptionHandler { | ||
|
||
// 비즈니스 예외 처리 | ||
@ExceptionHandler(BusinessException.class) | ||
protected ResponseEntity<Object> handleBusinessException(BusinessException e) { | ||
log.error(e.toString(), e); | ||
return handleExceptionInternal(e.getErrorCode()); | ||
} | ||
|
||
// 지원하지 않는 HTTP method를 호출할 경우 | ||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class) | ||
protected ResponseEntity<Object> handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { | ||
log.error("HttpRequestMethodNotSupportedException : {}", e.getMessage()); | ||
return handleExceptionInternal(ErrorCode.METHOD_NOT_ALLOWED); | ||
} | ||
|
||
// 그 밖에 발생하는 모든 예외 처리 | ||
@ExceptionHandler(value = {Exception.class, RuntimeException.class, SQLException.class, DataIntegrityViolationException.class}) | ||
protected ResponseEntity<Object> handleException(Exception e) { | ||
log.error(e.toString(), e); | ||
|
||
return handleExceptionInternal(ErrorCode.INTERNAL_ERROR, e); | ||
} | ||
|
||
private ResponseEntity<Object> handleExceptionInternal(ErrorCode errorCode) { | ||
return ResponseEntity.status(errorCode.getHttpStatus()) | ||
.body(ErrorResponseDto.from(errorCode)); | ||
} | ||
|
||
private ResponseEntity<Object> handleExceptionInternal(ErrorCode errorCode, Exception e) { | ||
return ResponseEntity.status(errorCode.getHttpStatus()) | ||
.body(ErrorResponseDto.of(errorCode, e)); | ||
} | ||
// 비즈니스 예외 처리 | ||
@ExceptionHandler(BusinessException.class) | ||
protected ResponseEntity<Object> handleBusinessException(BusinessException e) { | ||
log.error(e.toString(), e); | ||
return handleExceptionInternal(e.getErrorCode()); | ||
} | ||
|
||
// 지원하지 않는 HTTP method를 호출할 경우 | ||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class) | ||
protected ResponseEntity<Object> handleHttpRequestMethodNotSupportedException( | ||
HttpRequestMethodNotSupportedException e) { | ||
log.error("HttpRequestMethodNotSupportedException : {}", e.getMessage()); | ||
return handleExceptionInternal(ErrorCode.METHOD_NOT_ALLOWED); | ||
} | ||
|
||
// 존재하지 않는 URI에 접근할 경우 | ||
@ExceptionHandler(NoResourceFoundException.class) | ||
protected ResponseEntity<Object> handleNoResourceFoundException(NoResourceFoundException e) { | ||
return handleExceptionInternal(ErrorCode.API_NOT_FOUND); | ||
} | ||
|
||
// 그 밖에 발생하는 모든 예외 처리 | ||
@ExceptionHandler(value = {Exception.class, RuntimeException.class, SQLException.class, | ||
DataIntegrityViolationException.class}) | ||
protected ResponseEntity<Object> handleException(Exception e) { | ||
log.error(e.toString(), e); | ||
|
||
return handleExceptionInternal(ErrorCode.INTERNAL_ERROR, e); | ||
} | ||
|
||
private ResponseEntity<Object> handleExceptionInternal(ErrorCode errorCode) { | ||
return ResponseEntity.status(errorCode.getHttpStatus()) | ||
.body(ErrorResponseDto.from(errorCode)); | ||
} | ||
|
||
private ResponseEntity<Object> handleExceptionInternal(ErrorCode errorCode, Exception e) { | ||
return ResponseEntity.status(errorCode.getHttpStatus()) | ||
.body(ErrorResponseDto.of(errorCode, e)); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
packy-api/src/main/java/com/dilly/global/utils/SecurityUtil.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,24 @@ | ||
package com.dilly.global.utils; | ||
|
||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
import com.dilly.global.exception.AuthorizationFailedException; | ||
import com.dilly.global.response.ErrorCode; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class SecurityUtil { | ||
|
||
public static Long getMemberId() { | ||
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
|
||
if (authentication == null || authentication.getName() == null || authentication.getName() | ||
.equals("anonymousUser")) { | ||
throw new AuthorizationFailedException(ErrorCode.AUTH_INFO_NOT_FOUND); | ||
} | ||
|
||
return Long.parseLong(authentication.getName()); | ||
} | ||
} |
Oops, something went wrong.