2024-07-29 00:01:09 +08:00
|
|
|
package com.aiosman.riderpro.data
|
|
|
|
|
|
2024-08-11 17:15:17 +08:00
|
|
|
import com.aiosman.riderpro.data.api.ApiClient
|
2024-08-24 23:11:20 +08:00
|
|
|
import com.aiosman.riderpro.entity.AccountProfileEntity
|
2024-07-29 00:01:09 +08:00
|
|
|
|
2024-07-30 16:57:25 +08:00
|
|
|
data class UserAuth(
|
|
|
|
|
val id: Int,
|
|
|
|
|
val token: String? = null
|
|
|
|
|
)
|
|
|
|
|
|
2024-08-24 23:11:20 +08:00
|
|
|
/**
|
|
|
|
|
* 用户相关 Service
|
|
|
|
|
*/
|
2024-07-29 00:01:09 +08:00
|
|
|
interface UserService {
|
2024-08-24 23:11:20 +08:00
|
|
|
/**
|
|
|
|
|
* 获取用户信息
|
|
|
|
|
* @param id 用户ID
|
|
|
|
|
* @return 用户信息
|
|
|
|
|
*/
|
2024-08-11 17:15:17 +08:00
|
|
|
suspend fun getUserProfile(id: String): AccountProfileEntity
|
2024-08-24 23:11:20 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 关注用户
|
|
|
|
|
* @param id 用户ID
|
|
|
|
|
*/
|
2024-08-11 17:15:17 +08:00
|
|
|
suspend fun followUser(id: String)
|
2024-08-24 23:11:20 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 取消关注用户
|
|
|
|
|
* @param id 用户ID
|
|
|
|
|
*/
|
2024-08-11 17:15:17 +08:00
|
|
|
suspend fun unFollowUser(id: String)
|
2024-08-24 23:11:20 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取用户列表
|
|
|
|
|
* @param pageSize 分页大小
|
|
|
|
|
* @param page 页码
|
|
|
|
|
* @param nickname 昵称搜索
|
2024-09-06 01:55:12 +08:00
|
|
|
* @param followerId 粉丝ID,账号粉丝
|
|
|
|
|
* @param followingId 关注ID,账号关注
|
2024-08-24 23:11:20 +08:00
|
|
|
* @return 用户列表
|
|
|
|
|
*/
|
2024-08-17 17:40:21 +08:00
|
|
|
suspend fun getUsers(
|
|
|
|
|
pageSize: Int = 20,
|
|
|
|
|
page: Int = 1,
|
2024-09-06 01:55:12 +08:00
|
|
|
nickname: String? = null,
|
|
|
|
|
followerId: Int? = null,
|
|
|
|
|
followingId: Int? = null
|
2024-08-17 17:40:21 +08:00
|
|
|
): ListContainer<AccountProfileEntity>
|
2024-07-31 14:50:55 +08:00
|
|
|
|
2024-09-27 21:11:48 +08:00
|
|
|
suspend fun getUserProfileByTrtcUserId(id: String):AccountProfileEntity
|
|
|
|
|
|
2024-07-29 00:01:09 +08:00
|
|
|
}
|
|
|
|
|
|
2024-08-24 23:11:20 +08:00
|
|
|
class UserServiceImpl : UserService {
|
2024-08-11 17:15:17 +08:00
|
|
|
override suspend fun getUserProfile(id: String): AccountProfileEntity {
|
|
|
|
|
val resp = ApiClient.api.getAccountProfileById(id.toInt())
|
|
|
|
|
val body = resp.body() ?: throw ServiceException("Failed to get account")
|
|
|
|
|
return body.data.toAccountProfileEntity()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override suspend fun followUser(id: String) {
|
|
|
|
|
val resp = ApiClient.api.followUser(id.toInt())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override suspend fun unFollowUser(id: String) {
|
|
|
|
|
val resp = ApiClient.api.unfollowUser(id.toInt())
|
|
|
|
|
return
|
2024-07-29 00:01:09 +08:00
|
|
|
}
|
2024-08-17 17:40:21 +08:00
|
|
|
|
|
|
|
|
override suspend fun getUsers(
|
|
|
|
|
pageSize: Int,
|
|
|
|
|
page: Int,
|
2024-09-06 01:55:12 +08:00
|
|
|
nickname: String?,
|
|
|
|
|
followerId: Int?,
|
|
|
|
|
followingId: Int?
|
2024-08-17 17:40:21 +08:00
|
|
|
): ListContainer<AccountProfileEntity> {
|
2024-09-06 01:55:12 +08:00
|
|
|
val resp = ApiClient.api.getUsers(
|
|
|
|
|
page = page,
|
|
|
|
|
pageSize = pageSize,
|
|
|
|
|
search = nickname,
|
|
|
|
|
followerId = followerId,
|
|
|
|
|
followingId = followingId
|
|
|
|
|
)
|
2024-08-17 17:40:21 +08:00
|
|
|
val body = resp.body() ?: throw ServiceException("Failed to get account")
|
|
|
|
|
return ListContainer<AccountProfileEntity>(
|
|
|
|
|
list = body.list.map { it.toAccountProfileEntity() },
|
|
|
|
|
page = body.page,
|
|
|
|
|
total = body.total,
|
2024-09-06 01:55:12 +08:00
|
|
|
pageSize = body.pageSize,
|
2024-08-17 17:40:21 +08:00
|
|
|
)
|
|
|
|
|
}
|
2024-09-27 21:11:48 +08:00
|
|
|
|
|
|
|
|
override suspend fun getUserProfileByTrtcUserId(id: String): AccountProfileEntity {
|
|
|
|
|
val resp = ApiClient.api.getAccountProfileByTrtcUserId(id)
|
|
|
|
|
val body = resp.body() ?: throw ServiceException("Failed to get account")
|
|
|
|
|
return body.data.toAccountProfileEntity()
|
|
|
|
|
}
|
2024-07-29 00:01:09 +08:00
|
|
|
}
|