package com.aiosman.riderpro.data import com.aiosman.riderpro.data.api.ApiClient import com.aiosman.riderpro.entity.AccountProfileEntity data class UserAuth( val id: Int, val token: String? = null ) /** * 用户相关 Service */ interface UserService { /** * 获取用户信息 * @param id 用户ID * @return 用户信息 */ suspend fun getUserProfile(id: String): AccountProfileEntity /** * 关注用户 * @param id 用户ID */ suspend fun followUser(id: String) /** * 取消关注用户 * @param id 用户ID */ suspend fun unFollowUser(id: String) /** * 获取用户列表 * @param pageSize 分页大小 * @param page 页码 * @param nickname 昵称搜索 * @param followerId 粉丝ID,账号粉丝 * @param followingId 关注ID,账号关注 * @return 用户列表 */ suspend fun getUsers( pageSize: Int = 20, page: Int = 1, nickname: String? = null, followerId: Int? = null, followingId: Int? = null ): ListContainer } class UserServiceImpl : UserService { 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 } override suspend fun getUsers( pageSize: Int, page: Int, nickname: String?, followerId: Int?, followingId: Int? ): ListContainer { val resp = ApiClient.api.getUsers( page = page, pageSize = pageSize, search = nickname, followerId = followerId, followingId = followingId ) val body = resp.body() ?: throw ServiceException("Failed to get account") return ListContainer( list = body.list.map { it.toAccountProfileEntity() }, page = body.page, total = body.total, pageSize = body.pageSize, ) } }