Skip to content

Commit

Permalink
Merge pull request #236 from Link-MIND/feature/#235
Browse files Browse the repository at this point in the history
[Feature/#235] ์˜จ๋ณด๋”ฉ์—์„œ์˜ ํ† ํฐ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ API ์ž‘์„ฑ
  • Loading branch information
sss4920 authored Mar 31, 2024
2 parents 90ffa18 + 302c83f commit 3e486f1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingRequestHeaderException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
Expand Down Expand Up @@ -116,6 +117,14 @@ protected ResponseEntity<ApiResponse> UnknownHostException(final UnknownHostExce
.body(ApiResponse.error(Error.BAD_REQUEST_VALIDATION, Error.BAD_REQUEST_VALIDATION.getMessage()));
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingRequestHeaderException.class)
protected ResponseEntity<ApiResponse> MissingRequestHeaderException(final MissingRequestHeaderException e){
Sentry.captureException(e);
return ResponseEntity.status(Error.BAD_REQUEST_VALIDATION.getErrorCode())
.body(ApiResponse.error(Error.BAD_REQUEST_VALIDATION, Error.BAD_REQUEST_VALIDATION.getMessage()));
}



/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.app.toaster.config.UserId;
import com.app.toaster.controller.request.auth.SignInRequestDto;
import com.app.toaster.controller.response.auth.SignInResponseDto;
import com.app.toaster.controller.response.auth.TokenHealthDto;
import com.app.toaster.controller.response.auth.TokenResponseDto;
import com.app.toaster.exception.Success;
import com.app.toaster.service.auth.AuthService;
Expand Down Expand Up @@ -56,4 +57,10 @@ public ApiResponse withdraw(@UserId Long userId) {
authService.withdraw(userId);
return ApiResponse.success(Success.DELETE_USER_SUCCESS);
}

@PostMapping("/token/health")
@ResponseStatus(HttpStatus.OK)
public ApiResponse<TokenHealthDto> checkHealthOfToken(@RequestHeader String token) {
return ApiResponse.success(Success.TOKEN_HEALTH_CHECKED_SUCCESS, authService.checkHealthOfToken(token));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.app.toaster.controller.response.auth;

public record TokenHealthDto(boolean tokenHealth) {
public static TokenHealthDto of(boolean tokenHealth){return new TokenHealthDto(tokenHealth);}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum Success {

LOGIN_SUCCESS(HttpStatus.OK, "๋กœ๊ทธ์ธ ์„ฑ๊ณต"),
RE_ISSUE_TOKEN_SUCCESS(HttpStatus.OK, "ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ ์„ฑ๊ณต"),
TOKEN_HEALTH_CHECKED_SUCCESS(HttpStatus.OK, "ํ† ํฐ ํ—ฌ์Šค์ฒดํฌ ์„ฑ๊ณต"),
SIGNOUT_SUCCESS(HttpStatus.OK, "๋กœ๊ทธ์•„์›ƒ ์„ฑ๊ณต"),
DELETE_USER_SUCCESS(HttpStatus.OK, "ํšŒ์› ํƒˆํ‡ด๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ด๋ฃจ์–ด์กŒ์Šต๋‹ˆ๋‹ค."),
DELETE_TOAST_SUCCESS(HttpStatus.OK, "ํ† ์ŠคํŠธ ์‚ญ์ œ ์„ฑ๊ณต"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import com.app.toaster.common.dto.ApiResponse;
import com.app.toaster.config.jwt.JwtService;
import com.app.toaster.controller.request.auth.SignInRequestDto;
import com.app.toaster.controller.response.auth.SignInResponseDto;
import com.app.toaster.controller.response.auth.TokenHealthDto;
import com.app.toaster.controller.response.auth.TokenResponseDto;
import com.app.toaster.domain.SocialType;
import com.app.toaster.domain.User;
Expand Down Expand Up @@ -156,4 +158,9 @@ public void withdraw(Long userId) {
}
}

@Transactional(readOnly = true)
public TokenHealthDto checkHealthOfToken(String refreshToken){
return TokenHealthDto.of(jwtService.verifyToken(refreshToken));
}

}

0 comments on commit 3e486f1

Please sign in to comment.