Skip to content

Commit 15eed39

Browse files
committed
refactor/qg-253: типы календарей переведены со строк на типы
1 parent f469cc1 commit 15eed39

File tree

12 files changed

+40
-19
lines changed

12 files changed

+40
-19
lines changed

app/src/main/kotlin/pro/qyoga/app/therapist/appointments/core/edit/ops/GetAppointmentPrefillDataOp.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class GetAppointmentPrefillDataOp(
3232
val currentUserTimeZone = userSettingsRepo.getUserTimeZone(UserRef(therapistRef))
3333

3434
val sourceEvent = when (sourceItem?.type) {
35-
ICalCalendar.TYPE ->
35+
ICalCalendar.Type.name ->
3636
iCalCalendarsRepo.findById(therapistRef, sourceItem.icsEventId())
3737

38-
GoogleCalendar.TYPE ->
38+
GoogleCalendar.Type.name ->
3939
googleCalendarsService.findById(therapistRef, sourceItem.googleEventId())
4040

4141
else ->

app/src/main/kotlin/pro/qyoga/app/therapist/appointments/core/edit/view_model/SourceItem.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ data class SourceItem(
1111
val id: String
1212
) {
1313

14-
constructor(eventId: CalendarItemId) : this(eventId.type, eventId.toQueryParamStr())
14+
constructor(eventId: CalendarItemId) : this(eventId.type.name, eventId.toQueryParamStr())
1515

1616
companion object {
1717
fun icsEvent(eventId: ICalEventId): SourceItem =
18-
SourceItem(ICalCalendar.TYPE, eventId.toQueryParamStr())
18+
SourceItem(ICalCalendar.Type.name, eventId.toQueryParamStr())
1919

2020
fun googleEvent(eventId: GoogleCalendarItemId): SourceItem =
2121
SourceItem("Google", eventId.toQueryParamStr())
@@ -25,7 +25,7 @@ data class SourceItem(
2525
}
2626

2727
fun SourceItem.icsEventId(): ICalEventId {
28-
check(type == ICalCalendar.TYPE)
28+
check(type == ICalCalendar.Type.name)
2929
val matcher = "uid=(.+),rid=(.*)".toRegex().matchEntire(id)
3030
check(matcher != null)
3131
val uid = matcher.groups[1]!!.value
@@ -34,7 +34,7 @@ fun SourceItem.icsEventId(): ICalEventId {
3434
}
3535

3636
fun SourceItem.googleEventId(): GoogleCalendarItemId {
37-
check(type == GoogleCalendar.TYPE)
37+
check(type == GoogleCalendar.Type.name)
3838
val matcher = "(.+),(.+)".toRegex().matchEntire(id)
3939
check(matcher != null)
4040
return GoogleCalendarItemId(matcher.groups[1]!!.value, matcher.groups[2]!!.value)

app/src/main/kotlin/pro/qyoga/core/calendar/api/Calendar.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ import pro.qyoga.core.users.therapists.TherapistRef
66
interface Calendar {
77
val ownerRef: TherapistRef
88
val name: String
9-
val type: String
10-
}
9+
val type: CalendarType
10+
}

app/src/main/kotlin/pro/qyoga/core/calendar/api/CalendarItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.time.temporal.Temporal
55

66
interface CalendarItemId {
77

8-
val type: String
8+
val type: CalendarType
99

1010
fun toQueryParamStr(): String
1111

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package pro.qyoga.core.calendar.api
2+
3+
4+
interface CalendarType {
5+
6+
val name: String
7+
8+
}

app/src/main/kotlin/pro/qyoga/core/calendar/api/CalendarsService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ data class SearchResult<ID>(
1313

1414
interface CalendarsService<ID> {
1515

16+
val type: CalendarType
17+
1618
fun findCalendarItemsInInterval(
1719
therapist: TherapistRef,
1820
interval: Interval<ZonedDateTime>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pro.qyoga.i9ns.calendars.google
22

33
import pro.qyoga.core.calendar.api.Calendar
4+
import pro.qyoga.core.calendar.api.CalendarType
45
import pro.qyoga.core.users.therapists.TherapistRef
56

67

@@ -10,11 +11,10 @@ data class GoogleCalendar(
1011
override val name: String,
1112
) : Calendar {
1213

13-
override val type: String = TYPE
14+
override val type: CalendarType = Type
1415

15-
companion object {
16-
17-
const val TYPE = "Google"
16+
object Type : CalendarType {
17+
override val name = "Google"
1818
}
1919

2020
}

app/src/main/kotlin/pro/qyoga/i9ns/calendars/google/GoogleCalendarItem.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ package pro.qyoga.i9ns.calendars.google
33
import pro.azhidkov.platform.java.time.toLocalDateTime
44
import pro.qyoga.core.calendar.api.CalendarItem
55
import pro.qyoga.core.calendar.api.CalendarItemId
6+
import pro.qyoga.core.calendar.api.CalendarType
67
import java.time.Duration
78
import java.time.ZoneId
89
import java.time.temporal.Temporal
910

11+
1012
data class GoogleCalendarItemId(
1113
val calendarId: String,
1214
val itemId: String
1315
) : CalendarItemId {
1416

15-
override val type: String = GoogleCalendar.TYPE
17+
override val type: CalendarType = GoogleCalendar.Type
1618

1719
override fun toQueryParamStr(): String =
1820
"$calendarId,$itemId"

app/src/main/kotlin/pro/qyoga/i9ns/calendars/google/GoogleCalendarsService.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import pro.azhidkov.platform.java.time.zoneId
1010
import pro.azhidkov.platform.kotlin.tryExecute
1111
import pro.azhidkov.platform.spring.sdj.ergo.hydration.ref
1212
import pro.qyoga.core.calendar.api.CalendarItem
13+
import pro.qyoga.core.calendar.api.CalendarType
1314
import pro.qyoga.core.calendar.api.CalendarsService
1415
import pro.qyoga.core.calendar.api.SearchResult
1516
import pro.qyoga.core.users.therapists.TherapistRef
@@ -81,6 +82,8 @@ class GoogleCalendarsService(
8182
private val googleCalendarsClient: GoogleCalendarsClient,
8283
) : CalendarsService<GoogleCalendarItemId> {
8384

85+
override val type: CalendarType = GoogleCalendar.Type
86+
8487
private val executor = VirtualThreadExecutor("google-calendar-events-fetcher")
8588

8689
fun addGoogleAccount(googleAccount: GoogleAccount) {

app/src/main/kotlin/pro/qyoga/i9ns/calendars/ical/ICalCalendarsRepo.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.springframework.scheduling.annotation.Scheduled
55
import org.springframework.stereotype.Component
66
import pro.azhidkov.platform.java.time.Interval
77
import pro.qyoga.core.calendar.api.CalendarItem
8+
import pro.qyoga.core.calendar.api.CalendarType
89
import pro.qyoga.core.calendar.api.CalendarsService
910
import pro.qyoga.core.calendar.api.SearchResult
1011
import pro.qyoga.core.users.therapists.TherapistRef
@@ -24,6 +25,8 @@ class ICalCalendarsRepo(
2425

2526
private val log = LoggerFactory.getLogger(javaClass)
2627

28+
override val type: CalendarType = ICalCalendar.Type
29+
2730
fun addICal(createICalRq: CreateICalRq): ICalCalendar {
2831
val icsData = createICalRq.icsUrl.readText()
2932
val ical = ICalCalendar.createFrom(createICalRq, icsData)

0 commit comments

Comments
 (0)