Skip to content

Commit

Permalink
Merge pull request #27 from Nexters/feature/fix-qa-mvp
Browse files Browse the repository at this point in the history
로그인 수정사항 변경, 프로필 수정 구현
  • Loading branch information
bywindow authored Aug 14, 2024
2 parents 784b8ad + 26ff8af commit ebab65d
Show file tree
Hide file tree
Showing 33 changed files with 454 additions and 202 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {
minSdk = 26
targetSdk = 34
versionCode = 1
versionName = "1.0"
versionName = "1.0.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ plugins {
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.hilt.android) apply false
alias(libs.plugins.kotlin.ksp) apply false
alias(libs.plugins.kotlin.parcelize) apply false
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,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.CharacterType
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)
override suspend fun saveProfile(nickname: String, type: CharacterType): NetworkResult<Unit> = handleResult {
val request = SaveProfileRequest.createRequest(nickname, type)
profileService.saveProfile(request)
}
}
2 changes: 2 additions & 0 deletions core/datastore/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ dependencies {

ksp(libs.hilt.compiler)
implementation(libs.hilt.android)

implementation(project(":core:model"))
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.goalpanzi.mission_mate.core.datastore.datasource

import com.luckyoct.core.model.UserProfile
import kotlinx.coroutines.flow.Flow

interface DefaultDataSource {
fun clearUserData() : Flow<Unit>
fun setUserProfile(data: UserProfile) : Flow<Unit>
fun getUserProfile() : Flow<UserProfile?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,45 @@ package com.goalpanzi.mission_mate.core.datastore.datasource
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import com.luckyoct.core.model.CharacterType
import com.luckyoct.core.model.UserProfile
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class DefaultDataSourceImpl @Inject constructor(
private val dataStore: DataStore<Preferences>
) : DefaultDataSource {

object PreferencesKey {
val USER_NICKNAME = stringPreferencesKey("USER_NICKNAME")
val USER_CHARACTER = stringPreferencesKey("USER_CHARACTER")
}

override fun clearUserData(): Flow<Unit> = flow {
dataStore.edit { preferences ->
preferences.clear()
}
emit(Unit)
}

override fun setUserProfile(data: UserProfile): Flow<Unit> = flow {
dataStore.edit { preferences ->
preferences[PreferencesKey.USER_NICKNAME] = data.nickname
preferences[PreferencesKey.USER_CHARACTER] = data.characterType.name.uppercase()
}
emit(Unit)
}

override fun getUserProfile(): Flow<UserProfile?> = dataStore.data.map { preferences ->
val nickname = preferences[PreferencesKey.USER_NICKNAME]
val character = preferences[PreferencesKey.USER_CHARACTER]
if (nickname != null && character != null) {
UserProfile(nickname, CharacterType.valueOf(character))
} else {
null
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.goalpanzi.mission_mate.core.domain.repository

import com.goalpanzi.mission_mate.core.network.ResultHandler
import com.luckyoct.core.model.GoogleLogin
import com.luckyoct.core.model.response.GoogleLogin
import com.luckyoct.core.model.base.NetworkResult

interface AuthRepository : ResultHandler {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.goalpanzi.mission_mate.core.domain.repository

import com.goalpanzi.mission_mate.core.network.ResultHandler
import com.luckyoct.core.model.CharacterType
import com.luckyoct.core.model.base.NetworkResult

interface ProfileRepository: ResultHandler {
suspend fun saveProfile(nickname: String, index: Int): NetworkResult<Unit>
suspend fun saveProfile(nickname: String, type: CharacterType): NetworkResult<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
package com.goalpanzi.mission_mate.core.domain.usecase

import com.goalpanzi.mission_mate.core.datastore.datasource.AuthDataSource
import com.goalpanzi.mission_mate.core.datastore.datasource.DefaultDataSource
import com.goalpanzi.mission_mate.core.domain.repository.AuthRepository
import com.luckyoct.core.model.GoogleLogin
import com.luckyoct.core.model.UserProfile
import com.luckyoct.core.model.response.GoogleLogin
import com.luckyoct.core.model.base.NetworkResult
import kotlinx.coroutines.flow.first
import javax.inject.Inject

class LoginUseCase @Inject constructor(
private val authRepository: AuthRepository,
private val authDataSource: AuthDataSource
private val authDataSource: AuthDataSource,
private val defaultDataSource: DefaultDataSource
) {
suspend fun requestGoogleLogin(email: String): GoogleLogin? {
return when (val response = authRepository.requestGoogleLogin(email)) {
is NetworkResult.Success -> {
response.data.also {
authDataSource.setAccessToken(it.accessToken).first()
authDataSource.setRefreshToken(it.refreshToken).first()
(it.nickname to it.characterType).let { (nickname, character) ->
if (nickname != null && character != null) {
defaultDataSource.setUserProfile(
UserProfile(nickname, character)
).first()
}
}
}
}

is NetworkResult.Error, is NetworkResult.Exception -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package com.goalpanzi.mission_mate.core.domain.usecase

import com.goalpanzi.mission_mate.core.datastore.datasource.DefaultDataSource
import com.goalpanzi.mission_mate.core.domain.repository.ProfileRepository
import com.luckyoct.core.model.CharacterType
import com.luckyoct.core.model.UserProfile
import com.luckyoct.core.model.base.NetworkResult
import kotlinx.coroutines.flow.first
import javax.inject.Inject

class ProfileUseCase @Inject constructor(
private val profileRepository: ProfileRepository
private val profileRepository: ProfileRepository,
private val defaultDataSource: DefaultDataSource
) {
suspend fun saveProfile(nickname: String, index: Int) = profileRepository.saveProfile(nickname, index)
suspend fun saveProfile(nickname: String, type: CharacterType) = profileRepository.saveProfile(nickname, type).also {
if (it is NetworkResult.Success) {
defaultDataSource.setUserProfile(UserProfile(nickname, type)).first()
}
}
suspend fun getProfile(): UserProfile? = defaultDataSource.getUserProfile().first()
}
1 change: 1 addition & 0 deletions core/model/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.kotlin.plugin.serialization)
alias(libs.plugins.kotlin.parcelize)
}

android {
Expand Down
24 changes: 24 additions & 0 deletions core/model/src/main/java/com/luckyoct/core/model/CharacterType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.luckyoct.core.model

import kotlinx.serialization.SerialName

enum class CharacterType {

@SerialName("RABBIT")
RABBIT,

@SerialName("CAT")
CAT,

@SerialName("DOG")
DOG,

@SerialName("PANDA")
PANDA,

@SerialName("BEAR")
BEAR,

@SerialName("BIRD")
BIRD
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.luckyoct.core.model

data class UserProfile(
val nickname: String,
val characterType: CharacterType
)
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.luckyoct.core.model.request

import com.luckyoct.core.model.CharacterType
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(
fun createRequest(nickname: String, type: CharacterType) = SaveProfileRequest(
nickname = nickname,
characterType = CharacterType.entries[index].name.uppercase()
characterType = type.name.uppercase()
)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.luckyoct.core.model
package com.luckyoct.core.model.response

import com.luckyoct.core.model.CharacterType
import kotlinx.serialization.Serializable

@Serializable
data class GoogleLogin(
val accessToken: String,
val refreshToken: String,
val nickname: String?,
val characterType: CharacterType?,
val isProfileSet: Boolean
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.luckyoct.core.model.response

import com.luckyoct.core.model.request.CharacterType
import com.luckyoct.core.model.CharacterType
import kotlinx.serialization.Serializable

@Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.luckyoct.core.model.response

import com.luckyoct.core.model.request.CharacterType
import com.luckyoct.core.model.CharacterType
import kotlinx.serialization.Serializable

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.serialization.json.Json
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Converter
import retrofit2.Retrofit
import retrofit2.converter.kotlinx.serialization.asConverterFactory
import java.security.KeyStore
import javax.inject.Singleton
import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManagerFactory
import javax.net.ssl.X509TrustManager

@Module
@InstallIn(SingletonComponent::class)
Expand All @@ -36,16 +31,9 @@ internal object NetworkModule {
httpLoggingInterceptor: HttpLoggingInterceptor,
tokenInterceptor: TokenInterceptor
): OkHttpClient {
// TLS 대응
val trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
trustManagerFactory.init(null as KeyStore?)
val trustManager = trustManagerFactory.trustManagers[0] as X509TrustManager
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(null, arrayOf(trustManager), java.security.SecureRandom())

return OkHttpClient.Builder()
.addInterceptor(tokenInterceptor)
.sslSocketFactory(sslContext.socketFactory, trustManager)
.addInterceptor(httpLoggingInterceptor)
.build()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.goalpanzi.mission_mate.core.network.service

import com.luckyoct.core.model.GoogleLogin
import com.luckyoct.core.model.response.GoogleLogin
import com.luckyoct.core.model.request.GoogleLoginRequest
import retrofit2.Response
import retrofit2.http.Body
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.goalpanzi.mission_mate.feature.board.model

import androidx.annotation.DrawableRes
import com.luckyoct.core.model.request.CharacterType
import com.luckyoct.core.model.CharacterType

enum class Character(
@DrawableRes val imageId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ internal fun MainNavHost(
settingNavGraph(
onBackClick = { navigator.popBackStack() },
onClickProfileSetting = { navigator.navigateToProfileSetting() },
onClickInquiry = { navigator.navigationToInquiry() },
onClickServicePolicy = { navigator.navigationToServicePolicy() },
onClickPrivacyPolicy = { navigator.navigationToPrivacyPolicy() },
onClickLogout = { navigator.navigateToLogin() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ class MainNavigator(
navController.navigateToSetting()
}

fun navigationToInquiry() {
navController.navigateToInquiry()
}

fun navigationToServicePolicy() {
navController.navigateToServicePolicy()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ fun NavGraphBuilder.profileNavGraph(
composable<RouteModel.Profile.Create> {
ProfileRoute(
profileSettingType = ProfileSettingType.CREATE,
onSaveSuccess = { onSaveSuccess() }
onSaveSuccess = onSaveSuccess
)
}
composable<RouteModel.Profile.Setting> {
ProfileRoute(
profileSettingType = ProfileSettingType.SETTING,
onSaveSuccess = { onSaveSuccess() },
onBackClick = { onBackClick() }
onSaveSuccess = onBackClick,
onBackClick = onBackClick
)
}
}
Loading

0 comments on commit ebab65d

Please sign in to comment.