Files
rider-pro-android-app/app/src/main/java/com/aiosman/riderpro/data/AccountService.kt

64 lines
1.8 KiB
Kotlin
Raw Normal View History

2024-07-29 00:01:09 +08:00
package com.aiosman.riderpro.data
2024-07-29 16:50:07 +08:00
import com.aiosman.riderpro.test.TestDatabase
2024-07-29 00:01:09 +08:00
data class AccountProfile(
val id: Int,
val followerCount: Int,
val followingCount: Int,
val nickName: String,
val avatar: String,
val bio: String,
val country: String,
)
interface AccountService {
2024-07-29 16:50:07 +08:00
suspend fun getMyAccountProfile(): AccountProfile
suspend fun getAccountProfileById(id: Int): AccountProfile
2024-07-31 14:50:55 +08:00
suspend fun getMyAccount(): UserAuth
suspend fun loginUserWithPassword(loginName: String, password: String): UserAuth
suspend fun logout()
suspend fun updateAvatar(uri: String)
suspend fun updateProfile(nickName: String, bio: String)
2024-07-29 00:01:09 +08:00
}
class TestAccountServiceImpl : AccountService {
2024-07-29 16:50:07 +08:00
override suspend fun getMyAccountProfile(): AccountProfile {
2024-07-31 14:50:55 +08:00
return TestDatabase.accountData.first { it.id == 1 }
2024-07-29 16:50:07 +08:00
}
override suspend fun getAccountProfileById(id: Int): AccountProfile {
return TestDatabase.accountData.first { it.id == id }
2024-07-29 00:01:09 +08:00
}
2024-07-31 14:50:55 +08:00
override suspend fun getMyAccount(): UserAuth {
return UserAuth(1)
}
override suspend fun loginUserWithPassword(loginName: String, password: String): UserAuth {
return UserAuth(1, "token")
}
override suspend fun logout() {
// do nothing
}
override suspend fun updateAvatar(uri: String) {
TestDatabase.accountData = TestDatabase.accountData.map {
if (it.id == 1) {
it.copy(avatar = uri)
} else {
it
}
}
}
override suspend fun updateProfile(nickName: String, bio: String) {
TestDatabase.accountData = TestDatabase.accountData.map {
if (it.id == 1) {
it.copy(nickName = nickName, bio = bio)
} else {
it
}
}
}
2024-07-29 00:01:09 +08:00
}