-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat/logout] 로그아웃 api, refresh token 삭제 로직 구현 #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b70335a
:sparkles: feat : make HealthCheck api
jeeheaG 29f06c5
:sparkles: feat : make refresh token delete logic in TokenRefreshService
jeeheaG 2690848
:sparkles: feat : add refresh token delete logic at withdraw api
jeeheaG 8a7d8da
:rocket: feat : make log out api
jeeheaG f227816
:white_check_mark: test : add test for log out api
jeeheaG e1637d4
:white_check_mark: test : refactor healthCheck and logOut test code
jeeheaG 6d9a58f
:recycle: refactor : change log out api to endpoint /auth and move pa…
jeeheaG 7884c95
:recycle: refactor : change get token logic of log out api
jeeheaG f899625
:recycle: refactor : add exception logic in JwtResolver.getUserIdFrom…
jeeheaG 798ae75
:recycle: refactor : change token resolve logic at Logout and TokenRe…
jeeheaG cb16509
:bulb: chore : tidy up useless imports
jeeheaG 6c924a8
:white_check_mark: test : make log out test data sql
jeeheaG bf76853
:white_check_mark: test : make login-logout success test case
jeeheaG 0c65ab3
:bulb: chore : tidy up code
jeeheaG e9179ea
:recycle: refactor : extract method of login-logout test case code
jeeheaG 53ccea2
:white_check_mark: test : make apple login-logout test case
jeeheaG 77b68b2
:sparkles: add : add 'already log out' response at log out api
jeeheaG a31d44a
:white_check_mark: test : modify test for already log out case
jeeheaG 314018a
:bug: fix : add UserException handler
jeeheaG 35464c3
:recycle: refactor : rename log out acceptance test class
jeeheaG 2bb7704
:white_check_mark: test : make fail test cases for log out api
jeeheaG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
25 changes: 25 additions & 0 deletions
25
src/main/java/org/runimo/runimo/checker/controller/HealthCheckController.java
This file contains hidden or 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 org.runimo.runimo.checker.controller; | ||
|
|
||
| import org.runimo.runimo.common.log.ServiceLog; | ||
| import org.runimo.runimo.common.response.SuccessResponse; | ||
| import org.runimo.runimo.exceptions.code.ExampleErrorCode; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/checker") | ||
| public class HealthCheckController { | ||
|
|
||
| /** | ||
| * health check api | ||
| */ | ||
| @ServiceLog | ||
| @GetMapping("/health-check") | ||
| public ResponseEntity<SuccessResponse<String>> healthCheck() { | ||
| return ResponseEntity.ok( | ||
| SuccessResponse.of(ExampleErrorCode.SUCCESS, "Health check success !")); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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
37 changes: 37 additions & 0 deletions
37
src/main/java/org/runimo/runimo/user/controller/LogOutController.java
This file contains hidden or 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,37 @@ | ||
| package org.runimo.runimo.user.controller; | ||
|
|
||
| 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.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.runimo.runimo.common.response.SuccessResponse; | ||
| import org.runimo.runimo.user.enums.UserHttpResponseCode; | ||
| import org.runimo.runimo.user.service.usecases.logout.LogOutUsecase; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @Tag(name = "USER-LOG-OUT", description = "로그아웃 API") | ||
| @RestController | ||
| @RequestMapping("/api/v1/users") | ||
| @RequiredArgsConstructor | ||
| public class LogOutController { | ||
|
|
||
| private final LogOutUsecase logOutUsecase; | ||
|
|
||
| @Operation(summary = "로그아웃", description = "사용자를 로그아웃 처리합니다.") | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "200", description = "로그아웃 성공"), | ||
| @ApiResponse(responseCode = "404", description = "사용자를 찾을 수 없음") | ||
| }) | ||
| @PostMapping("/log-out") | ||
| public ResponseEntity<SuccessResponse<Void>> logOut( | ||
| @UserId Long userId | ||
| ) { | ||
| logOutUsecase.execute(userId); | ||
| return ResponseEntity.ok() | ||
| .body(SuccessResponse.of(UserHttpResponseCode.LOG_OUT_SUCCESS, null)); | ||
| } | ||
| } | ||
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
src/main/java/org/runimo/runimo/user/exception/UserException.java
This file contains hidden or 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,19 @@ | ||
| package org.runimo.runimo.user.exception; | ||
|
|
||
| import org.runimo.runimo.exceptions.BusinessException; | ||
| import org.runimo.runimo.exceptions.code.CustomResponseCode; | ||
|
|
||
| public class UserException extends BusinessException { | ||
|
|
||
| protected UserException(CustomResponseCode errorCode) { | ||
| super(errorCode); | ||
| } | ||
|
|
||
| public UserException(CustomResponseCode errorCode, String logMessage) { | ||
| super(errorCode, logMessage); | ||
| } | ||
|
|
||
| public static UserException of(CustomResponseCode errorCode) { | ||
| return new UserException(errorCode, errorCode.getLogMessage()); | ||
| } | ||
| } |
This file contains hidden or 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
6 changes: 6 additions & 0 deletions
6
src/main/java/org/runimo/runimo/user/service/usecases/logout/LogOutUsecase.java
This file contains hidden or 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,6 @@ | ||
| package org.runimo.runimo.user.service.usecases.logout; | ||
|
|
||
| public interface LogOutUsecase { | ||
|
|
||
| void execute(Long userId); | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/runimo/runimo/user/service/usecases/logout/LogOutUsecaseImpl.java
This file contains hidden or 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 org.runimo.runimo.user.service.usecases.logout; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.runimo.runimo.auth.service.TokenRefreshService; | ||
| import org.runimo.runimo.user.domain.User; | ||
| import org.runimo.runimo.user.enums.UserHttpResponseCode; | ||
| import org.runimo.runimo.user.exception.UserException; | ||
| import org.runimo.runimo.user.service.UserFinder; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class LogOutUsecaseImpl implements LogOutUsecase { | ||
|
|
||
| private final UserFinder userFinder; | ||
| private final TokenRefreshService tokenRefreshService; | ||
|
|
||
| @Override | ||
| public void execute(Long userId) { | ||
| User user = userFinder.findUserById(userId).orElseThrow(() -> UserException.of( | ||
| UserHttpResponseCode.USER_NOT_FOUND)); | ||
| tokenRefreshService.removeRefreshToken(user.getId()); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/test/java/org/runimo/runimo/checker/controller/HealthCheckControllerTest.java
This file contains hidden or 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,48 @@ | ||
| package org.runimo.runimo.checker.controller; | ||
|
|
||
| import static io.restassured.RestAssured.given; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.notNullValue; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import io.restassured.RestAssured; | ||
| import io.restassured.http.ContentType; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.runimo.runimo.CleanUpUtil; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.test.web.server.LocalServerPort; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
|
|
||
| @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
| @ActiveProfiles("test") | ||
| class HealthCheckControllerTest { | ||
|
|
||
| @LocalServerPort | ||
| int port; | ||
|
|
||
| @Autowired | ||
| private CleanUpUtil cleanUpUtil; | ||
ekgns33 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| RestAssured.port = port; | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| void healthCheck() { | ||
|
|
||
| // when & then | ||
| given() | ||
| .contentType(ContentType.JSON) | ||
| .when() | ||
| .get("/checker/health-check") | ||
| .then() | ||
| .log().all() | ||
| .statusCode(200) | ||
| .body("payload", equalTo("Health check success !")); | ||
| } | ||
| } | ||
69 changes: 69 additions & 0 deletions
69
src/test/java/org/runimo/runimo/user/controller/LogOutControllerTest.java
This file contains hidden or 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,69 @@ | ||
| package org.runimo.runimo.user.controller; | ||
|
|
||
| import static io.restassured.RestAssured.given; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
| import static org.runimo.runimo.TestConsts.TEST_USER_UUID; | ||
|
|
||
| import io.restassured.RestAssured; | ||
| import io.restassured.http.ContentType; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.runimo.runimo.CleanUpUtil; | ||
| import org.runimo.runimo.TokenUtils; | ||
| import org.runimo.runimo.exceptions.code.CustomResponseCode; | ||
| import org.runimo.runimo.user.enums.UserHttpResponseCode; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.test.web.server.LocalServerPort; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
| import org.springframework.test.context.jdbc.Sql; | ||
|
|
||
|
|
||
| @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
| @ActiveProfiles("test") | ||
| class LogOutControllerTest { | ||
ekgns33 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @LocalServerPort | ||
| int port; | ||
|
|
||
| @Autowired | ||
| private CleanUpUtil cleanUpUtil; | ||
|
|
||
| @Autowired | ||
| private TokenUtils tokenUtils; | ||
|
|
||
| private String token; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| RestAssured.port = port; | ||
| token = tokenUtils.createTokenByUserPublicId(TEST_USER_UUID); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void tearDown() { | ||
| cleanUpUtil.cleanUpUserInfos(); | ||
| } | ||
|
|
||
| @Test | ||
| @Sql(scripts = "/sql/log_out_test_data.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
| void logOut() { | ||
ekgns33 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| CustomResponseCode responseCode = UserHttpResponseCode.LOG_OUT_SUCCESS; | ||
|
|
||
| given() | ||
| .header("Authorization", token) | ||
| .contentType(ContentType.JSON) | ||
|
|
||
| .when() | ||
| .post("/api/v1/users/log-out") | ||
|
|
||
| .then() | ||
| .log().all() | ||
| .statusCode(responseCode.getHttpStatusCode().value()) | ||
|
|
||
| .body("code", equalTo(responseCode.getCode())) | ||
| .body("message", equalTo(responseCode.getClientMessage())); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.