Skip to content

Commit

Permalink
👍 各 UseCase で場所の情報を取得するよう変更
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsutakein committed Dec 5, 2023
1 parent d58a4d4 commit 631cba0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package club.nito.core.domain

import club.nito.core.data.ParticipantRepository
import club.nito.core.data.PlaceRepository
import club.nito.core.data.ScheduleRepository
import club.nito.core.data.UserRepository
import club.nito.core.domain.extension.toUserIdList
import club.nito.core.domain.model.ParticipantSchedule
import club.nito.core.model.FetchSingleContentResult
import club.nito.core.model.UserProfile
import club.nito.core.model.participant.Participant
import club.nito.core.model.place.Place
import club.nito.core.model.schedule.Schedule
import club.nito.core.model.schedule.ScheduleId
import club.nito.core.model.toNitoError
Expand All @@ -22,6 +24,7 @@ public sealed interface FetchParticipantScheduleByIdUseCase {
public class FetchParticipantScheduleByIdExecutor(
private val scheduleRepository: ScheduleRepository,
private val participantRepository: ParticipantRepository,
private val placeRepository: PlaceRepository,
private val userRepository: UserRepository,
) : FetchParticipantScheduleByIdUseCase {
override suspend fun invoke(id: ScheduleId): FetchSingleContentResult<ParticipantSchedule> {
Expand All @@ -33,10 +36,12 @@ public class FetchParticipantScheduleByIdExecutor(

val participants = participantRepository.getParticipants(id)
val profiles = userRepository.getProfiles(userIds = participants.toUserIdList())
val places = placeRepository.fetchPlaceList(schedule.venueId, schedule.meetId)
val participantSchedule = transformToParticipantSchedule(
schedule = schedule,
participants = participants,
userProfiles = profiles,
places = places,
)

return FetchSingleContentResult.Success(participantSchedule)
Expand All @@ -46,6 +51,7 @@ public class FetchParticipantScheduleByIdExecutor(
schedule: Schedule,
participants: List<Participant>,
userProfiles: List<UserProfile>,
places: List<Place>,
): ParticipantSchedule {
val scheduleParticipants = participants.filter { it.scheduleId == schedule.id }
val scheduleParticipantProfiles = userProfiles.filter { profile ->
Expand All @@ -56,8 +62,8 @@ public class FetchParticipantScheduleByIdExecutor(
id = schedule.id,
scheduledAt = schedule.scheduledAt,
metAt = schedule.metAt,
venueId = schedule.venueId,
meetId = schedule.meetId,
venue = places.first { it.id == schedule.venueId },
meet = places.first { it.id == schedule.meetId },
description = schedule.description,
participants = scheduleParticipantProfiles,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package club.nito.core.domain

import club.nito.core.data.ParticipantRepository
import club.nito.core.data.PlaceRepository
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.Schedule
import club.nito.core.model.UserProfile
import club.nito.core.model.participant.Participant
import club.nito.core.model.place.Place
import club.nito.core.model.schedule.Schedule
import club.nito.core.model.toNitoError
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
Expand All @@ -22,6 +24,7 @@ public sealed interface GetParticipantScheduleListUseCase {
public class GetParticipantScheduleListExecutor(
private val scheduleRepository: ScheduleRepository,
private val participantRepository: ParticipantRepository,
private val placeRepository: PlaceRepository,
private val userRepository: UserRepository,
) : GetParticipantScheduleListUseCase {
override fun invoke(): Flow<FetchMultipleContentResult<ParticipantSchedule>> = flow {
Expand All @@ -40,10 +43,14 @@ public class GetParticipantScheduleListExecutor(
val participants = participantRepository.getParticipants(scheduleIds = schedules.map { it.id })
val profiles = userRepository.getProfiles(userIds = participants.distinctBy { it.userId }.map { it.userId })

val placeIds = (schedules.map { it.meetId } + schedules.map { it.venueId }).distinct()
val places = placeRepository.fetchPlaceList(*placeIds.toTypedArray())

val participantScheduleList = transformToParticipantScheduleList(
schedules = schedules,
participants = participants,
userProfiles = profiles,
places = places,
)

emit(FetchMultipleContentResult.Success(participantScheduleList))
Expand All @@ -53,6 +60,7 @@ public class GetParticipantScheduleListExecutor(
schedules: List<Schedule>,
participants: List<Participant>,
userProfiles: List<UserProfile>,
places: List<Place>,
): List<ParticipantSchedule> = schedules.map { schedule ->
val scheduleParticipants = participants.filter { it.scheduleId == schedule.id }
val scheduleParticipantProfiles = userProfiles.filter { profile ->
Expand All @@ -63,8 +71,8 @@ public class GetParticipantScheduleListExecutor(
id = schedule.id,
scheduledAt = schedule.scheduledAt,
metAt = schedule.metAt,
venueId = schedule.venueId,
meetId = schedule.meetId,
venue = places.first { it.id == schedule.venueId },
meet = places.first { it.id == schedule.meetId },
description = schedule.description,
participants = scheduleParticipantProfiles,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package club.nito.core.domain

import club.nito.core.data.ParticipantRepository
import club.nito.core.data.PlaceRepository
import club.nito.core.data.ScheduleRepository
import club.nito.core.data.UserRepository
import club.nito.core.domain.model.ParticipantSchedule
import club.nito.core.model.FetchSingleContentResult
import club.nito.core.model.Order
import club.nito.core.model.schedule.Schedule
import club.nito.core.model.UserProfile
import club.nito.core.model.place.Place
import club.nito.core.model.schedule.Schedule
import club.nito.core.model.toNitoError
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
Expand All @@ -23,6 +25,7 @@ public sealed interface GetRecentScheduleUseCase {
public class GetRecentScheduleExecutor(
private val scheduleRepository: ScheduleRepository,
private val participantRepository: ParticipantRepository,
private val placeRepository: PlaceRepository,
private val userRepository: UserRepository,
) : GetRecentScheduleUseCase {
override fun invoke(): Flow<FetchSingleContentResult<ParticipantSchedule>> = flow {
Expand All @@ -46,10 +49,12 @@ public class GetRecentScheduleExecutor(

val participants = participantRepository.getParticipants(scheduleId = schedule.id)
val userProfiles = userRepository.getProfiles(userIds = participants.map { it.userId })
val places = placeRepository.fetchPlaceList(schedule.venueId, schedule.meetId)

val participantSchedule = transformToParticipantSchedule(
schedule = schedule,
userProfiles = userProfiles,
places = places,
)

emit(FetchSingleContentResult.Success(participantSchedule))
Expand All @@ -58,13 +63,14 @@ public class GetRecentScheduleExecutor(
private fun transformToParticipantSchedule(
schedule: Schedule,
userProfiles: List<UserProfile>,
places: List<Place>,
): ParticipantSchedule {
return ParticipantSchedule(
id = schedule.id,
scheduledAt = schedule.scheduledAt,
metAt = schedule.metAt,
venueId = schedule.venueId,
meetId = schedule.meetId,
venue = places.first { it.id == schedule.venueId },
meet = places.first { it.id == schedule.meetId },
description = schedule.description,
participants = userProfiles,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package club.nito.core.domain.model

import club.nito.core.model.UserProfile
import club.nito.core.model.place.Place
import club.nito.core.model.schedule.ScheduleId
import kotlinx.datetime.Instant

public data class ParticipantSchedule(
val id: ScheduleId,
val scheduledAt: Instant,
val metAt: Instant,
val venueId: String,
val meetId: String,
val venue: Place,
val meet: Place,
val description: String,
val participants: List<UserProfile>,
)

0 comments on commit 631cba0

Please sign in to comment.