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 a658bda..f3effec 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 @@ -5,5 +5,9 @@ import org.sopt.kream.util.base.BaseResponse interface ProductRemoteDataSource { suspend fun getSearchProduct(findName: String): BaseResponse - suspend fun deleteScrap(memberId: Int, productId: Int): BaseResponse + + suspend fun deleteScrap( + 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 4a3b5ae..609bbb8 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 @@ -10,5 +10,9 @@ class ProductRemoteDataSourceImpl : ProductRemoteDataSource { private val productService = ServicePool.productService override suspend fun getSearchProduct(findName: String): BaseResponse = productService.getSearchProduct(findName = findName) - override suspend fun deleteScrap(memberId: Int, productId: Int): BaseResponse = productService.deleteScrap(memberId, RequestDeleteScrapDto(productId)) + + override suspend fun deleteScrap( + memberId: Int, + productId: Int, + ): BaseResponse = productService.deleteScrap(memberId, RequestDeleteScrapDto(productId)) } 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 78517d1..cba4536 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 @@ -13,7 +13,10 @@ class ProductRepositoryImpl( productRemoteDataSource.getSearchProduct(findName = findName).data.toSearchProductModel() } - override suspend fun deleteScrap(memberId: Int, productId: Int): Result { + override suspend fun deleteScrap( + memberId: Int, + productId: Int, + ): Result { return runCatching { productRemoteDataSource.deleteScrap(memberId, 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 54b72bc..db0ae62 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 @@ -5,7 +5,6 @@ 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.Body -import retrofit2.http.DELETE import retrofit2.http.GET import retrofit2.http.HTTP import retrofit2.http.Header 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 77210ea..4c154d6 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 @@ -4,5 +4,9 @@ import org.sopt.kream.domain.model.SearchProductModel interface ProductRepository { suspend fun getSearchProduct(findName: String): Result - suspend fun deleteScrap(memberId: Int, productId: Int): Result + + suspend fun deleteScrap( + memberId: Int, + productId: Int, + ): Result } 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 06af64a..3cad7a8 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 @@ -6,7 +6,6 @@ import org.sopt.kream.data.datasourceimpl.DummyRemoteDataSourceImpl 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.domain.repository.ProductRepository import org.sopt.kream.presentation.ui.dummy.DummyViewModel import org.sopt.kream.presentation.ui.main.home.release.ReleaseProductViewModel import org.sopt.kream.presentation.ui.search.SearchViewModel diff --git a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/release/ReleaseFragment.kt b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/release/ReleaseFragment.kt index e1f5313..1c46a94 100644 --- a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/release/ReleaseFragment.kt +++ b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/release/ReleaseFragment.kt @@ -1,7 +1,6 @@ package org.sopt.kream.presentation.ui.main.home.release import android.os.Bundle -import android.util.Log import android.view.View import androidx.compose.foundation.Image import androidx.compose.foundation.background @@ -68,7 +67,7 @@ import java.util.Calendar import java.util.concurrent.TimeUnit class ReleaseFragment : BindingFragment({ FragmentReleaseBinding.inflate(it) }) { - private val viewModel : ReleaseProductViewModel by viewModels { ViewModelFactory() } + private val viewModel: ReleaseProductViewModel by viewModels { ViewModelFactory() } override fun onViewCreated( view: View, @@ -87,23 +86,19 @@ class ReleaseFragment : BindingFragment({ FragmentReleas else -> Unit } }.launchIn(viewLifecycleOwner.lifecycleScope) - - - - } } @Composable fun UiStateISSuccess( - viewModel: ReleaseProductViewModel + viewModel: ReleaseProductViewModel, ) { val advertisement by remember { mutableStateOf(viewModel.advertisements) } Box( modifier = - Modifier - .fillMaxSize() - .verticalScroll(rememberScrollState()), + Modifier + .fillMaxSize() + .verticalScroll(rememberScrollState()), ) { Column( modifier = @@ -299,7 +294,11 @@ fun CustomMidNaviBar() { } @Composable -fun ShoesItem(releaseProductResponseDto: ResponseReleaseProductDto.ReleaseProductResponseDto,productIndex:Int,viewModel: ReleaseProductViewModel) { +fun ShoesItem( + releaseProductResponseDto: ResponseReleaseProductDto.ReleaseProductResponseDto, + productIndex: Int, + viewModel: ReleaseProductViewModel, +) { var isIconChanged by remember { mutableStateOf(releaseProductResponseDto.isScrap) } val iconResource = if (isIconChanged) { @@ -352,10 +351,10 @@ fun ShoesItem(releaseProductResponseDto: ResponseReleaseProductDto.ReleaseProduc modifier = Modifier.clickable { isIconChanged = !isIconChanged - if (releaseProductResponseDto.isScrap){ - viewModel.deleteScrap(productIndex) - } - + if (releaseProductResponseDto.isScrap) + { + viewModel.deleteScrap(productIndex) + } }, ) } @@ -370,7 +369,7 @@ fun ShoesItem(releaseProductResponseDto: ResponseReleaseProductDto.ReleaseProduc } @Composable -fun ShoesList(viewModel:ReleaseProductViewModel) { +fun ShoesList(viewModel: ReleaseProductViewModel) { val shoesList = viewModel.productList.collectAsState().value Column { val items = List(12) { it } @@ -379,9 +378,9 @@ fun ShoesList(viewModel:ReleaseProductViewModel) { modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceEvenly, ) { - ShoesItem( shoesList[i],i+1, viewModel) + ShoesItem(shoesList[i], i + 1, viewModel) if (i + 1 < items.size) { - ShoesItem(shoesList[i + 1],i+2,viewModel) + ShoesItem(shoesList[i + 1], i + 2, viewModel) } } Spacer(modifier = Modifier.height(14.dp)) diff --git a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/release/ReleaseProductViewModel.kt b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/release/ReleaseProductViewModel.kt index fa9d41c..d2587db 100644 --- a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/release/ReleaseProductViewModel.kt +++ b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/release/ReleaseProductViewModel.kt @@ -9,10 +9,8 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import org.sopt.kream.data.ServicePool -import org.sopt.kream.data.model.request.RequestDeleteScrapDto import org.sopt.kream.data.model.response.ResponseReleaseProductDto import org.sopt.kream.domain.repository.ProductRepository -import org.sopt.kream.util.base.BaseResponse import org.sopt.kream.util.view.UiState class ReleaseProductViewModel( @@ -29,12 +27,10 @@ class ReleaseProductViewModel( val getReleaseProductState get() = _getReleaseProductState.asStateFlow() val deleteScrapState get() = _deleteScrapState.asStateFlow() - private val _productList = MutableStateFlow>(listOf()) + private val _productList = MutableStateFlow>(listOf()) val productList get() = _productList.asStateFlow() - - fun getReleaseProduct() { viewModelScope.launch { runCatching { @@ -47,7 +43,8 @@ class ReleaseProductViewModel( } } } - fun deleteScrap(productIndex:Int){ + + fun deleteScrap(productIndex: Int) { Log.d("okhttp", "hi 1") viewModelScope.launch { repository.deleteScrap(2, productIndex) @@ -61,7 +58,6 @@ class ReleaseProductViewModel( } } - private fun generateDummyAdvertisement(): List { return AdvertisementType.entries.mapIndexed { index, adEnum -> Advertisement(