-
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.
- Loading branch information
1 parent
998858f
commit 6103f75
Showing
9 changed files
with
143 additions
and
0 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
72 changes: 72 additions & 0 deletions
72
core/domain/src/commonMain/kotlin/club/nito/core/domain/GetParticipantScheduleListUseCase.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,72 @@ | ||
package club.nito.core.domain | ||
|
||
import club.nito.core.data.ParticipantRepository | ||
import club.nito.core.data.ScheduleRepository | ||
import club.nito.core.data.UserRepository | ||
import club.nito.core.domain.model.ParticipantSchedule | ||
import club.nito.core.model.FetchMultipleContentResult | ||
import club.nito.core.model.Schedule | ||
import club.nito.core.model.UserProfile | ||
import club.nito.core.model.participant.Participant | ||
import club.nito.core.model.toNitoError | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
|
||
/** | ||
* スケジュール一覧を取得するユースケース | ||
*/ | ||
sealed interface GetParticipantScheduleListUseCase { | ||
operator fun invoke(): Flow<FetchMultipleContentResult<ParticipantSchedule>> | ||
} | ||
|
||
class GetParticipantScheduleListExecutor( | ||
private val scheduleRepository: ScheduleRepository, | ||
private val participantRepository: ParticipantRepository, | ||
private val userRepository: UserRepository, | ||
) : GetParticipantScheduleListUseCase { | ||
override fun invoke(): Flow<FetchMultipleContentResult<ParticipantSchedule>> = flow { | ||
val schedules = try { | ||
scheduleRepository.getScheduleList(limit = 10) | ||
} catch (e: Throwable) { | ||
emit(FetchMultipleContentResult.Failure(error = e.toNitoError())) | ||
return@flow | ||
} | ||
|
||
if (schedules.isEmpty()) { | ||
emit(FetchMultipleContentResult.NoContent) | ||
return@flow | ||
} | ||
|
||
val participants = participantRepository.getParticipants(scheduleIds = schedules.map { it.id }) | ||
val profiles = userRepository.getProfiles(userIds = participants.distinctBy { it.userId }.map { it.userId }) | ||
|
||
val participantScheduleList = transformToParticipantScheduleList( | ||
schedules = schedules, | ||
participants = participants, | ||
userProfiles = profiles, | ||
) | ||
|
||
emit(FetchMultipleContentResult.Success(participantScheduleList)) | ||
} | ||
|
||
private fun transformToParticipantScheduleList( | ||
schedules: List<Schedule>, | ||
participants: List<Participant>, | ||
userProfiles: List<UserProfile>, | ||
): List<ParticipantSchedule> = schedules.map { schedule -> | ||
val scheduleParticipants = participants.filter { it.scheduleId == schedule.id } | ||
val scheduleParticipantProfiles = userProfiles.filter { profile -> | ||
scheduleParticipants.any { it.userId == profile.id } | ||
} | ||
|
||
ParticipantSchedule( | ||
id = schedule.id, | ||
scheduledAt = schedule.scheduledAt, | ||
metAt = schedule.metAt, | ||
venueId = schedule.venueId, | ||
meetId = schedule.meetId, | ||
description = schedule.description, | ||
participants = scheduleParticipantProfiles, | ||
) | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
core/model/src/commonMain/kotlin/club/nito/core/model/FetchMultipleContentResult.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,26 @@ | ||
package club.nito.core.model | ||
|
||
/** | ||
* 複数のコンテンツデータを取得する結果 | ||
*/ | ||
sealed interface FetchMultipleContentResult<out T> { | ||
/** | ||
* 取得中 | ||
*/ | ||
data object Loading : FetchMultipleContentResult<Nothing> | ||
|
||
/** | ||
* 該当データなし | ||
*/ | ||
data object NoContent : FetchMultipleContentResult<Nothing> | ||
|
||
/** | ||
* 取得成功 | ||
*/ | ||
data class Success<T>(val data: List<T>) : FetchMultipleContentResult<T> | ||
|
||
/** | ||
* 取得失敗 | ||
*/ | ||
data class Failure(val error: NitoError?) : FetchMultipleContentResult<Nothing> | ||
} |
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