diff --git a/src/jvmMain/kotlin/de/kif/backend/route/CalendarExport.kt b/src/jvmMain/kotlin/de/kif/backend/route/CalendarExport.kt index f3f7739..2606999 100644 --- a/src/jvmMain/kotlin/de/kif/backend/route/CalendarExport.kt +++ b/src/jvmMain/kotlin/de/kif/backend/route/CalendarExport.kt @@ -1,20 +1,44 @@ package de.kif.backend.route +import biweekly.Biweekly +import biweekly.ICalendar +import biweekly.component.VEvent +import biweekly.util.Duration import de.kif.backend.repository.ScheduleRepository +import de.kif.common.model.Schedule import io.ktor.application.call import io.ktor.http.ContentType import io.ktor.response.respondText import io.ktor.routing.Route import io.ktor.routing.get +import java.util.* fun Route.calendarExport() { get("export/kif.ics") { - val scheduleList = ScheduleRepository.all() + val scheduleList: List = ScheduleRepository.all() - //TODO - - val text = "" + val ical = ICalendar() + for (scheduleItem in scheduleList) { + val event = VEvent() + event.setSummary(scheduleItem.workGroup.name) + event.setDescription(scheduleItem.workGroup.description) + val startTime = scheduleItem.getAbsoluteEndTime() + val calendar = Calendar.getInstance() + calendar.clear() + calendar.set( + 2019, + 5, + 13 + scheduleItem.day, + scheduleItem.time / 60, + scheduleItem.time % 60 + ) + event.setDateStart(Date(calendar.timeInMillis)) + event.setDuration(Duration.fromMillis(scheduleItem.workGroup.length * 60 * 1000L)) + event.setLocation(scheduleItem.room.name) + ical.addEvent(event) + } + val text = Biweekly.write(ical).go() call.respondText(contentType = ContentType.parse("text/calendar"), text = text) }