更新
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
package com.aiosman.riderpro.data
|
||||
|
||||
import com.aiosman.riderpro.AppStore
|
||||
import com.aiosman.riderpro.data.api.ApiClient
|
||||
import com.aiosman.riderpro.data.api.LoginUserRequestBody
|
||||
import com.aiosman.riderpro.data.api.RegisterRequestBody
|
||||
import com.aiosman.riderpro.test.TestDatabase
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import java.io.File
|
||||
|
||||
data class AccountProfileEntity(
|
||||
val id: Int,
|
||||
@@ -15,6 +22,7 @@ data class AccountProfileEntity(
|
||||
val country: String,
|
||||
val isFollowing: Boolean
|
||||
)
|
||||
|
||||
//{
|
||||
// "id": 1,
|
||||
// "username": "root",
|
||||
@@ -23,7 +31,7 @@ data class AccountProfileEntity(
|
||||
// "followingCount": 1,
|
||||
// "followerCount": 0
|
||||
//}
|
||||
data class AccountProfile (
|
||||
data class AccountProfile(
|
||||
val id: Int,
|
||||
val username: String,
|
||||
val nickname: String,
|
||||
@@ -38,13 +46,14 @@ data class AccountProfile (
|
||||
followerCount = followerCount,
|
||||
followingCount = followingCount,
|
||||
nickName = nickname,
|
||||
avatar = ApiClient.BASE_SERVER + avatar,
|
||||
avatar = ApiClient.BASE_SERVER + avatar + "?token=${AppStore.token}",
|
||||
bio = "",
|
||||
country = "Worldwide",
|
||||
isFollowing = isFollowing
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
interface AccountService {
|
||||
suspend fun getMyAccountProfile(): AccountProfileEntity
|
||||
suspend fun getAccountProfileById(id: Int): AccountProfileEntity
|
||||
@@ -52,7 +61,7 @@ interface AccountService {
|
||||
suspend fun loginUserWithPassword(loginName: String, password: String): UserAuth
|
||||
suspend fun logout()
|
||||
suspend fun updateAvatar(uri: String)
|
||||
suspend fun updateProfile(nickName: String, bio: String)
|
||||
suspend fun updateProfile(avatar: UploadImage?, nickName: String?, bio: String?)
|
||||
suspend fun registerUserWithPassword(loginName: String, password: String)
|
||||
}
|
||||
|
||||
@@ -95,14 +104,17 @@ class TestAccountServiceImpl : AccountService {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
fun createMultipartBody(file: File, filename:String,name: String): MultipartBody.Part {
|
||||
val requestFile = file.asRequestBody("image/*".toMediaTypeOrNull())
|
||||
return MultipartBody.Part.createFormData(name, filename, requestFile)
|
||||
}
|
||||
|
||||
override suspend fun updateProfile(avatar: UploadImage?, nickName: String?, bio: String?) {
|
||||
val nicknameField: RequestBody? = nickName?.toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
val avatarField: MultipartBody.Part? = avatar?.let {
|
||||
createMultipartBody(it.file,it.filename, "avatar")
|
||||
}
|
||||
ApiClient.api.updateProfile(avatarField, nicknameField)
|
||||
}
|
||||
|
||||
override suspend fun registerUserWithPassword(loginName: String, password: String) {
|
||||
|
||||
@@ -2,6 +2,7 @@ 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.CommentRequestBody
|
||||
import com.aiosman.riderpro.test.TestDatabase
|
||||
@@ -52,7 +53,7 @@ data class Comment(
|
||||
likes = likeCount,
|
||||
replies = emptyList(),
|
||||
postId = 0,
|
||||
avatar = ApiClient.BASE_SERVER + user.avatar,
|
||||
avatar = ApiClient.BASE_SERVER + user.avatar + "?token=${AppStore.token}",
|
||||
author = user.id,
|
||||
liked = isLiked
|
||||
)
|
||||
|
||||
@@ -43,9 +43,10 @@ data class Moment(
|
||||
val time: String
|
||||
) {
|
||||
fun toMomentItem(): MomentEntity {
|
||||
val avatar = ApiClient.BASE_SERVER + user.avatar + "?token=${AppStore.token}"
|
||||
return MomentEntity(
|
||||
id = id.toInt(),
|
||||
avatar = ApiClient.BASE_SERVER + user.avatar,
|
||||
avatar = ApiClient.BASE_SERVER + user.avatar + "?token=${AppStore.token}",
|
||||
nickname = user.nickName,
|
||||
location = "Worldwide",
|
||||
time = time,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.aiosman.riderpro.data.api
|
||||
|
||||
import com.aiosman.riderpro.AppStore
|
||||
import com.aiosman.riderpro.ConstVars
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Response
|
||||
@@ -16,7 +17,7 @@ class AuthInterceptor() : Interceptor {
|
||||
}
|
||||
|
||||
object ApiClient {
|
||||
const val BASE_SERVER = "http://192.168.31.57:8088"
|
||||
const val BASE_SERVER = ConstVars.BASE_SERVER
|
||||
const val BASE_API_URL = "${BASE_SERVER}/api/v1"
|
||||
const val RETROFIT_URL = "${BASE_API_URL}/"
|
||||
private val okHttpClient: OkHttpClient by lazy {
|
||||
|
||||
@@ -13,6 +13,7 @@ import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Multipart
|
||||
import retrofit2.http.PATCH
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.Part
|
||||
import retrofit2.http.Path
|
||||
@@ -128,6 +129,13 @@ interface RiderProAPI {
|
||||
@GET("account/my")
|
||||
suspend fun getMyAccount(): Response<DataContainer<AccountProfile>>
|
||||
|
||||
@Multipart
|
||||
@PATCH("account/my/profile")
|
||||
suspend fun updateProfile(
|
||||
@Part avatar: MultipartBody.Part?,
|
||||
@Part("nickname") nickname: RequestBody?,
|
||||
): Response<Unit>
|
||||
|
||||
@GET("profile/{id}")
|
||||
suspend fun getAccountProfileById(
|
||||
@Path("id") id: Int
|
||||
|
||||
Reference in New Issue
Block a user