Skip to content

Commit

Permalink
[CHORE] #9-extension fun apply
Browse files Browse the repository at this point in the history
  • Loading branch information
librarywon authored and daehwan2da committed May 25, 2023
1 parent e282c5b commit b5df745
Showing 1 changed file with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.sopt.carrot.presentation.review.model

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.sopt.carrot.data.ApiPool
import com.sopt.carrot.data.review.ResponseReviewDto
import com.sopt.carrot.util.enqueueUtil
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -26,25 +28,17 @@ class ReviewViewModel : ViewModel() {

fun getReview() {
val reviewService = ApiPool.reviewService
reviewService.getReviewList().enqueue(object : Callback<ResponseReviewDto> {
override fun onResponse(
call: Call<ResponseReviewDto>,
response: Response<ResponseReviewDto>
) {
if (response.isSuccessful) {
val data = response.body()?.data?.reviews
_reviews.value = data!!
_signUpResult.value = response.body()
} else {
// handle failure
_errorResult.value = response.body()
}
reviewService.getReviewList().enqueueUtil(
onSuccess = { response ->
val data = response.data?.reviews
_reviews.value = data!!
_signUpResult.value = response
},
onError = { stateCode ->
Log.d("Error", "Error occurred with stateCode: $stateCode")
}

override fun onFailure(call: Call<ResponseReviewDto>, t: Throwable) {
_errorResult.value = (t.localizedMessage ?: "Unknown error") as ResponseReviewDto?
}
})
)
}


}

0 comments on commit b5df745

Please sign in to comment.