From eb6dedde0fb4b506a1955a26334e50f8107e3294 Mon Sep 17 00:00:00 2001 From: NaZe0320 Date: Tue, 13 Feb 2024 23:30:21 +0900 Subject: [PATCH] [feat/#51] coupon item test --- .../com/umc/coumo/data/remote/api/CoumoApi.kt | 15 +++ .../remote/datasource/CoumoRepositoryImpl.kt | 9 ++ .../data/remote/model/response/ResponseQR.kt | 5 + .../java/com/umc/coumo/di/RetrofitModule.kt | 4 +- .../domain/repository/CoumoRepository.kt | 9 ++ .../coumo/domain/viewmodel/CouponViewModel.kt | 23 ++++- .../coumo/presentation/dialog/CouponDialog.kt | 15 ++- .../com/umc/coumo/utils/BindingAdapter.kt | 13 +++ app/src/main/res/layout/dialog_coupon.xml | 91 +++++++++---------- 9 files changed, 133 insertions(+), 51 deletions(-) create mode 100644 app/src/main/java/com/umc/coumo/data/remote/model/response/ResponseQR.kt diff --git a/app/src/main/java/com/umc/coumo/data/remote/api/CoumoApi.kt b/app/src/main/java/com/umc/coumo/data/remote/api/CoumoApi.kt index 5e992c4..b197469 100644 --- a/app/src/main/java/com/umc/coumo/data/remote/api/CoumoApi.kt +++ b/app/src/main/java/com/umc/coumo/data/remote/api/CoumoApi.kt @@ -7,6 +7,8 @@ import com.umc.coumo.data.remote.model.response.ResponseStoreDataModel import com.umc.coumo.domain.type.CategoryType import retrofit2.Response import retrofit2.http.GET +import retrofit2.http.Headers +import retrofit2.http.POST import retrofit2.http.Path import retrofit2.http.Query @@ -32,4 +34,17 @@ interface CoumoApi { @Path("customerId") customerId: Int, @Path("storeId") storeId: Int ): Response> + + @Headers("Content-Type: image/png") + @POST("/api/qr/customer/stamp/{customerId}/{storeId}") + suspend fun postCustomerStamp( + @Path("customerId") customerId: Int, + @Path("storeId") storeId: Int, + ): String + + @POST("/api/qr/customer/payment/{customerId}/{storeId}") + suspend fun postCustomerPayment( + @Path("customerId") customerId: Int, + @Path("storeId") storeId: Int + ): Response } \ No newline at end of file diff --git a/app/src/main/java/com/umc/coumo/data/remote/datasource/CoumoRepositoryImpl.kt b/app/src/main/java/com/umc/coumo/data/remote/datasource/CoumoRepositoryImpl.kt index 9e1ddd3..ae4d6d4 100644 --- a/app/src/main/java/com/umc/coumo/data/remote/datasource/CoumoRepositoryImpl.kt +++ b/app/src/main/java/com/umc/coumo/data/remote/datasource/CoumoRepositoryImpl.kt @@ -20,6 +20,7 @@ class CoumoRepositoryImpl @Inject constructor( //API Injection private val coumoApi: CoumoApi ): CoumoRepository { + override suspend fun getPopularStoreList( longitude: Double, latitude: Double @@ -44,6 +45,14 @@ class CoumoRepositoryImpl @Inject constructor( return mapToStoreInfoModel(data.body()?.result) } + override suspend fun postStampCustomer(storeId: Int): String? { + return coumoApi.postCustomerStamp(1, storeId) + } + + override suspend fun postPaymentCustomer(storeId: Int): Uri? { + TODO("Not yet implemented") + } + private fun mapToStoreInfoModel(response: ResponseStoreDataModel?): StoreInfoModel? { return if (response != null) { StoreInfoModel( diff --git a/app/src/main/java/com/umc/coumo/data/remote/model/response/ResponseQR.kt b/app/src/main/java/com/umc/coumo/data/remote/model/response/ResponseQR.kt new file mode 100644 index 0000000..a87a964 --- /dev/null +++ b/app/src/main/java/com/umc/coumo/data/remote/model/response/ResponseQR.kt @@ -0,0 +1,5 @@ +package com.umc.coumo.data.remote.model.response + +data class ResponseQR( + val qr: String? +) diff --git a/app/src/main/java/com/umc/coumo/di/RetrofitModule.kt b/app/src/main/java/com/umc/coumo/di/RetrofitModule.kt index e680723..4c5041a 100644 --- a/app/src/main/java/com/umc/coumo/di/RetrofitModule.kt +++ b/app/src/main/java/com/umc/coumo/di/RetrofitModule.kt @@ -15,6 +15,7 @@ import okhttp3.Response import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory +import retrofit2.converter.scalars.ScalarsConverterFactory import java.io.IOException import javax.inject.Singleton @@ -31,7 +32,8 @@ object RetrofitModule { fun provideApiService(): CoumoApi { return Retrofit.Builder() .baseUrl(BASE_URL) - .addConverterFactory(GsonConverterFactory.create()) + .addConverterFactory(ScalarsConverterFactory.create()) + .addConverterFactory(GsonConverterFactory.create(gson)) .client(okHttpClient(AppInterceptor())) //Interceptor 필요할 때 .build() .create(CoumoApi::class.java) diff --git a/app/src/main/java/com/umc/coumo/domain/repository/CoumoRepository.kt b/app/src/main/java/com/umc/coumo/domain/repository/CoumoRepository.kt index 725810e..df0b8a9 100644 --- a/app/src/main/java/com/umc/coumo/domain/repository/CoumoRepository.kt +++ b/app/src/main/java/com/umc/coumo/domain/repository/CoumoRepository.kt @@ -1,5 +1,6 @@ package com.umc.coumo.domain.repository +import android.net.Uri import com.umc.coumo.domain.model.StoreCouponCountModel import com.umc.coumo.domain.model.StoreInfoItemModel import com.umc.coumo.domain.model.StoreInfoModel @@ -18,4 +19,12 @@ interface CoumoRepository { suspend fun getStoreData( storeId: Int ): StoreInfoModel? + + suspend fun postStampCustomer( + storeId: Int + ): String? + + suspend fun postPaymentCustomer( + storeId: Int + ): Uri? } \ No newline at end of file diff --git a/app/src/main/java/com/umc/coumo/domain/viewmodel/CouponViewModel.kt b/app/src/main/java/com/umc/coumo/domain/viewmodel/CouponViewModel.kt index 4902894..adc0b06 100644 --- a/app/src/main/java/com/umc/coumo/domain/viewmodel/CouponViewModel.kt +++ b/app/src/main/java/com/umc/coumo/domain/viewmodel/CouponViewModel.kt @@ -3,13 +3,18 @@ package com.umc.coumo.domain.viewmodel import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.umc.coumo.domain.model.CouponModel +import com.umc.coumo.domain.repository.CoumoRepository import com.umc.coumo.domain.type.CouponAlignType import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel -class CouponViewModel @Inject constructor(): ViewModel() { +class CouponViewModel @Inject constructor( + private val repository: CoumoRepository +): ViewModel() { private val _align = MutableLiveData(CouponAlignType.MOST) val align: LiveData get() = _align @@ -19,6 +24,9 @@ class CouponViewModel @Inject constructor(): ViewModel() { private val _currentCoupon = MutableLiveData() val currentCoupon: LiveData get() = _currentCoupon + private val _currentQR = MutableLiveData() + val currentQR: LiveData get() = _currentQR + fun changeAlign(align: CouponAlignType) { _align.value = align } @@ -32,4 +40,17 @@ class CouponViewModel @Inject constructor(): ViewModel() { ) _couponList.value = list } + + fun postCustomerStamp(storeId: Int) { + viewModelScope.launch { + _currentQR.value = repository.postStampCustomer(storeId) + } + } + + fun postCustomerPayment(storeId: Int) { + viewModelScope.launch { + //_currentQR.value = repository.postPaymentCustomer(storeId) + } + } + } \ No newline at end of file diff --git a/app/src/main/java/com/umc/coumo/presentation/dialog/CouponDialog.kt b/app/src/main/java/com/umc/coumo/presentation/dialog/CouponDialog.kt index e25a220..0fd56a1 100644 --- a/app/src/main/java/com/umc/coumo/presentation/dialog/CouponDialog.kt +++ b/app/src/main/java/com/umc/coumo/presentation/dialog/CouponDialog.kt @@ -1,12 +1,9 @@ package com.umc.coumo.presentation.dialog -import android.app.Dialog import android.os.Bundle import android.view.View -import android.view.WindowManager import androidx.recyclerview.widget.GridLayoutManager import com.umc.coumo.R -import com.umc.coumo.databinding.DialogConfirmBinding import com.umc.coumo.databinding.DialogCouponBinding import com.umc.coumo.domain.model.CouponModel import com.umc.coumo.domain.viewmodel.CouponViewModel @@ -17,6 +14,10 @@ class CouponDialog(val viewModel: CouponViewModel) : BindingDialogFragment i < coupon.stampCount } stampAdapter.submitList(result) diff --git a/app/src/main/java/com/umc/coumo/utils/BindingAdapter.kt b/app/src/main/java/com/umc/coumo/utils/BindingAdapter.kt index ea7ee94..ea51a82 100644 --- a/app/src/main/java/com/umc/coumo/utils/BindingAdapter.kt +++ b/app/src/main/java/com/umc/coumo/utils/BindingAdapter.kt @@ -1,11 +1,13 @@ package com.umc.coumo.utils import android.content.res.ColorStateList +import android.graphics.BitmapFactory import android.graphics.Color import android.net.Uri import android.text.Spannable import android.text.SpannableString import android.text.style.ForegroundColorSpan +import android.util.Log import android.view.View import android.view.ViewGroup import android.widget.ImageView @@ -74,6 +76,17 @@ fun setImageUri(imageView: ImageView, imageUri: Uri?) { } } +@BindingAdapter("imageQR") +fun setImageQR(imageView: ImageView, imageUri: String?) { + Log.d("TEST HTTP","$imageUri") + if (imageUri != null) { + imageView.setImageBitmap(BitmapFactory.decodeStream(imageUri.byteInputStream())) + } else { + imageView.setImageResource(R.drawable.default_image) + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + } +} + @BindingAdapter("highlightText") fun TextView.setHighlightedText(fullText: String?) { fullText?.let { diff --git a/app/src/main/res/layout/dialog_coupon.xml b/app/src/main/res/layout/dialog_coupon.xml index 3e814c3..912b9fd 100644 --- a/app/src/main/res/layout/dialog_coupon.xml +++ b/app/src/main/res/layout/dialog_coupon.xml @@ -6,7 +6,7 @@ + type="com.umc.coumo.domain.viewmodel.CouponViewModel" /> - - - - - + app:layout_constraintTop_toTopOf="parent"/> @@ -98,7 +61,7 @@ android:layout_height="match_parent" android:background="@drawable/shape_rect_round_6" android:paddingTop="28dp" - app:dynamicBackgroundColor="@{coupon.color}" + app:dynamicBackgroundColor="@{coupon.currentCoupon.color}" tools:backgroundTint="#FFDA26"> + + + + \ No newline at end of file