-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#91 검색 기록 저장/수정하는 SearchHistoryRepository내 로직 최적화, 불필요한 suspend 제거
- Loading branch information
Showing
11 changed files
with
49 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 16 additions & 9 deletions
25
...omain/src/main/java/com/android/mediproject/core/domain/GetMedicineApprovalListUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,36 @@ | ||
package com.android.mediproject.core.domain | ||
|
||
import androidx.paging.map | ||
import com.android.mediproject.core.common.network.Dispatcher | ||
import com.android.mediproject.core.common.network.MediDispatchers | ||
import com.android.mediproject.core.data.remote.medicineapproval.MedicineApprovalRepository | ||
import com.android.mediproject.core.model.constants.MedicationType | ||
import com.android.mediproject.core.model.parameters.ApprovalListSearchParameter | ||
import com.android.mediproject.core.model.medicine.medicineapproval.toDto | ||
import com.android.mediproject.core.model.parameters.ApprovalListSearchParameter | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.flow.flowOn | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
class GetMedicineApprovalListUseCase @Inject constructor( | ||
private val medicineApprovalRepository: MedicineApprovalRepository | ||
private val medicineApprovalRepository: MedicineApprovalRepository, | ||
@Dispatcher(MediDispatchers.Default) private val defaultDispatcher: CoroutineDispatcher, | ||
) { | ||
|
||
suspend operator fun invoke( | ||
/** | ||
* 약품 목록 조회 UseCase | ||
*/ | ||
operator fun invoke( | ||
parameter: ApprovalListSearchParameter | ||
) = medicineApprovalRepository.getMedicineApprovalList( | ||
itemName = parameter.itemName, entpName = parameter.entpName, medicationType = when (parameter.medicationType) { | ||
MedicationType.ALL -> null | ||
else -> parameter.medicationType.description | ||
} | ||
).let { pager -> | ||
pager.map { pagingData -> | ||
pagingData.map { item -> | ||
item.toDto() | ||
} | ||
).map { pagingData -> | ||
pagingData.map { item -> | ||
// 데이터 변환 | ||
item.toDto() | ||
} | ||
} | ||
}.flowOn(defaultDispatcher) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 2 additions & 10 deletions
12
...java/com/android/mediproject/feature/search/recentsearchlist/RecentSearchListViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,19 @@ | ||
package com.android.mediproject.feature.search.recentsearchlist | ||
|
||
import androidx.lifecycle.viewModelScope | ||
import com.android.mediproject.core.common.network.Dispatcher | ||
import com.android.mediproject.core.common.network.MediDispatchers | ||
import com.android.mediproject.core.domain.SearchHistoryUseCase | ||
import com.android.mediproject.core.ui.base.BaseViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.flow.shareIn | ||
import kotlinx.coroutines.flow.stateIn | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class RecentSearchListViewModel @Inject constructor( | ||
private val searchHistoryUseCase: SearchHistoryUseCase, | ||
@Dispatcher(MediDispatchers.IO) private val ioDispatcher: CoroutineDispatcher, | ||
) : BaseViewModel() { | ||
val searchHistoryList by lazy { | ||
suspend { | ||
searchHistoryUseCase.getSearchHistoryList(6).distinctUntilChanged().shareIn( | ||
viewModelScope, started = SharingStarted.Lazily, replay = 1 | ||
) | ||
searchHistoryUseCase.getSearchHistoryList(6).stateIn(viewModelScope) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters