更新 google 登录
This commit is contained in:
@@ -2,9 +2,9 @@ package com.aiosman.riderpro.data
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import com.aiosman.riderpro.AppStore
|
||||
import com.aiosman.riderpro.data.api.ApiClient
|
||||
import com.aiosman.riderpro.data.api.ChangePasswordRequestBody
|
||||
import com.aiosman.riderpro.data.api.GoogleRegisterRequestBody
|
||||
import com.aiosman.riderpro.data.api.LoginUserRequestBody
|
||||
import com.aiosman.riderpro.data.api.RegisterRequestBody
|
||||
import com.aiosman.riderpro.data.api.UpdateNoticeRequestBody
|
||||
@@ -24,11 +24,13 @@ data class AccountLikeEntity(
|
||||
val user: NoticeUserEntity,
|
||||
val likeTime: Date,
|
||||
)
|
||||
|
||||
data class AccountFavouriteEntity(
|
||||
val post: NoticePostEntity,
|
||||
val user: NoticeUserEntity,
|
||||
val favoriteTime: Date,
|
||||
)
|
||||
|
||||
data class AccountProfileEntity(
|
||||
val id: Int,
|
||||
val followerCount: Int,
|
||||
@@ -281,10 +283,12 @@ interface AccountService {
|
||||
suspend fun getAccountProfileById(id: Int): AccountProfileEntity
|
||||
suspend fun getMyAccount(): UserAuth
|
||||
suspend fun loginUserWithPassword(loginName: String, password: String): UserAuth
|
||||
suspend fun loginUserWithGoogle(googleId: String): UserAuth
|
||||
suspend fun logout()
|
||||
suspend fun updateAvatar(uri: String)
|
||||
suspend fun updateProfile(avatar: UploadImage?, nickName: String?, bio: String?)
|
||||
suspend fun registerUserWithPassword(loginName: String, password: String)
|
||||
suspend fun regiterUserWithGoogleAccount(idToken: String)
|
||||
suspend fun changeAccountPassword(oldPassword: String, newPassword: String)
|
||||
suspend fun getMyLikeNotice(page: Int, pageSize: Int): ListContainer<AccountLike>
|
||||
suspend fun getMyFollowNotice(page: Int, pageSize: Int): ListContainer<AccountFollow>
|
||||
@@ -293,7 +297,7 @@ interface AccountService {
|
||||
suspend fun updateNotice(payload: UpdateNoticeRequestBody)
|
||||
}
|
||||
|
||||
class TestAccountServiceImpl : AccountService {
|
||||
class AccountServiceImpl : AccountService {
|
||||
override suspend fun getMyAccountProfile(): AccountProfileEntity {
|
||||
val resp = ApiClient.api.getMyAccount()
|
||||
val body = resp.body() ?: throw ServiceException("Failed to get account")
|
||||
@@ -318,6 +322,19 @@ class TestAccountServiceImpl : AccountService {
|
||||
return UserAuth(0, body.token)
|
||||
}
|
||||
|
||||
override suspend fun loginUserWithGoogle(googleId: String): UserAuth {
|
||||
val resp = ApiClient.api.login(LoginUserRequestBody(googleId=googleId))
|
||||
val body = resp.body() ?: throw ServiceException("Failed to login")
|
||||
return UserAuth(0, body.token)
|
||||
}
|
||||
|
||||
override suspend fun regiterUserWithGoogleAccount(idToken: String) {
|
||||
val resp = ApiClient.api.registerWithGoogle(GoogleRegisterRequestBody(idToken))
|
||||
if (resp.code() != 200) {
|
||||
throw ServiceException("Failed to register")
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun logout() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -27,14 +27,22 @@ data class RegisterRequestBody(
|
||||
@SerializedName("username")
|
||||
val username: String,
|
||||
@SerializedName("password")
|
||||
val password: String
|
||||
)
|
||||
val password: String,
|
||||
|
||||
)
|
||||
|
||||
data class LoginUserRequestBody(
|
||||
@SerializedName("username")
|
||||
val username: String,
|
||||
val username: String? = null,
|
||||
@SerializedName("password")
|
||||
val password: String
|
||||
val password: String? = null,
|
||||
@SerializedName("googleId")
|
||||
val googleId: String? = null,
|
||||
)
|
||||
|
||||
data class GoogleRegisterRequestBody(
|
||||
@SerializedName("idToken")
|
||||
val idToken: String
|
||||
)
|
||||
|
||||
data class AuthResult(
|
||||
@@ -219,4 +227,7 @@ interface RiderProAPI {
|
||||
@Query("nickname") search: String? = null,
|
||||
): Response<ListContainer<AccountProfile>>
|
||||
|
||||
@POST("register/google")
|
||||
suspend fun registerWithGoogle(@Body body: GoogleRegisterRequestBody): Response<AuthResult>
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user