Skip to content

Commit

Permalink
#219 CommentsDataSource.kt내에서 댓글 가져오는 메서드 인자를 새로운 api에 맞게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
pknujsp committed Mar 10, 2024
1 parent ce3ce28 commit b3870e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.Flow

interface CommentsDataSource {

suspend fun getCommentsByMedicineId(medicineId: Long): Result<CommentListResponse>
suspend fun getCommentsByMedicineId(medicineId: Long, page: Int, rows: Int, userId: String = "-1"): Result<CommentListResponse>

suspend fun getMyCommentsList(): Flow<Result<MyCommentsListResponse>>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class CommentsDataSourceImpl @Inject constructor(
private val awsNetworkApi: AwsNetworkApi,
) : CommentsDataSource {

override suspend fun getCommentsByMedicineId(medicineId: Long): Result<CommentListResponse> {
return awsNetworkApi.getCommentsByMedicineId(medicineId).onResponse().fold(
override suspend fun getCommentsByMedicineId(medicineId: Long, page: Int, rows: Int, userId: String): Result<CommentListResponse> {
return awsNetworkApi.getCommentsByMedicineId(medicineId, page, rows, userId).onResponse().fold(
onSuccess = { response ->
if (response.commentList.isEmpty()) Result.failure(Exception("댓글이 없습니다."))
else Result.success(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ class CommentsListDataSourceImpl(

override suspend fun load(params: LoadParams<Int>): LoadResult<Int, CommentListResponse.Comment> {
return try {
commentsDataSource.getCommentsByMedicineId(medicineId).fold(onSuccess = {
LoadResult.Page(
data = it.commentList,
prevKey = null,
nextKey = if (it.commentList.size > 1000000) 1 else null,
)
}, onFailure = {
LoadResult.Error(it)
})
commentsDataSource.getCommentsByMedicineId(medicineId, 1, 15, "-1").fold(
onSuccess = {
LoadResult.Page(
data = it.commentList,
prevKey = null,
nextKey = if (it.commentList.size > 1000000) 1 else null,
)
},
onFailure = {
LoadResult.Error(it)
},
)
} catch (e: Exception) {
LoadResult.Error(e)
}
Expand Down

0 comments on commit b3870e1

Please sign in to comment.