-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from Team-Notitime/feat/announcement/113-read…
…-api Feat/announcement/113 read api
- Loading branch information
Showing
27 changed files
with
216 additions
and
136 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
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
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
46 changes: 46 additions & 0 deletions
46
...a/com/easyhz/noffice/domain/organization/usecase/organization/FetchOrganizationUseCase.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.easyhz.noffice.domain.organization.usecase.organization | ||
|
||
import com.easyhz.noffice.core.common.base.BaseUseCase | ||
import com.easyhz.noffice.core.common.di.Dispatcher | ||
import com.easyhz.noffice.core.common.di.NofficeDispatchers | ||
import com.easyhz.noffice.core.model.organization.OrganizationInformation | ||
import com.easyhz.noffice.core.model.organization.category.Category | ||
import com.easyhz.noffice.data.organization.repository.category.CategoryRepository | ||
import com.easyhz.noffice.data.organization.repository.organization.OrganizationRepository | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.coroutineScope | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
class FetchOrganizationUseCase @Inject constructor( | ||
@Dispatcher(NofficeDispatchers.IO) private val dispatcher: CoroutineDispatcher, | ||
private val categoryRepository: CategoryRepository, | ||
private val organizationRepository: OrganizationRepository | ||
):BaseUseCase<Int, OrganizationInformation>() { | ||
override suspend fun invoke(param: Int): Result<OrganizationInformation> = withContext(dispatcher) { | ||
runCatching { | ||
val (categoriesResult, organizationInfoResult) = coroutineScope { | ||
val categoriesDeferred = async { fetchCategories() } | ||
val organizationInfoDeferred = async { fetchOrganizationInfo(param) } | ||
|
||
categoriesDeferred.await() to organizationInfoDeferred.await() | ||
} | ||
|
||
val categoryList = categoriesResult.getOrThrow() | ||
val info = organizationInfoResult.getOrThrow() | ||
|
||
info.copy(category = categoryList.filter { it.id == info.id }) | ||
} | ||
} | ||
|
||
|
||
private suspend fun fetchCategories(): Result<List<Category>> { | ||
return categoryRepository.fetchCategories() | ||
} | ||
|
||
private suspend fun fetchOrganizationInfo(id: Int): Result<OrganizationInformation> { | ||
return organizationRepository.fetchOrganizationInfo(id) | ||
} | ||
|
||
} |
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
Oops, something went wrong.