Skip to content

Commit

Permalink
Implement profile edit.
Browse files Browse the repository at this point in the history
  • Loading branch information
bywindow committed Aug 13, 2024
1 parent 32c7757 commit 26ff8af
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 165 deletions.
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)
}
}
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,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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ data class SaveProfileRequest(
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,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
@@ -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 @@ -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 26ff8af

Please sign in to comment.