-
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 #19 from team-haribo/feature/14-write-the-logic-login
🔀 :: (#14) - write the logic login
- Loading branch information
Showing
30 changed files
with
511 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.goms.common | ||
|
||
sealed class Event<out T>( | ||
val data: T? = null | ||
) { | ||
|
||
object Loading : Event<Nothing>() | ||
|
||
// 20X: 성공 | ||
class Success<T>(data: T? = null) : Event<T>(data = data) | ||
|
||
// 400: 올바르지 않은 요청 | ||
object BadRequest : Event<Nothing>() | ||
|
||
// 401: 비인증 상태 | ||
object Unauthorized : Event<Nothing>() | ||
|
||
// 403: 권한이 없음 | ||
object ForBidden : Event<Nothing>() | ||
|
||
// 404: 요청한 리소스를 찾을 수 없음 | ||
object NotFound : Event<Nothing>() | ||
|
||
// 406: 클라이언트가 허용되지 않는 규격을 요청 | ||
object NotAcceptable : Event<Nothing>() | ||
|
||
// 408: 요청시간초과 | ||
object TimeOut : Event<Nothing>() | ||
|
||
// 409: 충돌발생 | ||
object Conflict : Event<Nothing>() | ||
|
||
// 50X: 서버에러 | ||
object Server : Event<Nothing>() | ||
|
||
// 예상하지 못한 에러 | ||
object UnKnown : Event<Nothing>() | ||
} |
67 changes: 67 additions & 0 deletions
67
core/common/src/main/java/com/goms/common/errorHandling.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,67 @@ | ||
package com.goms.common | ||
|
||
import android.util.Log | ||
import com.goms.common.exception.* | ||
|
||
suspend fun <T> Throwable.errorHandling( | ||
badRequestAction: suspend () -> Unit = {}, | ||
unauthorizedAction: suspend () -> Unit = {}, | ||
forBiddenAction: suspend () -> Unit = {}, | ||
notFoundAction: suspend () -> Unit = {}, | ||
notAcceptableAction: suspend () -> Unit = {}, | ||
timeOutAction: suspend () -> Unit = {}, | ||
conflictAction: suspend () -> Unit = {}, | ||
serverAction: suspend () -> Unit = {}, | ||
unknownAction: suspend () -> Unit = {}, | ||
): Event<T> = | ||
when (this) { | ||
is BadRequestException -> { | ||
errorLog("BadRequestException", message) | ||
badRequestAction() | ||
Event.BadRequest | ||
} | ||
is UnauthorizedException, is TokenExpirationException -> { | ||
errorLog("UnauthorizedException", message) | ||
unauthorizedAction() | ||
Event.Unauthorized | ||
} | ||
is ForBiddenException -> { | ||
errorLog("ForBiddenException", message) | ||
forBiddenAction() | ||
Event.ForBidden | ||
} | ||
is NotFoundException -> { | ||
errorLog("NotFoundException", message) | ||
notFoundAction() | ||
Event.NotFound | ||
} | ||
is NotAcceptableException -> { | ||
errorLog("NotAcceptableException", message) | ||
notAcceptableAction() | ||
Event.NotAcceptable | ||
} | ||
is TimeOutException -> { | ||
errorLog("TimeOutException", message) | ||
timeOutAction() | ||
Event.TimeOut | ||
} | ||
is ConflictException -> { | ||
errorLog("ConflictException", message) | ||
conflictAction() | ||
Event.Conflict | ||
} | ||
is ServerException -> { | ||
errorLog("ServerException", message) | ||
serverAction() | ||
Event.Server | ||
} | ||
else -> { | ||
errorLog("UnKnownException", message) | ||
unknownAction() | ||
Event.UnKnown | ||
} | ||
} | ||
|
||
private fun errorLog(tag: String, msg: String?) { | ||
Log.d("ErrorHandling-$tag", msg ?: "알 수 없는 오류") | ||
} |
59 changes: 59 additions & 0 deletions
59
core/common/src/main/java/com/goms/common/exception/HttpException.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,59 @@ | ||
package com.goms.common.exception | ||
|
||
// 400: 올바르지 않은 요청 | ||
class BadRequestException( | ||
override val message: String? | ||
) : RuntimeException() | ||
|
||
|
||
// 401: 비인증 상태 | ||
class UnauthorizedException( | ||
override val message: String? | ||
) : RuntimeException() | ||
|
||
|
||
// 403: 권한이 없음 | ||
class ForBiddenException( | ||
override val message: String? | ||
) : RuntimeException() | ||
|
||
|
||
// 404: 요청한 리소스를 찾을 수 없음 | ||
class NotFoundException( | ||
override val message: String? | ||
) : RuntimeException() | ||
|
||
|
||
// 406: 클라이언트가 허용되지 않는 규격을 요청 | ||
class NotAcceptableException( | ||
override val message: String? | ||
) : RuntimeException() | ||
|
||
// 408: 요청시간초과 | ||
class TimeOutException( | ||
override val message: String? | ||
) : RuntimeException() | ||
|
||
|
||
// 409: 충돌발생 | ||
class ConflictException( | ||
override val message: String? | ||
) : RuntimeException() | ||
|
||
|
||
// 50X: 서버에러 | ||
class ServerException( | ||
override val message: String? | ||
) : RuntimeException() | ||
|
||
|
||
// 정의되지 않은 HTTP 상태 코드나 사용자 정의 상태 코드 | ||
class OtherHttpException( | ||
val code: Int, | ||
override val message: String? | ||
) : RuntimeException() | ||
|
||
// 예상하지 못한 에러 | ||
class UnKnownException( | ||
override val message: String? | ||
) : RuntimeException() |
6 changes: 6 additions & 0 deletions
6
core/common/src/main/java/com/goms/common/exception/InternetException.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,6 @@ | ||
package com.goms.common.exception | ||
|
||
class NoInternetException : RuntimeException() { | ||
override val message: String | ||
get() = "네트워크가 불안정합니다, 데이터나 와이파이 연결 상태를 확인해주세요." | ||
} |
8 changes: 8 additions & 0 deletions
8
core/common/src/main/java/com/goms/common/exception/TokenExpirationException.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,8 @@ | ||
package com.goms.common.exception | ||
|
||
import java.io.IOException | ||
|
||
class TokenExpirationException : IOException() { | ||
override val message: String | ||
get() = "토큰이 만료되었습니다. 다시 로그인 해주세요" | ||
} |
17 changes: 17 additions & 0 deletions
17
core/data/src/main/java/com/goms/data/di/RepositoryModule.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,17 @@ | ||
package com.goms.data.di | ||
|
||
import com.goms.data.repository.auth.AuthRepository | ||
import com.goms.data.repository.auth.AuthRepositoryImpl | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class RepositoryModule { | ||
@Binds | ||
abstract fun bindAuthRepository( | ||
authRepositoryImpl: AuthRepositoryImpl | ||
): AuthRepository | ||
} |
Empty file.
9 changes: 9 additions & 0 deletions
9
core/data/src/main/java/com/goms/data/repository/auth/AuthRepository.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,9 @@ | ||
package com.goms.data.repository.auth | ||
|
||
import com.goms.model.request.auth.LoginRequest | ||
import com.goms.model.response.auth.LoginResponse | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface AuthRepository { | ||
suspend fun login(body: LoginRequest): Flow<LoginResponse> | ||
} |
15 changes: 15 additions & 0 deletions
15
core/data/src/main/java/com/goms/data/repository/auth/AuthRepositoryImpl.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,15 @@ | ||
package com.goms.data.repository.auth | ||
|
||
import com.goms.model.request.auth.LoginRequest | ||
import com.goms.model.response.auth.LoginResponse | ||
import com.goms.network.datasource.auth.AuthDataSource | ||
import kotlinx.coroutines.flow.Flow | ||
import javax.inject.Inject | ||
|
||
class AuthRepositoryImpl @Inject constructor( | ||
private val remoteAuthDataSource: AuthDataSource | ||
) : AuthRepository { | ||
override suspend fun login(body: LoginRequest): Flow<LoginResponse> { | ||
return remoteAuthDataSource.login(body = body) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
core/domain/src/main/java/com/goms/domain/auth/LoginUseCase.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,13 @@ | ||
package com.goms.domain.auth | ||
|
||
import com.goms.data.repository.auth.AuthRepository | ||
import com.goms.model.request.auth.LoginRequest | ||
import javax.inject.Inject | ||
|
||
class LoginUseCase @Inject constructor( | ||
private val authRepository: AuthRepository | ||
) { | ||
suspend operator fun invoke(body: LoginRequest) = kotlin.runCatching { | ||
authRepository.login(body = body) | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
core/model/src/main/java/com/goms/model/request/auth/LoginRequest.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,5 @@ | ||
package com.goms.model.request.auth | ||
|
||
data class LoginRequest( | ||
val code: String | ||
) |
Empty file.
9 changes: 9 additions & 0 deletions
9
core/model/src/main/java/com/goms/model/response/auth/LoginResponse.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,9 @@ | ||
package com.goms.model.response.auth | ||
|
||
data class LoginResponse( | ||
val accessToken: String, | ||
val refreshToken: String, | ||
val accessTokenExp: String, | ||
val refreshTokenExp: String, | ||
val authority: String | ||
) |
Empty file.
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
Empty file.
13 changes: 13 additions & 0 deletions
13
core/network/src/main/java/com/goms/network/api/AuthAPI.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,13 @@ | ||
package com.goms.network.api | ||
|
||
import com.goms.model.request.auth.LoginRequest | ||
import com.goms.model.response.auth.LoginResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface AuthAPI { | ||
@POST("/api/v2/auth/signin") | ||
suspend fun login( | ||
@Body body: LoginRequest | ||
): LoginResponse | ||
} |
Empty file.
9 changes: 9 additions & 0 deletions
9
core/network/src/main/java/com/goms/network/datasource/auth/AuthDataSource.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,9 @@ | ||
package com.goms.network.datasource.auth | ||
|
||
import com.goms.model.request.auth.LoginRequest | ||
import com.goms.model.response.auth.LoginResponse | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface AuthDataSource { | ||
suspend fun login(body: LoginRequest): Flow<LoginResponse> | ||
} |
23 changes: 23 additions & 0 deletions
23
core/network/src/main/java/com/goms/network/datasource/auth/AuthDataSourceImpl.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,23 @@ | ||
package com.goms.network.datasource.auth | ||
|
||
import com.goms.model.request.auth.LoginRequest | ||
import com.goms.model.response.auth.LoginResponse | ||
import com.goms.network.api.AuthAPI | ||
import com.goms.network.util.GomsApiHandler | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOn | ||
import javax.inject.Inject | ||
|
||
class AuthDataSourceImpl @Inject constructor( | ||
private val authAPI: AuthAPI | ||
) : AuthDataSource { | ||
override suspend fun login(body: LoginRequest): Flow<LoginResponse> = flow { | ||
emit( | ||
GomsApiHandler<LoginResponse>() | ||
.httpRequest { authAPI.login(body = body) } | ||
.sendRequest() | ||
) | ||
}.flowOn(Dispatchers.IO) | ||
} |
Oops, something went wrong.