Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#205 : 프로필 수정 푸시 클릭 동작 구현해요 #207

Merged
merged 12 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/kotlin/com/bff/wespot/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ private fun navigateScreenFromNavArgs(
navigator.navigateToVoteStorageScreen()
}

NotificationType.PROFILE_UPDATE -> {
navigator.navigateToProfileEditScreen()
}

NotificationType.IDLE -> {
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.bff.wespot

import androidx.navigation.NavController
import com.bff.wespot.entire.screen.destinations.ProfileEditScreenDestination
import com.bff.wespot.entire.screen.edit.ProfileEditNavArgs
import com.bff.wespot.message.screen.MessageScreenArgs
import com.bff.wespot.message.screen.destinations.MessageScreenDestination
import com.bff.wespot.message.screen.destinations.ReceiverSelectionScreenDestination
Expand Down Expand Up @@ -60,4 +62,8 @@ class NotificationNavigatorImpl(private val navController: NavController): Notif
override fun navigateToVoteStorageScreen() {
navController.navigate(VoteStorageScreenDestination within AppNavGraphs.vote)
}

override fun navigateToProfileEditScreen() {
navController.navigate(ProfileEditScreenDestination(ProfileEditNavArgs(false)) within AppNavGraphs.entire)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.bff.wespot.model.auth.request

data class SignIn(
val accessToken: String,
val versionName: String,
val socialType: String = "KAKAO",
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class SignUp(
val grade: Int,
val classNumber: Int,
val gender: String,
val versionName: String,
val consents: Consents,
val profileUrl: String?,
val introduction: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ enum class NotificationType {
VOTE,
VOTE_RESULT,
VOTE_RECEIVED,
PROFILE_UPDATE,
;

fun toDescription(): String = when (this) {
MESSAGE, MESSAGE_SENT, MESSAGE_RECEIVED -> "쪽지 알림"
VOTE, VOTE_RESULT, VOTE_RECEIVED -> "투표 알림"
PROFILE_UPDATE -> "프로필 알림"
IDLE -> ""
}

Expand All @@ -27,6 +29,7 @@ enum class NotificationType {
VOTE.name -> VOTE
VOTE_RESULT.name -> VOTE_RESULT
VOTE_RECEIVED.name -> VOTE_RECEIVED
PROFILE_UPDATE.name -> PROFILE_UPDATE
else -> IDLE
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.bff.wespot.data.remote.model.auth.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class KakaoAuthTokenDto(
data class SignInDto(
val socialType: String,
val identityToken: String,
val fcmToken: String,
)
@SerialName("androidVersionName") val versionName: String,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bff.wespot.data.remote.model.auth.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
Expand All @@ -10,7 +11,8 @@ data class SignUpDto(
val classNumber: Int,
val gender: String,
val signUpToken: String,
@SerialName("androidVersionNameWhenSignUp") val versionName: String,
val consents: ConsentsDto,
val introduction: String?,
val profileUrl: String?,
)
)
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.bff.wespot.data.remote.source.auth

import com.bff.wespot.data.remote.model.auth.request.KakaoAuthTokenDto
import com.bff.wespot.data.remote.model.auth.request.SignInDto
import com.bff.wespot.data.remote.model.auth.request.SignUpDto
import com.bff.wespot.data.remote.model.auth.response.AuthTokenDto
import com.bff.wespot.data.remote.model.auth.response.SchoolListDto
import com.bff.wespot.model.auth.request.RevokeReasonListDto

interface AuthDataSource {
suspend fun getSchoolList(search: String, cursorId: Int?): Result<SchoolListDto>
suspend fun sendKakaoToken(token: KakaoAuthTokenDto): Result<Any>
suspend fun signIn(signIn: SignInDto): Result<Any>
suspend fun signUp(signUp: SignUpDto): Result<AuthTokenDto>
suspend fun revoke(revokeReasonList: RevokeReasonListDto): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bff.wespot.data.remote.source.auth

import com.bff.wespot.data.remote.extensions.invalidateBearerTokens
import com.bff.wespot.data.remote.model.auth.request.KakaoAuthTokenDto
import com.bff.wespot.data.remote.model.auth.request.SignInDto
import com.bff.wespot.data.remote.model.auth.request.SignUpDto
import com.bff.wespot.data.remote.model.auth.response.AuthTokenDto
import com.bff.wespot.data.remote.model.auth.response.SchoolListDto
Expand All @@ -27,13 +27,13 @@ class AuthDataSourceImpl @Inject constructor(
}
}

override suspend fun sendKakaoToken(token: KakaoAuthTokenDto): Result<Any> {
override suspend fun signIn(signIn: SignInDto): Result<Any> {
val client = httpClient.safeRequest<Any> {
url {
method = HttpMethod.Post
path("api/v1/auth/login")
}
setBody(token)
setBody(signIn)
}
httpClient.invalidateBearerTokens()
return client
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.bff.wespot.data.mapper.auth

import com.bff.wespot.data.remote.model.auth.request.ConsentsDto
import com.bff.wespot.data.remote.model.auth.request.KakaoAuthTokenDto
import com.bff.wespot.data.remote.model.auth.request.SignInDto
import com.bff.wespot.data.remote.model.auth.request.SignUpDto
import com.bff.wespot.model.auth.request.KakaoAuthToken
import com.bff.wespot.model.auth.request.SignIn
import com.bff.wespot.model.auth.request.SignUp
import com.bff.wespot.model.auth.response.Consents

internal fun KakaoAuthToken.toDto(fcmToken: String) =
KakaoAuthTokenDto(
internal fun SignIn.toDto(fcmToken: String) =
SignInDto(
socialType = socialType,
identityToken = accessToken,
versionName = versionName,
fcmToken = fcmToken,
)

Expand All @@ -27,6 +28,7 @@ internal fun SignUp.toDto(token: String) =
classNumber = classNumber,
gender = gender,
signUpToken = token,
versionName = versionName,
consents = consents.toDto(),
profileUrl = profileUrl,
introduction = introduction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.bff.wespot.data.remote.model.auth.response.SignUpTokenDto
import com.bff.wespot.data.remote.source.auth.AuthDataSource
import com.bff.wespot.domain.repository.auth.AuthRepository
import com.bff.wespot.domain.util.DataStoreKey
import com.bff.wespot.model.auth.request.KakaoAuthToken
import com.bff.wespot.model.auth.request.RevokeReasonListDto
import com.bff.wespot.model.auth.request.SignIn
import com.bff.wespot.model.auth.request.SignUp
import kotlinx.coroutines.flow.first
import javax.inject.Inject
Expand All @@ -17,9 +17,11 @@ class AuthRepositoryImpl @Inject constructor(
private val authDataSource: AuthDataSource,
private val dataStore: WeSpotDataStore
) : AuthRepository {
override suspend fun sendKakaoToken(token: KakaoAuthToken): Result<Any> =
authDataSource
.sendKakaoToken(token.toDto(dataStore.getString(DataStoreKey.PUSH_TOKEN).first()))
override suspend fun signIn(signIn: SignIn): Result<Any> {
val fcmToken = dataStore.getString(DataStoreKey.PUSH_TOKEN).first()
val signInDto = signIn.toDto(fcmToken)
return authDataSource
.signIn(signInDto)
.mapCatching {
when (it) {
is AuthTokenDto -> {
Expand All @@ -33,6 +35,7 @@ class AuthRepositoryImpl @Inject constructor(
else -> throw IllegalArgumentException("Unknown token type")
}
}
}

override suspend fun signUp(signUp: SignUp): Boolean {
val response = authDataSource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.bff.wespot.domain.repository.auth

import com.bff.wespot.model.auth.request.KakaoAuthToken
import com.bff.wespot.model.auth.request.SignIn
import com.bff.wespot.model.auth.request.SignUp

interface AuthRepository {
suspend fun sendKakaoToken(token: KakaoAuthToken): Result<Any>
suspend fun signIn(signIn: SignIn): Result<Any>
suspend fun signUp(signUp: SignUp): Boolean
suspend fun revoke(revokeReasonList: List<String>): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class AutoLoginUseCase @Inject constructor(
private val dataStoreRepository: DataStoreRepository,
private val remoteConfigRepository: RemoteConfigRepository,
) {
suspend operator fun invoke(versionCode: String): LoginState {
suspend operator fun invoke(versionName: String): LoginState {
val minVersion = remoteConfigRepository.fetchFromRemoteConfig(RemoteConfigKey.MIN_VERSION)

if (versionCompare(minVersion, versionCode)) {
if (versionCompare(minVersion, versionName)) {
return LoginState.FORCE_UPDATE
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.bff.wespot.domain.repository.DataStoreRepository
import com.bff.wespot.domain.repository.auth.AuthRepository
import com.bff.wespot.domain.repository.firebase.messaging.MessagingRepository
import com.bff.wespot.domain.util.DataStoreKey
import com.bff.wespot.model.auth.request.KakaoAuthToken
import com.bff.wespot.model.auth.request.SignIn
import com.bff.wespot.model.auth.response.AuthToken
import com.bff.wespot.model.auth.response.SignUpToken
import com.bff.wespot.model.constants.LoginState
Expand All @@ -15,11 +15,11 @@ class KakaoLoginUseCase @Inject constructor(
private val authRepository: AuthRepository,
private val dataStoreRepository: DataStoreRepository,
) {
suspend operator fun invoke(result: KakaoAuthToken): Result<LoginState> {
suspend operator fun invoke(signIn: SignIn): Result<LoginState> {
val token = messagingRepository.getFcmToken()
dataStoreRepository.saveString(DataStoreKey.PUSH_TOKEN, token)

return authRepository.sendKakaoToken(result)
return authRepository.signIn(signIn)
.map {
when (it) {
is AuthToken -> {
Expand Down
23 changes: 11 additions & 12 deletions feature/auth/src/main/kotlin/com/bff/wespot/auth/AuthActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bff.wespot.auth

import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.ViewTreeObserver
Expand Down Expand Up @@ -66,9 +67,10 @@ class AuthActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val toastMessage = intent.getStringExtra(EXTRA_TOAST_MESSAGE)
viewModel.onAction(AuthAction.OnActivityCreated(getAppVersionName(this)))

setContent {
var showDialog by remember {
var showVersionUpdateDialog by remember {
mutableStateOf(false)
}
val context = LocalContext.current
Expand All @@ -78,11 +80,8 @@ class AuthActivity : ComponentActivity() {
var showToast by remember { mutableStateOf(true) }

val state by viewModel.collectAsState()
val action = viewModel::onAction

login {
showDialog = true
}
login(showVersionUpdateDialog = { showVersionUpdateDialog = true })

viewModel.collectSideEffect {
when (it) {
Expand Down Expand Up @@ -160,7 +159,7 @@ class AuthActivity : ComponentActivity() {
LoadingAnimation()
}

if (showDialog) {
if (showVersionUpdateDialog) {
WSDialog(
title = stringResource(R.string.new_version),
subTitle = stringResource(R.string.update_to_new_version),
Expand All @@ -180,12 +179,9 @@ class AuthActivity : ComponentActivity() {
}

private fun login(
showUpdateDialog: () -> Unit,
showVersionUpdateDialog: () -> Unit,
) {
val packageInfo = packageManager.getPackageInfo(packageName, 0)
val versionCode = packageInfo.versionName

viewModel.onAction(AuthAction.AutoLogin(versionCode))
viewModel.onAction(AuthAction.AutoLogin)
viewModel.loginState.observe(this) {
loginState = it
}
Expand All @@ -209,7 +205,7 @@ class AuthActivity : ComponentActivity() {
)
startActivity(intent)
} else if (loginState == LoginState.FORCE_UPDATE) {
showUpdateDialog()
showVersionUpdateDialog()
}

content.viewTreeObserver.removeOnPreDrawListener(this)
Expand All @@ -221,3 +217,6 @@ class AuthActivity : ComponentActivity() {
})
}
}

private fun getAppVersionName(context: Context): String =
context.packageManager.getPackageInfo(context.packageName, 0).versionName
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.bff.wespot.auth.screen
import androidx.annotation.DrawableRes
import androidx.annotation.RawRes
import androidx.annotation.StringRes
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -49,7 +48,6 @@ import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootNavGraph
import kotlinx.coroutines.launch

@OptIn(ExperimentalFoundationApi::class)
@Destination
@RootNavGraph(start = true)
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ sealed class AuthAction {

data object Signup : AuthAction()

data class AutoLogin(val versionCode: String) : AuthAction()
data class OnActivityCreated(val versionName: String) : AuthAction()

data object AutoLogin : AuthAction()

data object OnStartSchoolScreen : AuthAction()

Expand Down
Loading