Skip to content

Commit

Permalink
[MERGE] #100 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#100] 판매뷰 / 판매 물품 확인 & 확정 API 구현
  • Loading branch information
Marchbreeze authored Sep 1, 2024
2 parents bc82159 + 5392c20 commit c17131f
Show file tree
Hide file tree
Showing 19 changed files with 262 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import co.orange.data.repositoryImpl.ProfileRepositoryImpl
import co.orange.data.repositoryImpl.SearchRepositoryImpl
import co.orange.data.repositoryImpl.SellRepositoryImpl
import co.orange.data.repositoryImpl.SettingRepositoryImpl
import co.orange.data.repositoryImpl.UploadRepositoryImpl
import co.orange.domain.repository.AuthRepository
import co.orange.domain.repository.BuyRepository
import co.orange.domain.repository.DeviceRepository
Expand All @@ -20,6 +21,7 @@ import co.orange.domain.repository.ProfileRepository
import co.orange.domain.repository.SearchRepository
import co.orange.domain.repository.SellRepository
import co.orange.domain.repository.SettingRepository
import co.orange.domain.repository.UploadRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -65,6 +67,10 @@ object RepositoryModule {
@Singleton
fun provideInterestRepository(interestRepositoryImpl: InterestRepositoryImpl): InterestRepository = interestRepositoryImpl

@Provides
@Singleton
fun provideUploadRepository(uploadRepositoryImpl: UploadRepositoryImpl): UploadRepository = uploadRepositoryImpl

@Provides
@Singleton
fun provideIamportRepository(iamportRepositoryImpl: IamportRepositoryImpl): IamportRepository = iamportRepositoryImpl
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/co/orange/ddanzi/di/module/ServiceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import co.orange.data.service.ProfileService
import co.orange.data.service.SearchService
import co.orange.data.service.SellService
import co.orange.data.service.SettingService
import co.orange.data.service.UploadService
import co.orange.ddanzi.di.interceptor.RetrofitQualifier
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -75,6 +76,12 @@ object ServiceModule {
@RetrofitQualifier.JWT retrofit: Retrofit,
): InterestService = retrofit.create(InterestService::class.java)

@Provides
@Singleton
fun provideUploadService(
@RetrofitQualifier.NOTOKEN retrofit: Retrofit,
): UploadService = retrofit.create(UploadService::class.java)

@Provides
@Singleton
fun provideIamportService(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package co.orange.data.dataSource

import co.orange.data.dto.BaseResponse
import co.orange.data.dto.request.SellCheckRequestDto
import co.orange.data.dto.response.SellCheckedProductDto
import co.orange.data.dto.response.SellProductDto
import co.orange.data.dto.response.SignedUrlDto

interface SellDataSource {
suspend fun getSignedUrl(fileName: String): BaseResponse<SignedUrlDto>

suspend fun postToCheckProduct(request: SellCheckRequestDto): BaseResponse<SellCheckedProductDto>

suspend fun getProductToSell(productId: String): BaseResponse<SellProductDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package co.orange.data.dataSourceImpl

import co.orange.data.dataSource.SellDataSource
import co.orange.data.dto.BaseResponse
import co.orange.data.dto.request.SellCheckRequestDto
import co.orange.data.dto.response.SellCheckedProductDto
import co.orange.data.dto.response.SellProductDto
import co.orange.data.dto.response.SignedUrlDto
import co.orange.data.service.SellService
import javax.inject.Inject
Expand All @@ -12,4 +15,9 @@ data class SellDateSourceImpl
private val sellService: SellService,
) : SellDataSource {
override suspend fun getSignedUrl(fileName: String): BaseResponse<SignedUrlDto> = sellService.getSignedUrl(fileName)

override suspend fun postToCheckProduct(request: SellCheckRequestDto): BaseResponse<SellCheckedProductDto> =
sellService.postToCheckProduct(request)

override suspend fun getProductToSell(productId: String): BaseResponse<SellProductDto> = sellService.getProductToSell(productId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package co.orange.data.dto.request

import co.orange.domain.entity.request.SellCheckRequestModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SellCheckRequestDto(
@SerialName("image_url")
val imageUrl: String,
) {
companion object {
fun SellCheckRequestModel.toDto() = SellCheckRequestDto(imageUrl)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package co.orange.data.dto.response

import co.orange.domain.entity.response.SellCheckedProductModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SellCheckedProductDto(
@SerialName("productId")
val productId: String,
@SerialName("productName")
val productName: String,
) {
fun toModel() = SellCheckedProductModel(productId, productName)
}
21 changes: 21 additions & 0 deletions data/src/main/java/co/orange/data/dto/response/SellProductDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package co.orange.data.dto.response

import co.orange.domain.entity.response.SellProductModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SellProductDto(
@SerialName("productId")
val productId: String,
@SerialName("productName")
val productName: String,
@SerialName("originPrice")
val originPrice: Int,
@SerialName("salePrice")
val salePrice: Int,
@SerialName("isAddressExist")
val isAddressExist: Boolean,
) {
fun toModel() = SellProductModel(productId, productName, originPrice, salePrice, isAddressExist)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package co.orange.data.repositoryImpl

import co.orange.data.dataSource.SellDataSource
import co.orange.data.dto.request.SellCheckRequestDto.Companion.toDto
import co.orange.domain.entity.request.SellCheckRequestModel
import co.orange.domain.entity.response.SellCheckedProductModel
import co.orange.domain.entity.response.SellProductModel
import co.orange.domain.entity.response.SignedUrlModel
import co.orange.domain.repository.SellRepository
import javax.inject.Inject
Expand All @@ -14,4 +18,14 @@ class SellRepositoryImpl
runCatching {
sellDataSource.getSignedUrl(fileName).data.toModel()
}

override suspend fun postToCheckProduct(request: SellCheckRequestModel): Result<SellCheckedProductModel> =
runCatching {
sellDataSource.postToCheckProduct(request.toDto()).data.toModel()
}

override suspend fun getProductToSell(productId: String): Result<SellProductModel> =
runCatching {
sellDataSource.getProductToSell(productId).data.toModel()
}
}
16 changes: 16 additions & 0 deletions data/src/main/java/co/orange/data/service/SellService.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
package co.orange.data.service

import co.orange.data.dto.BaseResponse
import co.orange.data.dto.request.SellCheckRequestDto
import co.orange.data.dto.response.SellCheckedProductDto
import co.orange.data.dto.response.SellProductDto
import co.orange.data.dto.response.SignedUrlDto
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface SellService {
@GET("/api/v1/item/signed-url")
suspend fun getSignedUrl(
@Query("fileName") fileName: String,
): BaseResponse<SignedUrlDto>

@POST("/api/v1/item/check")
suspend fun postToCheckProduct(
@Body request: SellCheckRequestDto,
): BaseResponse<SellCheckedProductDto>

@GET("/api/v1/item/product/{id}")
suspend fun getProductToSell(
@Path("id") productId: String,
): BaseResponse<SellProductDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package co.orange.domain.entity.request

data class SellCheckRequestModel(
val imageUrl: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package co.orange.domain.entity.response

data class SellCheckedProductModel(
val productId: String,
val productName: String,
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package co.orange.domain.entity.response

data class SellProductModel(
val productId: Long,
val productId: String,
val productName: String,
val originPrice: Int,
val salePrice: Int,
val isAddressExist: Boolean,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package co.orange.domain.repository

import co.orange.domain.entity.request.SellCheckRequestModel
import co.orange.domain.entity.response.SellCheckedProductModel
import co.orange.domain.entity.response.SellProductModel
import co.orange.domain.entity.response.SignedUrlModel

interface SellRepository {
suspend fun getSignedUrl(fileName: String): Result<SignedUrlModel>

suspend fun postToCheckProduct(request: SellCheckRequestModel): Result<SellCheckedProductModel>

suspend fun getProductToSell(productId: String): Result<SellProductModel>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.core.view.isVisible
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import co.orange.core.base.BaseActivity
import co.orange.core.extension.setOnSingleClickListener
import co.orange.core.extension.setStatusBarColorFromResource
import co.orange.core.extension.stringOf
import co.orange.core.extension.toast
import co.orange.core.state.UiState
Expand Down Expand Up @@ -52,10 +54,7 @@ class SellOnboardingActivity :
photoPickerResult.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
} else {
galleryPickerResult.launch(
Intent(Intent.ACTION_PICK).apply {
type = "image/*"
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
},
Intent(Intent.ACTION_PICK).apply { type = "image/*" },
)
}
}
Expand Down Expand Up @@ -99,17 +98,33 @@ class SellOnboardingActivity :
.onEach { state ->
when (state) {
is UiState.Success -> {
// sellProductDialog = SellProductDialog()
// sellProductDialog?.show(supportFragmentManager, SELL_PRODUCT_DIALOG)
setLoadingScreen(false)
sellProductDialog = SellProductDialog()
sellProductDialog?.show(supportFragmentManager, SELL_PRODUCT_DIALOG)
viewModel.resetProductIdState()
}

is UiState.Failure -> toast(stringOf(R.string.error_msg))
else -> return@onEach
is UiState.Failure -> {
setLoadingScreen(false)
toast(stringOf(R.string.error_msg))
}

is UiState.Loading -> setLoadingScreen(true)
is UiState.Empty -> return@onEach
}
}.launchIn(lifecycleScope)
}

private fun setLoadingScreen(isLoading: Boolean) {
if (isLoading) {
setStatusBarColorFromResource(R.color.background_50)
binding.layoutLoading.isVisible = true
} else {
setStatusBarColorFromResource(R.color.white)
binding.layoutLoading.isVisible = false
}
}

override fun onDestroy() {
super.onDestroy()
sellProductDialog = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import co.orange.core.extension.getFileName
import co.orange.core.state.UiState
import co.orange.domain.entity.request.SellCheckRequestModel
import co.orange.domain.repository.SellRepository
import co.orange.domain.repository.UploadRepository
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -27,6 +28,9 @@ class SellOnboardingViewModel
private var selectedImageName = ""
private var uploadedUrl = ""

var productId = ""
var productName = ""

private val _isCheckedAgain = MutableSharedFlow<Boolean>()
val isCheckedAgain: SharedFlow<Boolean> = _isCheckedAgain

Expand Down Expand Up @@ -63,14 +67,29 @@ class SellOnboardingViewModel
viewModelScope.launch {
uploadRepository.putImageToCloud(url, selectedImageUri)
.onSuccess {
// 성공 시 이미지 요청
postToCheckProduct()
}.onFailure {
_changingImageState.value = UiState.Failure(it.message.toString())
_changingImageState.value = UiState.Empty
}
}
}

private fun postToCheckProduct() {
viewModelScope.launch {
sellRepository.postToCheckProduct(SellCheckRequestModel(uploadedUrl))
.onSuccess {
productId = it.productId
productName = it.productName
_changingImageState.value = UiState.Success(it.productId)
}
.onFailure {
_changingImageState.value = UiState.Failure(it.message.toString())
_changingImageState.value = UiState.Empty
}
}
}

fun resetProductIdState() {
_changingImageState.value = UiState.Empty
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class SellProductDialog :

private fun initConfirmBtnListener() {
binding.btnSubmit.setOnSingleClickListener {
// TODO intent값 수정
SellProgressActivity.createIntent(requireContext(), -1).apply {
SellProgressActivity.createIntent(requireContext(), viewModel.productId).apply {
startActivity(this)
}
dismiss()
Expand All @@ -62,7 +61,7 @@ class SellProductDialog :
with(binding) {
// TODO
// ivSellProduct.load()
tvSellProductName.text = "퓨퓨어 오일 퍼퓸 긴제목 텍스트트트트트트"
tvSellProductName.text = viewModel.productName
}
}
}
Loading

0 comments on commit c17131f

Please sign in to comment.