Add ical file
This commit is contained in:
parent
4250497f80
commit
e2d23f4dcf
|
@ -1,20 +1,44 @@
|
||||||
package de.kif.backend.route
|
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.backend.repository.ScheduleRepository
|
||||||
|
import de.kif.common.model.Schedule
|
||||||
import io.ktor.application.call
|
import io.ktor.application.call
|
||||||
import io.ktor.http.ContentType
|
import io.ktor.http.ContentType
|
||||||
import io.ktor.response.respondText
|
import io.ktor.response.respondText
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import io.ktor.routing.get
|
import io.ktor.routing.get
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
fun Route.calendarExport() {
|
fun Route.calendarExport() {
|
||||||
get("export/kif.ics") {
|
get("export/kif.ics") {
|
||||||
val scheduleList = ScheduleRepository.all()
|
val scheduleList: List<Schedule> = ScheduleRepository.all()
|
||||||
|
|
||||||
//TODO
|
val ical = ICalendar()
|
||||||
|
for (scheduleItem in scheduleList) {
|
||||||
val text = ""
|
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)
|
call.respondText(contentType = ContentType.parse("text/calendar"), text = text)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue