更新代码

This commit is contained in:
2024-09-14 23:27:44 +08:00
parent de5088dc02
commit 6247ade1dd
18 changed files with 785 additions and 366 deletions

View File

@@ -46,14 +46,15 @@ class CommentPagingSource(
postUser = postUser,
selfNotice = selfNotice,
order = order,
parentCommentId = parentCommentId
parentCommentId = parentCommentId,
pageSize = params.loadSize
)
LoadResult.Page(
data = comments.list,
prevKey = if (currentPage == 1) null else currentPage - 1,
nextKey = if (comments.list.isEmpty()) null else comments.page + 1
)
} catch (exception: IOException) {
} catch (exception: Exception) {
return LoadResult.Error(exception)
}
}

View File

@@ -8,6 +8,7 @@ import com.aiosman.riderpro.data.MomentService
import com.aiosman.riderpro.data.ServiceException
import com.aiosman.riderpro.data.UploadImage
import com.aiosman.riderpro.data.api.ApiClient
import com.aiosman.riderpro.data.parseErrorResponse
import com.aiosman.riderpro.entity.MomentEntity
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
@@ -165,8 +166,13 @@ class MomentBackend {
suspend fun getMomentById(id: Int): MomentEntity {
var resp = ApiClient.api.getPost(id)
var body = resp.body()?.data ?: throw ServiceException("Failed to get moment")
return body.toMomentItem()
if (!resp.isSuccessful) {
parseErrorResponse(resp.errorBody())?.let {
throw it.toServiceException()
}
throw ServiceException("Failed to get moment")
}
return resp.body()?.data?.toMomentItem() ?: throw ServiceException("Failed to get moment")
}
suspend fun likeMoment(id: Int) {