Add ical file

This commit is contained in:
Leon Georgi 2019-06-13 12:23:02 +02:00
parent 4250497f80
commit e2d23f4dcf
Signed by: leon
GPG key ID: D97C549071D39393

View file

@ -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<Schedule> = 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)
}