Skip to content

Commit

Permalink
feat: 로그인, 토큰 갱신 API 수정 - deviceIdentifier, osType 필드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
eshc123 committed Dec 19, 2024
1 parent 6feb32b commit df7101d
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.goalpanzi.mission_mate.core.data.auth.repository

import com.goalpanzi.mission_mate.core.data.auth.mapper.toModel
import com.goalpanzi.mission_mate.core.data.common.DeviceInfoProvider
import com.goalpanzi.mission_mate.core.data.common.handleResult
import com.goalpanzi.mission_mate.core.datastore.datasource.AuthDataSource
import com.goalpanzi.mission_mate.core.domain.auth.repository.AuthRepository
Expand All @@ -13,11 +14,15 @@ import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
private val loginService: LoginService,
private val authDataSource: AuthDataSource
): AuthRepository {
private val authDataSource: AuthDataSource,
private val deviceInfoProvider: DeviceInfoProvider
) : AuthRepository {

override suspend fun requestGoogleLogin(email: String) = handleResult {
val request = GoogleLoginRequest(email = email)
val request = GoogleLoginRequest(
email = email,
deviceIdentifier = deviceInfoProvider.getDeviceSSAID()
)
loginService.requestGoogleLogin(request)
}.convert {
it.toModel()
Expand All @@ -35,7 +40,9 @@ class AuthRepositoryImpl @Inject constructor(

override fun getRefreshToken(): Flow<String?> = authDataSource.getRefreshToken()

override fun setAccessToken(accessToken: String): Flow<Unit> = authDataSource.setAccessToken(accessToken)
override fun setAccessToken(accessToken: String): Flow<Unit> =
authDataSource.setAccessToken(accessToken)

override fun setRefreshToken(refreshToken: String): Flow<Unit> = authDataSource.setRefreshToken(refreshToken)
override fun setRefreshToken(refreshToken: String): Flow<Unit> =
authDataSource.setRefreshToken(refreshToken)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.goalpanzi.mission_mate.core.data.common

import android.annotation.SuppressLint
import android.content.Context
import android.provider.Settings
import javax.inject.Inject

class DeviceInfoProvider @Inject constructor(
private val context: Context
) {
@SuppressLint("HardwareIds")
fun getDeviceSSAID(): String {
return Settings.Secure.getString(context.contentResolver,Settings.Secure.ANDROID_ID)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.goalpanzi.mission_mate.core.data.common.di

import android.content.Context
import com.goalpanzi.mission_mate.core.data.common.DeviceInfoProvider
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
object DeviceInfoProviderModule {
@Singleton
@Provides
fun provideADeviceInfoProvider(
@ApplicationContext context: Context
): DeviceInfoProvider {
return DeviceInfoProvider(context)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.goalpanzi.mission_mate.core.data.user.repository

import com.goalpanzi.mission_mate.core.data.common.DeviceInfoProvider
import com.goalpanzi.mission_mate.core.data.common.handleResult
import com.goalpanzi.mission_mate.core.data.common.mapper.toResponse
import com.goalpanzi.mission_mate.core.data.user.FcmTokenManager
Expand All @@ -20,7 +21,8 @@ import javax.inject.Inject
class UserRepositoryImpl @Inject constructor(
private val profileService: ProfileService,
private val defaultDataSource: DefaultDataSource,
private val fcmTokenManager: FcmTokenManager
private val fcmTokenManager: FcmTokenManager,
private val deviceInfoProvider: DeviceInfoProvider
) : UserRepository {
override suspend fun saveProfile(
nickname: String,
Expand All @@ -35,7 +37,11 @@ class UserRepositoryImpl @Inject constructor(
}

override suspend fun updateFcmToken(fcmToken: String): DomainResult<Unit> = handleResult {
val request = UpdateDeviceTokenRequest(fcmToken)
val request = UpdateDeviceTokenRequest(
deviceToken = fcmToken,
deviceIdentifier = deviceInfoProvider.getDeviceSSAID(),
osType = "AOS"
)
profileService.updateDeviceToken(request)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import kotlinx.serialization.Serializable

@Serializable
data class GoogleLoginRequest(
val email: String
val email: String,
val deviceIdentifier: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ import kotlinx.serialization.Serializable

@Serializable
data class UpdateDeviceTokenRequest(
val deviceToken: String
val deviceToken: String,
val deviceIdentifier: String,
val osType: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ProfileService {
@Body request: SaveProfileRequest
): Response<Unit>

@PATCH("/api/member/device-token")
@PATCH("/api/device/device-token")
suspend fun updateDeviceToken(
@Body request: UpdateDeviceTokenRequest
): Response<Unit>
Expand Down

0 comments on commit df7101d

Please sign in to comment.