@@ -2,6 +2,7 @@ package pro.qyoga.app.therapist.appointments.core.schedule
22
33import org.springframework.stereotype.Component
44import pro.azhidkov.platform.java.time.Interval
5+ import pro.azhidkov.platform.kotlin.tryExecute
56import pro.qyoga.core.appointments.core.AppointmentsRepo
67import pro.qyoga.core.calendar.api.CalendarItem
78import pro.qyoga.core.calendar.google.GoogleCalendarsService
@@ -12,21 +13,36 @@ import pro.qyoga.core.users.therapists.TherapistRef
1213import java.time.*
1314
1415
16+ data class GetCalendarAppointmentsRs (
17+ val appointments : List <CalendarItem <* , LocalDateTime >>,
18+ val hasErrors : Boolean
19+ )
20+
1521@Component
1622class GetCalendarAppointmentsOp (
1723 private val userSettingsRepo : UserSettingsRepo ,
1824 private val appointmentsRepo : AppointmentsRepo ,
1925 private val iCalCalendarsRepo : ICalCalendarsRepo ,
2026 private val googleCalendarsService : GoogleCalendarsService
21- ) : (TherapistRef , LocalDate ) -> Iterable<CalendarItem<*, LocalDateTime>> {
27+ ) : (TherapistRef , LocalDate ) -> GetCalendarAppointmentsRs {
2228
23- override fun invoke (therapist : TherapistRef , date : LocalDate ): Iterable < CalendarItem < * , LocalDateTime >> {
29+ override fun invoke (therapist : TherapistRef , date : LocalDate ): GetCalendarAppointmentsRs {
2430 val currentUserTimeZone = userSettingsRepo.getUserTimeZone(UserRef (therapist))
2531 val interval = calendarIntervalAround(date, currentUserTimeZone)
2632 val appointments = appointmentsRepo.findCalendarItemsInInterval(therapist, interval)
27- val drafts = iCalCalendarsRepo.findCalendarItemsInInterval(therapist, interval) +
28- googleCalendarsService.findCalendarItemsInInterval(therapist, interval)
29- return appointments + drafts
33+
34+ val iCalEventsResult =
35+ tryExecute { iCalCalendarsRepo.findCalendarItemsInInterval(therapist, interval) }
36+
37+ val googleCalendarEventsResult =
38+ tryExecute { googleCalendarsService.findCalendarItemsInInterval(therapist, interval) }
39+
40+ val drafts =
41+ iCalEventsResult.getOrElse { emptyList() } +
42+ googleCalendarEventsResult.getOrElse { emptyList() }
43+
44+ val hasErrors = iCalEventsResult.isFailure || googleCalendarEventsResult.isFailure
45+ return GetCalendarAppointmentsRs (appointments + drafts, hasErrors)
3046 }
3147
3248}
0 commit comments