-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: MingyeomKim <[email protected]>
- Loading branch information
1 parent
b1534d1
commit d01c73f
Showing
7 changed files
with
136 additions
and
11 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
50 changes: 50 additions & 0 deletions
50
src/main/java/com/backend/auth/presentation/TokenController.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,50 @@ | ||
package com.backend.auth.presentation; | ||
|
||
import com.backend.auth.jwt.TokenProvider; | ||
import com.backend.auth.presentation.dto.request.ExpireTimeRequest; | ||
import com.backend.auth.presentation.dto.response.ExpireTimeResponse; | ||
import com.backend.global.common.response.CustomResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import static com.backend.global.common.code.SuccessCode.SELECT_SUCCESS; | ||
import static com.backend.global.common.code.SuccessCode.UPDATE_SUCCESS; | ||
|
||
@Tag(name = "token", description = "토큰 관리 API입니다.") | ||
@RequiredArgsConstructor | ||
@RequestMapping("/token") | ||
@RestController | ||
public class TokenController { | ||
private final TokenProvider tokenProvider; | ||
|
||
@Operation(summary = "액세스 토큰 유효 시간 수정", description = "액세스 토큰의 유효 시간을 수정한다.") | ||
@PutMapping("/access/expire") | ||
public ResponseEntity<CustomResponse<Void>> updateAccessTokenExpireTime(@RequestBody ExpireTimeRequest expireTimeRequest){ | ||
tokenProvider.updateAccessTokenExpireTime(expireTimeRequest.toLong()); | ||
return CustomResponse.success(UPDATE_SUCCESS); | ||
} | ||
|
||
@Operation(summary = "리프레시 토큰 유효 시간 수정", description = "리프레시 토큰의 유효 시간을 수정한다.") | ||
@PutMapping("/refresh/expire") | ||
public ResponseEntity<CustomResponse<Void>> updateRefreshTokenExpireTime(@RequestBody ExpireTimeRequest expireTimeRequest){ | ||
tokenProvider.updateRefreshTokenExpireTime(expireTimeRequest.toLong()); | ||
return CustomResponse.success(UPDATE_SUCCESS); | ||
} | ||
|
||
@Operation(summary = "액세스 토큰 유효 시간 조회", description = "액세스 토큰의 유효 시간을 초 단위로 조회한다.") | ||
@GetMapping("/access/expire") | ||
public ResponseEntity<CustomResponse<ExpireTimeResponse>> getAccessTokenExpireTime(){ | ||
return CustomResponse.success(SELECT_SUCCESS, ExpireTimeResponse.from(tokenProvider.getAccessTokenExpireTime())); | ||
} | ||
|
||
@Operation(summary = "리프레시 토큰 유효 시간 조회", description = "리프레시 토큰의 유효 시간을 초 단위로 조회한다.") | ||
@GetMapping("/refresh/expire") | ||
public ResponseEntity<CustomResponse<ExpireTimeResponse>> getRefreshTokenExpireTime(){ | ||
return CustomResponse.success(SELECT_SUCCESS, ExpireTimeResponse.from(tokenProvider.getRefreshTokenExpireTime())); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/backend/auth/presentation/dto/request/ExpireTimeRequest.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,27 @@ | ||
package com.backend.auth.presentation.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public record ExpireTimeRequest( | ||
@Schema(description = "만료 기한의 일수", example = "14") | ||
Long days, | ||
|
||
@Schema(description = "만료 기한의 시간", example = "0") | ||
Long hours, | ||
|
||
@Schema(description = "만료 기한의 분", example = "0") | ||
Long minutes, | ||
|
||
@Schema(description = "만료 기한의 초", example = "0") | ||
Long seconds | ||
) { | ||
public Long toLong() { | ||
Long expireTime = 1000L; | ||
|
||
if(days!= 0) expireTime *= (days * 24 * 60 * 60); | ||
if(hours != 0) expireTime *= (hours * 60 * 60); | ||
if(minutes != 0) expireTime *= (minutes * 60); | ||
if(seconds != 0) expireTime *= (seconds * 60); | ||
return expireTime; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/backend/auth/presentation/dto/response/ExpireTimeResponse.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,33 @@ | ||
package com.backend.auth.presentation.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public record ExpireTimeResponse( | ||
@Schema(description = "만료 기한의 일수", example = "14") | ||
Long days, | ||
|
||
@Schema(description = "만료 기한의 시간", example = "0") | ||
Long hours, | ||
|
||
@Schema(description = "만료 기한의 분", example = "0") | ||
Long minutes, | ||
|
||
@Schema(description = "만료 기한의 초", example = "0") | ||
Long seconds | ||
) { | ||
public static ExpireTimeResponse from(Long expireTime) { | ||
expireTime /= 1000; | ||
|
||
Long days = expireTime / (24 * 60 * 60); | ||
if(days != 0) expireTime %= days; | ||
|
||
Long hours = expireTime / (60 * 60); | ||
if(hours != 0) expireTime %= hours; | ||
|
||
Long minutes = expireTime / 60; | ||
if(minutes != 0) expireTime %= minutes; | ||
|
||
Long seconds = expireTime / 60; | ||
return new ExpireTimeResponse(days, hours, minutes, seconds); | ||
} | ||
} |
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