From 481745a11a1ccb3fca69af61afee6ce89deb7915 Mon Sep 17 00:00:00 2001 From: librarywon Date: Fri, 26 May 2023 00:30:34 +0900 Subject: [PATCH] [CHORE] #9-setting for Intent --- .../java/com/sopt/carrot/data/review/ReviewService.kt | 7 ++++--- .../sopt/carrot/presentation/review/ReviewActivity.kt | 6 ++++++ .../presentation/review/model/ReviewViewModel.kt | 11 ++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/sopt/carrot/data/review/ReviewService.kt b/app/src/main/java/com/sopt/carrot/data/review/ReviewService.kt index 78249ce..eadf4cd 100644 --- a/app/src/main/java/com/sopt/carrot/data/review/ReviewService.kt +++ b/app/src/main/java/com/sopt/carrot/data/review/ReviewService.kt @@ -2,14 +2,15 @@ package com.sopt.carrot.data.review import retrofit2.Call import retrofit2.http.GET -import retrofit2.http.Header +import retrofit2.http.Headers import retrofit2.http.Path + interface ReviewService { + @Headers("Authorization: 1") // 정적 헤더 설정 @GET("/employer/{userId}/reviews?size=10") fun getReviewList( - @Header("Authorization") Authorization: String = "1", - @Path(value = "userId") userId: Int = 3 + @Path(value = "userId") userId: Long //userId 받아올준비 완료 ): Call } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/carrot/presentation/review/ReviewActivity.kt b/app/src/main/java/com/sopt/carrot/presentation/review/ReviewActivity.kt index 41a74a6..bb9cbf5 100644 --- a/app/src/main/java/com/sopt/carrot/presentation/review/ReviewActivity.kt +++ b/app/src/main/java/com/sopt/carrot/presentation/review/ReviewActivity.kt @@ -23,6 +23,8 @@ class ReviewActivity : AppCompatActivity() { binding.rcReviewReviews.addItemDecoration(CustomItemDecoration()) binding.rcReviewReviews.adapter = reviewAdapter + viewModel.getReview(getUserIdFromPage()) + //아이템 개수에 따라 뷰전환 viewModel.reviews.observe(this) { reviews -> if (reviews.isEmpty()) { @@ -44,6 +46,10 @@ class ReviewActivity : AppCompatActivity() { } } + private fun getUserIdFromPage(): Long { + return 3L //임시 데이터 3 + } + private fun makeToastMessage(string: String) { Toast.makeText(this, string, Toast.LENGTH_LONG).show() } diff --git a/app/src/main/java/com/sopt/carrot/presentation/review/model/ReviewViewModel.kt b/app/src/main/java/com/sopt/carrot/presentation/review/model/ReviewViewModel.kt index e74c936..39bf784 100644 --- a/app/src/main/java/com/sopt/carrot/presentation/review/model/ReviewViewModel.kt +++ b/app/src/main/java/com/sopt/carrot/presentation/review/model/ReviewViewModel.kt @@ -7,9 +7,6 @@ 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 class ReviewViewModel : ViewModel() { @@ -22,13 +19,9 @@ class ReviewViewModel : ViewModel() { private val _errorResult: MutableLiveData = MutableLiveData() val errorResult: LiveData = _errorResult - init { - getReview() - } - - fun getReview() { + fun getReview(userId: Long) { val reviewService = ApiPool.reviewService - reviewService.getReviewList().enqueueUtil( + reviewService.getReviewList(userId).enqueueUtil( onSuccess = { response -> val data = response.data?.reviews _reviews.value = data!!