From 5a934c20c54fc11a6371853421ce706422c54323 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Fri, 24 May 2024 00:57:52 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[feat]=20#30=20=EC=8A=A4=ED=81=AC=EB=9E=A9?= =?UTF-8?q?=20=EC=83=81=ED=92=88=20=EB=93=B1=EB=A1=9D=20API=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kream/data/datasource/ProductRemoteDataSource.kt | 5 +++++ .../data/datasourceimpl/ProductRemoteDataSourceImpl.kt | 6 ++++++ .../kream/data/model/request/RequestPostScrapDto.kt | 10 ++++++++++ .../kream/data/repository/ProductRepositoryImpl.kt | 8 ++++++++ .../java/org/sopt/kream/data/service/ProductService.kt | 9 +++++++++ .../sopt/kream/domain/repository/ProductRepository.kt | 5 +++++ 6 files changed, 43 insertions(+) create mode 100644 app/src/main/java/org/sopt/kream/data/model/request/RequestPostScrapDto.kt diff --git a/app/src/main/java/org/sopt/kream/data/datasource/ProductRemoteDataSource.kt b/app/src/main/java/org/sopt/kream/data/datasource/ProductRemoteDataSource.kt index c3f495a..59d2abf 100644 --- a/app/src/main/java/org/sopt/kream/data/datasource/ProductRemoteDataSource.kt +++ b/app/src/main/java/org/sopt/kream/data/datasource/ProductRemoteDataSource.kt @@ -8,4 +8,9 @@ interface ProductRemoteDataSource { suspend fun getSearchProduct(findName: String): BaseResponse suspend fun getRecommendProduct(memberId: Int): BaseResponse + + suspend fun postScrap( + memberId: Int, + productId: Int, + ): BaseResponse } diff --git a/app/src/main/java/org/sopt/kream/data/datasourceimpl/ProductRemoteDataSourceImpl.kt b/app/src/main/java/org/sopt/kream/data/datasourceimpl/ProductRemoteDataSourceImpl.kt index 46f3869..1929e75 100644 --- a/app/src/main/java/org/sopt/kream/data/datasourceimpl/ProductRemoteDataSourceImpl.kt +++ b/app/src/main/java/org/sopt/kream/data/datasourceimpl/ProductRemoteDataSourceImpl.kt @@ -2,6 +2,7 @@ package org.sopt.kream.data.datasourceimpl import org.sopt.kream.data.ServicePool import org.sopt.kream.data.datasource.ProductRemoteDataSource +import org.sopt.kream.data.model.request.RequestPostScrapDto import org.sopt.kream.data.model.response.ResponseRecommendProductDto import org.sopt.kream.data.model.response.ResponseSearchProductDto import org.sopt.kream.util.base.BaseResponse @@ -12,4 +13,9 @@ class ProductRemoteDataSourceImpl : ProductRemoteDataSource { override suspend fun getSearchProduct(findName: String): BaseResponse = productService.getSearchProduct(findName = findName) override suspend fun getRecommendProduct(memberId: Int): BaseResponse = productService.getRecommendProduct(memberId = memberId) + + override suspend fun postScrap( + memberId: Int, + productId: Int, + ): BaseResponse = productService.postScrap(memberId = memberId, request = RequestPostScrapDto(productId)) } diff --git a/app/src/main/java/org/sopt/kream/data/model/request/RequestPostScrapDto.kt b/app/src/main/java/org/sopt/kream/data/model/request/RequestPostScrapDto.kt new file mode 100644 index 0000000..92af721 --- /dev/null +++ b/app/src/main/java/org/sopt/kream/data/model/request/RequestPostScrapDto.kt @@ -0,0 +1,10 @@ +package org.sopt.kream.data.model.request + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class RequestPostScrapDto( + @SerialName("productId") + val productId: Int, +) diff --git a/app/src/main/java/org/sopt/kream/data/repository/ProductRepositoryImpl.kt b/app/src/main/java/org/sopt/kream/data/repository/ProductRepositoryImpl.kt index a61ec0b..bd13ac3 100644 --- a/app/src/main/java/org/sopt/kream/data/repository/ProductRepositoryImpl.kt +++ b/app/src/main/java/org/sopt/kream/data/repository/ProductRepositoryImpl.kt @@ -19,4 +19,12 @@ class ProductRepositoryImpl( runCatching { productRemoteDataSource.getRecommendProduct(memberId = memberId).data.toRecommendProductModel() } + + override suspend fun postScrap( + memberId: Int, + productId: Int, + ): Result = + runCatching { + productRemoteDataSource.postScrap(memberId = memberId, productId = productId) + } } diff --git a/app/src/main/java/org/sopt/kream/data/service/ProductService.kt b/app/src/main/java/org/sopt/kream/data/service/ProductService.kt index fd60a98..cba159d 100644 --- a/app/src/main/java/org/sopt/kream/data/service/ProductService.kt +++ b/app/src/main/java/org/sopt/kream/data/service/ProductService.kt @@ -1,10 +1,13 @@ package org.sopt.kream.data.service +import org.sopt.kream.data.model.request.RequestPostScrapDto import org.sopt.kream.data.model.response.ResponseRecommendProductDto import org.sopt.kream.data.model.response.ResponseSearchProductDto import org.sopt.kream.util.base.BaseResponse +import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.Header +import retrofit2.http.POST import retrofit2.http.Query interface ProductService { @@ -17,4 +20,10 @@ interface ProductService { suspend fun getRecommendProduct( @Header("memberId") memberId: Int, ): BaseResponse + + @POST("scrap") + suspend fun postScrap( + @Header("memberId") memberId: Int, + @Body request: RequestPostScrapDto, + ): BaseResponse } diff --git a/app/src/main/java/org/sopt/kream/domain/repository/ProductRepository.kt b/app/src/main/java/org/sopt/kream/domain/repository/ProductRepository.kt index f7321d6..ae91f72 100644 --- a/app/src/main/java/org/sopt/kream/domain/repository/ProductRepository.kt +++ b/app/src/main/java/org/sopt/kream/domain/repository/ProductRepository.kt @@ -7,4 +7,9 @@ interface ProductRepository { suspend fun getSearchProduct(findName: String): Result suspend fun getRecommendProduct(memberId: Int): Result + + suspend fun postScrap( + memberId: Int, + productId: Int, + ): Result } From 12673fa49aac2cd1d2dedcfdd1a0b8d5f1d7ed5a Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Fri, 24 May 2024 00:58:12 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[feat]=20#30=20=EC=8A=A4=ED=81=AC=EB=9E=A9?= =?UTF-8?q?=20=EC=83=81=ED=92=88=20=EB=93=B1=EB=A1=9D=20API=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/home/recommend/RecommendFragment.kt | 2 +- .../recommend/RecommendJustDroppedAdapter.kt | 4 ++++ .../RecommendJustDroppedViewHolder.kt | 20 +++++++++++++++++-- .../main/home/recommend/RecommendViewModel.kt | 17 ++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendFragment.kt b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendFragment.kt index d9cf7a2..81894c6 100644 --- a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendFragment.kt +++ b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendFragment.kt @@ -44,7 +44,7 @@ class RecommendFragment : BindingFragment({ FragmentRe advertisementAdapter = RecommendAdvertisementViewPagerAdapter(RecommendAdvertisementType.RECOMMEND_ADVERTISEMENT.advertisementList) circleMenuAdapter = RecommendCircleMenuAdapter(RecommendCircleMenuType.entries) forYouAdapter = RecommendForYouViewPagerAdapter(::navigateToProductDetail, ::navigateToSearch) - justDroppedAdapter = RecommendJustDroppedAdapter(::navigateToProductDetail) + justDroppedAdapter = RecommendJustDroppedAdapter(::navigateToProductDetail, recommendViewModel, memberId) styleAdapter = RecommendStyleAdapter() with(binding) { diff --git a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendJustDroppedAdapter.kt b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendJustDroppedAdapter.kt index 50df1d8..6748e23 100644 --- a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendJustDroppedAdapter.kt +++ b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendJustDroppedAdapter.kt @@ -9,6 +9,8 @@ import org.sopt.kream.util.view.ItemDiffCallback class RecommendJustDroppedAdapter( private val navigateToProductDetail: (Int) -> Unit, + private val recommendViewModel: RecommendViewModel, + private val memberId: Int, ) : ListAdapter< RecommendJustDroppedProductModel, RecommendJustDroppedViewHolder, @@ -29,6 +31,8 @@ class RecommendJustDroppedAdapter( false, ), navigateToProductDetail, + recommendViewModel, + memberId, ) override fun onBindViewHolder( diff --git a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendJustDroppedViewHolder.kt b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendJustDroppedViewHolder.kt index 70eaefb..5a840bd 100644 --- a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendJustDroppedViewHolder.kt +++ b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendJustDroppedViewHolder.kt @@ -10,13 +10,15 @@ import org.sopt.kream.domain.model.RecommendJustDroppedProductModel class RecommendJustDroppedViewHolder( private val binding: ItemRecommendJustDroppedProductBinding, private val navigateToProductDetail: (Int) -> Unit, + private val recommendViewModel: RecommendViewModel, + private val memberId: Int, ) : RecyclerView.ViewHolder(binding.root) { - private var recommendJustDroppedAdapter: RecommendJustDroppedAdapter = RecommendJustDroppedAdapter(navigateToProductDetail) - fun onBind( recommendJustDroppedProductModel: RecommendJustDroppedProductModel, position: Int, ) { + initScrapClickListener(recommendJustDroppedProductModel.isScrap, position + 1) + with(binding) { ivJustDroppedProduct.load(recommendJustDroppedProductModel.thumbnailUrl) tvJustDroppedProductBrand.text = recommendJustDroppedProductModel.brandTitle @@ -50,4 +52,18 @@ class RecommendJustDroppedViewHolder( } } } + + fun initScrapClickListener( + isScrap: Boolean, + productId: Int, + ) { + with(binding) { + ivJustDroppedProductScrap.setOnClickListener { + if (!isScrap) { + recommendViewModel.postScrapProduct(memberId, productId) + ivJustDroppedProductScrap.setImageResource(R.drawable.ic_saved_2_on_24) + } + } + } + } } diff --git a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendViewModel.kt b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendViewModel.kt index 39e5069..3ae014a 100644 --- a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendViewModel.kt +++ b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendViewModel.kt @@ -17,6 +17,9 @@ class RecommendViewModel( private val _recommendProductState = MutableStateFlow>(UiState.Empty) val recommendProductState get() = _recommendProductState.asStateFlow() + private val _postScrapState = MutableStateFlow>(UiState.Empty) + val postScrapState get() = _postScrapState.asStateFlow() + private val _instagramList = listOf( InstagramModel( @@ -52,4 +55,18 @@ class RecommendViewModel( } } } + + fun postScrapProduct( + memberId: Int, + productId: Int, + ) { + viewModelScope.launch { + _postScrapState.value = UiState.Loading + productRepository.postScrap(memberId = memberId, productId = productId).onSuccess { postScrapResult -> + _postScrapState.value = UiState.Success(postScrapResult) + }.onFailure { exception: Throwable -> + _postScrapState.value = UiState.Error(exception.message) + } + } + } } From 95d1986fa4ed3605244f802442525996a8db82a5 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Fri, 24 May 2024 02:17:55 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[chore]=20#30=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasourceimpl/ProductRemoteDataSourceImpl.kt | 2 +- .../java/org/sopt/kream/data/service/ProductService.kt | 9 ++++----- .../sopt/kream/presentation/common/ViewModelFactory.kt | 2 +- app/src/main/res/layout/fragment_recommend.xml | 2 +- app/src/main/res/layout/item_recommend_for_you.xml | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/sopt/kream/data/datasourceimpl/ProductRemoteDataSourceImpl.kt b/app/src/main/java/org/sopt/kream/data/datasourceimpl/ProductRemoteDataSourceImpl.kt index 68513bd..4964e1b 100644 --- a/app/src/main/java/org/sopt/kream/data/datasourceimpl/ProductRemoteDataSourceImpl.kt +++ b/app/src/main/java/org/sopt/kream/data/datasourceimpl/ProductRemoteDataSourceImpl.kt @@ -2,8 +2,8 @@ package org.sopt.kream.data.datasourceimpl import org.sopt.kream.data.ServicePool import org.sopt.kream.data.datasource.ProductRemoteDataSource -import org.sopt.kream.data.model.response.ResponseProductDetailDto import org.sopt.kream.data.model.request.RequestPostScrapDto +import org.sopt.kream.data.model.response.ResponseProductDetailDto import org.sopt.kream.data.model.response.ResponseRecommendProductDto import org.sopt.kream.data.model.response.ResponseSearchProductDto import org.sopt.kream.util.base.BaseResponse diff --git a/app/src/main/java/org/sopt/kream/data/service/ProductService.kt b/app/src/main/java/org/sopt/kream/data/service/ProductService.kt index c9f6ea8..a2b2dff 100644 --- a/app/src/main/java/org/sopt/kream/data/service/ProductService.kt +++ b/app/src/main/java/org/sopt/kream/data/service/ProductService.kt @@ -1,18 +1,17 @@ package org.sopt.kream.data.service -import org.sopt.kream.data.model.response.ResponseProductDetailDto -import org.sopt.kream.data.model.response.ResponseReleaseProductDto import org.sopt.kream.data.model.request.RequestPostScrapDto +import org.sopt.kream.data.model.response.ResponseProductDetailDto import org.sopt.kream.data.model.response.ResponseRecommendProductDto +import org.sopt.kream.data.model.response.ResponseReleaseProductDto import org.sopt.kream.data.model.response.ResponseSearchProductDto import org.sopt.kream.util.base.BaseResponse -import retrofit2.http.DELETE import retrofit2.http.Body +import retrofit2.http.DELETE import retrofit2.http.GET import retrofit2.http.Header -import retrofit2.http.Path -import retrofit2.http.Header import retrofit2.http.POST +import retrofit2.http.Path import retrofit2.http.Query interface ProductService { diff --git a/app/src/main/java/org/sopt/kream/presentation/common/ViewModelFactory.kt b/app/src/main/java/org/sopt/kream/presentation/common/ViewModelFactory.kt index 3881b6b..1dbff58 100644 --- a/app/src/main/java/org/sopt/kream/presentation/common/ViewModelFactory.kt +++ b/app/src/main/java/org/sopt/kream/presentation/common/ViewModelFactory.kt @@ -7,8 +7,8 @@ import org.sopt.kream.data.datasourceimpl.ProductRemoteDataSourceImpl import org.sopt.kream.data.repository.DummyRepositoryImpl import org.sopt.kream.data.repository.ProductRepositoryImpl import org.sopt.kream.presentation.ui.dummy.DummyViewModel -import org.sopt.kream.presentation.ui.productdetail.ProductDetailViewModel import org.sopt.kream.presentation.ui.main.home.recommend.RecommendViewModel +import org.sopt.kream.presentation.ui.productdetail.ProductDetailViewModel import org.sopt.kream.presentation.ui.search.SearchViewModel class ViewModelFactory : ViewModelProvider.Factory { diff --git a/app/src/main/res/layout/fragment_recommend.xml b/app/src/main/res/layout/fragment_recommend.xml index 057954c..dc63b1a 100644 --- a/app/src/main/res/layout/fragment_recommend.xml +++ b/app/src/main/res/layout/fragment_recommend.xml @@ -208,7 +208,7 @@ android:layout_height="wrap_content" android:layout_marginBottom="2dp" android:padding="14dp" - android:text="@string/recommend_more" + android:text="@string/all_details" android:textAppearance="@style/TextAppearance.Kream.Body5.Regular" android:textColor="@color/black06" app:layout_constraintBottom_toBottomOf="@id/tv_recommend_just_dropped_content" diff --git a/app/src/main/res/layout/item_recommend_for_you.xml b/app/src/main/res/layout/item_recommend_for_you.xml index dacb57c..4c2642b 100644 --- a/app/src/main/res/layout/item_recommend_for_you.xml +++ b/app/src/main/res/layout/item_recommend_for_you.xml @@ -77,7 +77,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="7dp" - android:text="@string/recommend_more" + android:text="@string/all_details" android:textAlignment="center" android:textAppearance="@style/TextAppearance.Kream.Body5.Regular" android:textColor="@color/gray02"