Skip to content

Commit

Permalink
#91 약 관심 추가/목록/삭제/확인 로직 데이터 영역 부분 작업 완
Browse files Browse the repository at this point in the history
  • Loading branch information
pknujsp committed Jun 7, 2023
1 parent e35e458 commit 6924768
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package com.android.mediproject.core.data.remote.interestedmedicine


import com.android.mediproject.core.model.medicine.InterestedMedicine.AddInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.DeleteInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.InterestedMedicineListResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.IsInterestedMedicineResponse
import com.android.mediproject.core.model.requestparameters.AddInterestedMedicineParameter
import kotlinx.coroutines.flow.Flow

interface InterestedMedicineRepository {
suspend fun getInterestedMedicineList() : Flow<Result<List<InterestedMedicineListResponse.Medicine>>>
suspend fun getInterestedMedicineList(): Flow<Result<List<InterestedMedicineListResponse.Medicine>>>

fun addInterestedMedicine(addInterestedMedicineParameter: AddInterestedMedicineParameter): Flow<Result<AddInterestedMedicineResponse>>

fun deleteInterestedMedicine(medicineId: Long): Flow<Result<DeleteInterestedMedicineResponse>>

fun isInterestedMedicine(itemSeq: Long): Flow<Result<IsInterestedMedicineResponse>>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.android.mediproject.core.data.remote.interestedmedicine

import com.android.mediproject.core.model.medicine.InterestedMedicine.AddInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.DeleteInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.InterestedMedicineListResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.IsInterestedMedicineResponse
import com.android.mediproject.core.model.requestparameters.AddInterestedMedicineParameter
import com.android.mediproject.core.network.datasource.interestedmedicine.InterestedMedicineDataSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
Expand All @@ -11,12 +15,18 @@ import javax.inject.Inject

class InterestedMedicineRepositoryImpl @Inject constructor(private val interestedMedicineDataSource: InterestedMedicineDataSource) :
InterestedMedicineRepository {
override suspend fun getInterestedMedicineList(): Flow<Result<List<InterestedMedicineListResponse.Medicine>>> =
channelFlow {
interestedMedicineDataSource.getInterestedMedicineList().map { result ->
result.fold(
onSuccess = { Result.success(it.medicineList) },
onFailure = { Result.failure(it) })
}.collectLatest { trySend(it) }
}
override suspend fun getInterestedMedicineList(): Flow<Result<List<InterestedMedicineListResponse.Medicine>>> = channelFlow {
interestedMedicineDataSource.getInterestedMedicineList().map { result ->
result.fold(onSuccess = { Result.success(it.medicineList) }, onFailure = { Result.failure(it) })
}.collectLatest { trySend(it) }
}

override fun addInterestedMedicine(addInterestedMedicineParameter: AddInterestedMedicineParameter): Flow<Result<AddInterestedMedicineResponse>> =
interestedMedicineDataSource.addInterestedMedicine(addInterestedMedicineParameter)

override fun deleteInterestedMedicine(medicineId: Long): Flow<Result<DeleteInterestedMedicineResponse>> =
interestedMedicineDataSource.deleteInterestedMedicine(medicineId)

override fun isInterestedMedicine(itemSeq: Long): Flow<Result<IsInterestedMedicineResponse>> =
interestedMedicineDataSource.isInterestedMedicine(itemSeq)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.android.mediproject.core.domain

import com.android.mediproject.core.data.remote.interestedmedicine.InterestedMedicineRepository
import com.android.mediproject.core.model.medicine.InterestedMedicine.AddInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.DeleteInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.IsInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.toInterestedMedicineDto
import com.android.mediproject.core.model.requestparameters.AddInterestedMedicineParameter
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.map
Expand All @@ -11,9 +16,25 @@ class GetInterestedMedicineUseCase @Inject constructor(private val interestedMed

suspend fun getInterestedMedicineList() = channelFlow {
interestedMedicineRepository.getInterestedMedicineList().map { result ->
result.fold(
onSuccess = { Result.success(it.map { it.toInterestedMedicineDto() }) },
onFailure = { Result.failure(it) })
result.fold(onSuccess = { Result.success(it.map { it.toInterestedMedicineDto() }) }, onFailure = { Result.failure(it) })
}.collectLatest { trySend(it) }
}

/**
* 관심 약 추가
*/
fun addInterestedMedicine(addInterestedMedicineParameter: AddInterestedMedicineParameter): Flow<Result<AddInterestedMedicineResponse>> =
interestedMedicineRepository.addInterestedMedicine(addInterestedMedicineParameter)

/**
* 관심 약 삭제
*/
fun deleteInterestedMedicine(medicineId: Long): Flow<Result<DeleteInterestedMedicineResponse>> =
interestedMedicineRepository.deleteInterestedMedicine(medicineId)

/**
* 관심 약 여부 확인
*/
fun isInterestedMedicine(medicineId: Long): Flow<Result<IsInterestedMedicineResponse>> =
interestedMedicineRepository.isInterestedMedicine(medicineId)
}

0 comments on commit 6924768

Please sign in to comment.