-
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.
refactor: 로그인 토큰과 회원가입 토큰을 AuthToken 으로 추상화
- Loading branch information
Showing
14 changed files
with
148 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,20 @@ | ||
package com.petqua.application.token | ||
|
||
import com.petqua.domain.auth.token.AuthToken | ||
import com.petqua.presentation.auth.SignUpTokenResponse | ||
|
||
data class AuthTokenInfo( | ||
val accessToken: String, | ||
val refreshToken: String, | ||
val authToken: AuthToken, | ||
) { | ||
val accessToken: String | ||
get() = authToken.getAccessToken() | ||
|
||
fun isSignUpNeeded(): Boolean { | ||
return AuthToken.isSignUpNeeded(refreshToken) | ||
} | ||
val refreshToken: String | ||
get() = authToken.getRefreshToken() | ||
|
||
fun toSignUpTokenResponse(): SignUpTokenResponse { | ||
return SignUpTokenResponse(accessToken) | ||
} | ||
val signUpToken: String | ||
get() = authToken.getSignUpToken() | ||
|
||
companion object { | ||
fun from(authToken: AuthToken): AuthTokenInfo { | ||
return AuthTokenInfo( | ||
accessToken = authToken.accessToken, | ||
refreshToken = authToken.refreshToken, | ||
) | ||
} | ||
|
||
fun signUpTokenOf(signUpToken: AuthToken): AuthTokenInfo { | ||
return AuthTokenInfo( | ||
accessToken = signUpToken.accessToken, | ||
refreshToken = signUpToken.refreshToken | ||
) | ||
} | ||
fun isSignUpNeeded(): Boolean { | ||
return authToken.isSignUpNeeded() | ||
} | ||
} |
30 changes: 16 additions & 14 deletions
30
src/main/kotlin/com/petqua/domain/auth/token/AuthToken.kt
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,29 +1,31 @@ | ||
package com.petqua.domain.auth.token | ||
|
||
private const val EMPTY_TOKEN = "" | ||
abstract class AuthToken { | ||
|
||
class AuthToken private constructor( | ||
val accessToken: String, | ||
val refreshToken: String, | ||
) { | ||
protected abstract fun isSignUpToken(): Boolean | ||
|
||
abstract fun getAccessToken(): String | ||
|
||
abstract fun getRefreshToken(): String | ||
|
||
abstract fun getSignUpToken(): String | ||
|
||
fun isSignUpNeeded(): Boolean { | ||
return isSignUpToken() | ||
} | ||
|
||
companion object { | ||
fun of(accessToken: String, refreshToken: String): AuthToken { | ||
return AuthToken( | ||
fun loginTokenOf(accessToken: String, refreshToken: String): AuthToken { | ||
return LoginToken( | ||
accessToken = accessToken, | ||
refreshToken = refreshToken, | ||
) | ||
} | ||
|
||
fun signUpTokenOf(signUpToken: String): AuthToken { | ||
return AuthToken( | ||
accessToken = signUpToken, | ||
refreshToken = EMPTY_TOKEN | ||
return SignUpToken( | ||
signUpToken = signUpToken, | ||
) | ||
} | ||
|
||
fun isSignUpNeeded(token: String): Boolean { | ||
return token == EMPTY_TOKEN | ||
} | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/com/petqua/domain/auth/token/LoginToken.kt
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.petqua.domain.auth.token | ||
|
||
|
||
import com.petqua.exception.auth.AuthException | ||
import com.petqua.exception.auth.AuthExceptionType.UNSUPPORTED_OPERATION | ||
|
||
class LoginToken( | ||
private val accessToken: String, | ||
private val refreshToken: String, | ||
) : AuthToken() { | ||
|
||
override fun isSignUpToken(): Boolean { | ||
return false | ||
} | ||
|
||
override fun getAccessToken(): String { | ||
return accessToken | ||
} | ||
|
||
override fun getRefreshToken(): String { | ||
return refreshToken | ||
} | ||
|
||
override fun getSignUpToken(): String { | ||
throw AuthException(UNSUPPORTED_OPERATION) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/com/petqua/domain/auth/token/SignUpToken.kt
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,25 @@ | ||
package com.petqua.domain.auth.token | ||
|
||
import com.petqua.exception.auth.AuthException | ||
import com.petqua.exception.auth.AuthExceptionType | ||
|
||
class SignUpToken( | ||
private val signUpToken: String, | ||
) : AuthToken() { | ||
|
||
override fun isSignUpToken(): Boolean { | ||
return true | ||
} | ||
|
||
override fun getAccessToken(): String { | ||
throw AuthException(AuthExceptionType.UNSUPPORTED_OPERATION) | ||
} | ||
|
||
override fun getRefreshToken(): String { | ||
throw AuthException(AuthExceptionType.UNSUPPORTED_OPERATION) | ||
} | ||
|
||
override fun getSignUpToken(): String { | ||
return signUpToken | ||
} | ||
} |
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
Oops, something went wrong.