cambios por api web: deja de enviar lastId al obtener comentarios cuando sea la primera pagina

This commit is contained in:
erik-everardo 2024-01-05 23:54:20 -06:00
parent 2bc27cca0c
commit f6c6d103f6
5 changed files with 5 additions and 5 deletions

View File

@ -13,7 +13,7 @@ interface CommentsApi {
fun postComment(@Path("postId") postId: Long, @Body commentToPost: CommentToPostDto): Call<CommentDto> fun postComment(@Path("postId") postId: Long, @Body commentToPost: CommentToPostDto): Call<CommentDto>
@GET("Fetch/Post/{postId}/Comments") @GET("Fetch/Post/{postId}/Comments")
fun getCommentsOfPosts(@Path("postId") postId: Long, @Query("lastId") lastId: Long, @Query("take") count: Int): Call<FeedCommentsDto> fun getCommentsOfPosts(@Path("postId") postId: Long, @Query("lastId") lastId: Long?, @Query("take") count: Int): Call<FeedCommentsDto>
@GET("Fetch/Comments/{commentId}") @GET("Fetch/Comments/{commentId}")
fun getComment(@Path("commentId") commentId: Long): Call<CommentDto> fun getComment(@Path("commentId") commentId: Long): Call<CommentDto>

View File

@ -14,7 +14,7 @@ import javax.inject.Inject
class CommentsRepositoryImpl @Inject constructor(private val commentsApi: CommentsApi) : class CommentsRepositoryImpl @Inject constructor(private val commentsApi: CommentsApi) :
CommentsRepository { CommentsRepository {
override fun getComments(postId: Long, lastId: Long): Flow<Resource<MutableList<Comment>>> = flow { override fun getComments(postId: Long, lastId: Long?): Flow<Resource<MutableList<Comment>>> = flow {
try { try {
emit(Resource.Loading()) emit(Resource.Loading())
val response = commentsApi.getCommentsOfPosts(postId, lastId, 15).awaitResponse() val response = commentsApi.getCommentsOfPosts(postId, lastId, 15).awaitResponse()

View File

@ -6,7 +6,7 @@ import com.isolaatti.utils.Resource
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
interface CommentsRepository { interface CommentsRepository {
fun getComments(postId: Long, lastId: Long): Flow<Resource<MutableList<Comment>>> fun getComments(postId: Long, lastId: Long?): Flow<Resource<MutableList<Comment>>>
fun getComment(commentId: Long): Flow<Resource<CommentDto>> fun getComment(commentId: Long): Flow<Resource<CommentDto>>
fun postComment(content: String, audioId: String?, postId: Long): Flow<Resource<Comment>> fun postComment(content: String, audioId: String?, postId: Long): Flow<Resource<Comment>>
fun editComment(commentId: Long, content: String, audioId: String?): Flow<Resource<Comment>> fun editComment(commentId: Long, content: String, audioId: String?): Flow<Resource<Comment>>

View File

@ -8,5 +8,5 @@ import javax.inject.Inject
class GetComments @Inject constructor(private val commentsRepository: CommentsRepository) { class GetComments @Inject constructor(private val commentsRepository: CommentsRepository) {
operator fun invoke(postId: Long, lastId: Long? = null): Flow<Resource<MutableList<Comment>>> = operator fun invoke(postId: Long, lastId: Long? = null): Flow<Resource<MutableList<Comment>>> =
commentsRepository.getComments(postId, lastId ?: 0) commentsRepository.getComments(postId, lastId)
} }

View File

@ -59,7 +59,7 @@ class CommentsViewModel @Inject constructor(
getContent() getContent()
} }
private var lastId: Long = 0L private var lastId: Long? = null
fun getContent(refresh: Boolean = false) { fun getContent(refresh: Boolean = false) {
viewModelScope.launch { viewModelScope.launch {