-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I think I found a pattern I like for calendar abstraction finally
Now just to get it all implemented
- Loading branch information
1 parent
ef9a382
commit 835e8bb
Showing
6 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
core/src/main/kotlin/org/dreamexposure/discal/core/business/CalendarProvider.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,13 @@ | ||
package org.dreamexposure.discal.core.business | ||
|
||
import org.dreamexposure.discal.core.`object`.new.Calendar | ||
import org.dreamexposure.discal.core.`object`.new.CalendarMetadata | ||
import org.dreamexposure.discal.core.`object`.new.CalendarMetadata.* | ||
|
||
interface CalendarProvider { | ||
val host: Host | ||
|
||
suspend fun getCalendar(metadata: CalendarMetadata): Calendar? | ||
|
||
// TODO: Implement the rest of required CRUD functions | ||
} |
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
...ain/kotlin/org/dreamexposure/discal/core/business/google/GoogleCalendarProviderService.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 org.dreamexposure.discal.core.business.google | ||
|
||
import org.dreamexposure.discal.core.business.CalendarProvider | ||
import org.dreamexposure.discal.core.`object`.new.Calendar | ||
import org.dreamexposure.discal.core.`object`.new.CalendarMetadata | ||
import org.springframework.stereotype.Component | ||
import java.time.ZoneId | ||
|
||
@Component | ||
class GoogleCalendarProviderService( | ||
val googleCalendarApiWrapper: GoogleCalendarApiWrapper, | ||
) : CalendarProvider { | ||
override val host = CalendarMetadata.Host.GOOGLE | ||
|
||
override suspend fun getCalendar(metadata: CalendarMetadata): Calendar? { | ||
val googleCalendar = googleCalendarApiWrapper.getCalendar(metadata) ?: return null | ||
|
||
return Calendar( | ||
metadata = metadata, | ||
name = googleCalendar.summary.orEmpty(), | ||
description = googleCalendar.description.orEmpty(), | ||
timezone = ZoneId.of(googleCalendar.timeZone), | ||
hostLink = "https://calendar.google.com/calendar/embed?src=${metadata.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
16 changes: 16 additions & 0 deletions
16
core/src/main/kotlin/org/dreamexposure/discal/core/object/new/Calendar.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,16 @@ | ||
package org.dreamexposure.discal.core.`object`.new | ||
|
||
import org.dreamexposure.discal.core.config.Config | ||
import java.time.ZoneId | ||
|
||
data class Calendar( | ||
val metadata: CalendarMetadata, | ||
val name: String, | ||
val description: String, | ||
val timezone: ZoneId, | ||
val hostLink: String, | ||
) { | ||
// TODO: Consider moving this link formatting somewhere else? | ||
val link: String | ||
get() = "${Config.URL_BASE.getString()}/embed/${metadata.guildId.asString()}/calendar/${metadata.number}" | ||
} |
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