-
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.
- Loading branch information
Showing
44 changed files
with
920 additions
and
26 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
16 changes: 16 additions & 0 deletions
16
...ta/src/main/java/com/goalpanzi/mission_mate/core/data/repository/ProfileRepositoryImpl.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,16 @@ | ||
package com.goalpanzi.mission_mate.core.data.repository | ||
|
||
import com.goalpanzi.mission_mate.core.domain.repository.ProfileRepository | ||
import com.goalpanzi.mission_mate.core.network.service.ProfileService | ||
import com.luckyoct.core.model.base.NetworkResult | ||
import com.luckyoct.core.model.request.SaveProfileRequest | ||
import javax.inject.Inject | ||
|
||
class ProfileRepositoryImpl @Inject constructor( | ||
private val profileService: ProfileService | ||
): ProfileRepository { | ||
override suspend fun saveProfile(nickname: String, index: Int): NetworkResult<Unit> = handleResult { | ||
val request = SaveProfileRequest.createRequest(nickname, index) | ||
profileService.saveProfile(request) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../src/main/java/com/goalpanzi/mission_mate/core/datastore/datasource/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
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
30 changes: 30 additions & 0 deletions
30
core/domain/src/main/java/com/goalpanzi/mission_mate/core/domain/di/ResourceProvider.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,30 @@ | ||
package com.goalpanzi.mission_mate.core.domain.di | ||
|
||
import android.content.Context | ||
import android.content.res.TypedArray | ||
import androidx.annotation.ArrayRes | ||
import androidx.annotation.StringRes | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class ResourceProvider @Inject constructor( | ||
@ApplicationContext private val context: Context | ||
) { | ||
fun getString(@StringRes stringResId: Int): String { | ||
return context.getString(stringResId) | ||
} | ||
|
||
fun getIntArray(@ArrayRes arrayResId: Int): Array<Int> { | ||
return context.resources.getIntArray(arrayResId).toTypedArray() | ||
} | ||
|
||
fun getDrawableArray(@ArrayRes arrayResId: Int): TypedArray { | ||
return context.resources.obtainTypedArray(arrayResId) | ||
} | ||
|
||
fun getStringArray(@ArrayRes arrayResId: Int): Array<String> { | ||
return context.resources.getStringArray(arrayResId) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...main/src/main/java/com/goalpanzi/mission_mate/core/domain/repository/ProfileRepository.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.goalpanzi.mission_mate.core.domain.repository | ||
|
||
import com.goalpanzi.mission_mate.core.network.ResultHandler | ||
import com.luckyoct.core.model.base.NetworkResult | ||
|
||
interface ProfileRepository: ResultHandler { | ||
suspend fun saveProfile(nickname: String, index: Int): NetworkResult<Unit> | ||
} |
12 changes: 10 additions & 2 deletions
12
core/domain/src/main/java/com/goalpanzi/mission_mate/core/domain/usecase/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 |
---|---|---|
@@ -1,13 +1,21 @@ | ||
package com.goalpanzi.mission_mate.core.domain.usecase | ||
|
||
import com.goalpanzi.mission_mate.core.datastore.datasource.AuthDataSource | ||
import com.goalpanzi.mission_mate.core.domain.repository.LoginRepository | ||
import com.luckyoct.core.model.GoogleLogin | ||
import kotlinx.coroutines.flow.first | ||
import javax.inject.Inject | ||
|
||
class LoginUseCase @Inject constructor( | ||
private val loginRepository: LoginRepository | ||
private val loginRepository: LoginRepository, | ||
private val authDataSource: AuthDataSource | ||
) { | ||
|
||
suspend fun requestGoogleLogin(token: String, email: String): GoogleLogin = loginRepository.requestGoogleLogin(token, email) | ||
suspend fun requestGoogleLogin(token: String, email: String): GoogleLogin { | ||
val response = loginRepository.requestGoogleLogin(token, email) | ||
authDataSource.setAccessToken(response.accessToken).first() | ||
authDataSource.setRefreshToken(response.refreshToken).first() | ||
return response | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
core/domain/src/main/java/com/goalpanzi/mission_mate/core/domain/usecase/ProfileUseCase.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,10 @@ | ||
package com.goalpanzi.mission_mate.core.domain.usecase | ||
|
||
import com.goalpanzi.mission_mate.core.domain.repository.ProfileRepository | ||
import javax.inject.Inject | ||
|
||
class ProfileUseCase @Inject constructor( | ||
private val profileRepository: ProfileRepository | ||
) { | ||
suspend fun saveProfile(nickname: String, index: Int) = profileRepository.saveProfile(nickname, index) | ||
} |
7 changes: 7 additions & 0 deletions
7
core/model/src/main/java/com/luckyoct/core/model/base/NetworkResult.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,7 @@ | ||
package com.luckyoct.core.model.base | ||
|
||
sealed interface NetworkResult<out T> { | ||
data class Success<out T>(val data: T) : NetworkResult<T> | ||
data class Error(val code: Int? = null, val message: String? = null) : NetworkResult<Nothing> | ||
data class Exception(val error: Throwable) : NetworkResult<Nothing> | ||
} |
20 changes: 20 additions & 0 deletions
20
core/model/src/main/java/com/luckyoct/core/model/request/SaveProfileRequest.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,20 @@ | ||
package com.luckyoct.core.model.request | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
enum class CharacterType { | ||
RABBIT, CAT, DOG, PANDA, BEAR, BIRD | ||
} | ||
|
||
@Serializable | ||
data class SaveProfileRequest( | ||
val nickname: String, | ||
val characterType: String, | ||
) { | ||
companion object { | ||
fun createRequest(nickname: String, index: Int) = SaveProfileRequest( | ||
nickname = nickname, | ||
characterType = CharacterType.entries[index].name.uppercase() | ||
) | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
core/network/src/main/java/com/goalpanzi/mission_mate/core/network/ResultHandler.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,28 @@ | ||
package com.goalpanzi.mission_mate.core.network | ||
|
||
import com.luckyoct.core.model.base.NetworkResult | ||
import retrofit2.HttpException | ||
import retrofit2.Response | ||
|
||
interface ResultHandler { | ||
|
||
suspend fun <T : Any> handleResult(execute: suspend () -> Response<T>): NetworkResult<T> { | ||
return try { | ||
val response = execute() | ||
if (response.isSuccessful) { | ||
val body = response.body() | ||
if (body != null) { | ||
NetworkResult.Success(body) | ||
} else { | ||
NetworkResult.Error(response.code(), "Response body is null") | ||
} | ||
} else { | ||
NetworkResult.Error(response.code(), response.errorBody()?.string()) | ||
} | ||
} catch (e: HttpException) { | ||
NetworkResult.Error(e.code(), e.message()) | ||
} catch (e: Throwable) { | ||
NetworkResult.Exception(e) | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
core/network/src/main/java/com/goalpanzi/mission_mate/core/network/TokenInterceptor.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,40 @@ | ||
package com.goalpanzi.mission_mate.core.network | ||
|
||
import com.goalpanzi.mission_mate.core.datastore.datasource.AuthDataSource | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.runBlocking | ||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class TokenInterceptor @Inject constructor( | ||
private val authDataSource: AuthDataSource | ||
) : Interceptor { | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
val newRequest = chain.request().newBuilder().apply { | ||
runBlocking { | ||
val token = authDataSource.getAccessToken().first() | ||
token?.let { | ||
addHeader("Authorization", "Bearer $it") | ||
} | ||
} | ||
} | ||
|
||
val response = chain.proceed(newRequest.build()) | ||
if (response.code == 200) { | ||
val newAccessToken: String = response.header("Authorization", null) ?: return response | ||
CoroutineScope(Dispatchers.IO).launch { | ||
val existedAccessToken = authDataSource.getAccessToken().first() | ||
if (existedAccessToken != newAccessToken) { | ||
authDataSource.setAccessToken(newAccessToken) | ||
} | ||
} | ||
} | ||
return response | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
core/network/src/main/java/com/goalpanzi/mission_mate/core/network/service/ProfileService.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.goalpanzi.mission_mate.core.network.service | ||
|
||
import com.luckyoct.core.model.request.SaveProfileRequest | ||
import retrofit2.Response | ||
import retrofit2.http.Body | ||
import retrofit2.http.PATCH | ||
|
||
interface ProfileService { | ||
@PATCH("/api/member/profile") | ||
suspend fun saveProfile( | ||
@Body request: SaveProfileRequest | ||
): Response<Unit> | ||
} |
6 changes: 6 additions & 0 deletions
6
feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginEvent.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.goalpanzi.mission_mate.feature.login | ||
|
||
sealed interface LoginEvent { | ||
data object Error : LoginEvent | ||
data class Success(val isAlreadyMember: Boolean) : LoginEvent | ||
} |
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.