mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2026-01-17 12:02:26 +01:00
feat:#49 refactoring and tests
This commit is contained in:
@@ -30,6 +30,39 @@ import (
|
||||
func GenerateIcalFeed(events model.Events, mapping map[string]model.FeedCollection, userAgent string) *ics.Calendar {
|
||||
|
||||
cal := ics.NewCalendarFor("HTWK Kalender")
|
||||
setDefaultIcalParams(cal)
|
||||
|
||||
europeTime, _ := time.LoadLocation("Europe/Berlin")
|
||||
internalClock := clock.RealClock{}
|
||||
|
||||
for _, event := range events {
|
||||
mapEntry, mappingFound := mapping[event.UUID]
|
||||
|
||||
var eventHash = functions.HashString(time.Time(event.Start).String() + time.Time(event.End).String() + event.Course + event.Name + event.Rooms)
|
||||
|
||||
icalEvent := ics.NewEvent(eventHash + "@htwkalender.de")
|
||||
|
||||
icalEvent.SetDtStampTime(internalClock.Now().Local().In(europeTime))
|
||||
icalEvent.SetStartAt(time.Time(event.Start).Local().In(europeTime))
|
||||
icalEvent.SetEndAt(time.Time(event.End).Local().In(europeTime))
|
||||
|
||||
if mappingFound {
|
||||
addPropertyIfNotEmpty(icalEvent, ics.ComponentPropertySummary, replaceNameIfUserDefined(&event, mapEntry))
|
||||
addAlarmIfSpecified(icalEvent, event, mapEntry, internalClock)
|
||||
} else {
|
||||
addPropertyIfNotEmpty(icalEvent, ics.ComponentPropertySummary, event.Name)
|
||||
}
|
||||
|
||||
addUserAgentSpecificDescription(icalEvent, event, userAgent)
|
||||
addPropertyIfNotEmpty(icalEvent, ics.ComponentPropertyLocation, event.Rooms)
|
||||
|
||||
cal.AddVEvent(icalEvent)
|
||||
|
||||
}
|
||||
return cal
|
||||
}
|
||||
|
||||
func setDefaultIcalParams(cal *ics.Calendar) {
|
||||
cal.SetMethod(ics.MethodPublish)
|
||||
cal.SetProductId("-//HTWK Kalender//htwkalender.de//DE")
|
||||
cal.SetTzid("Europe/Berlin")
|
||||
@@ -116,35 +149,6 @@ func GenerateIcalFeed(events model.Events, mapping map[string]model.FeedCollecti
|
||||
}
|
||||
|
||||
cal.AddVTimezone(vTimeZone)
|
||||
|
||||
europeTime, _ := time.LoadLocation("Europe/Berlin")
|
||||
internalClock := clock.RealClock{}
|
||||
|
||||
for _, event := range events {
|
||||
mapEntry, mappingFound := mapping[event.UUID]
|
||||
|
||||
var eventHash = functions.HashString(time.Time(event.Start).String() + time.Time(event.End).String() + event.Course + event.Name + event.Rooms)
|
||||
|
||||
icalEvent := ics.NewEvent(eventHash + "@htwkalender.de")
|
||||
|
||||
icalEvent.SetDtStampTime(internalClock.Now().Local().In(europeTime))
|
||||
icalEvent.SetStartAt(time.Time(event.Start).Local().In(europeTime))
|
||||
icalEvent.SetEndAt(time.Time(event.End).Local().In(europeTime))
|
||||
|
||||
if mappingFound {
|
||||
addPropertyIfNotEmpty(icalEvent, ics.ComponentPropertySummary, replaceNameIfUserDefined(&event, mapEntry))
|
||||
addAlarmIfSpecified(icalEvent, event, mapEntry, internalClock)
|
||||
} else {
|
||||
addPropertyIfNotEmpty(icalEvent, ics.ComponentPropertySummary, event.Name)
|
||||
}
|
||||
|
||||
generateUserAgentSpecificDescription(icalEvent, event, userAgent)
|
||||
addPropertyIfNotEmpty(icalEvent, ics.ComponentPropertyLocation, event.Rooms)
|
||||
|
||||
cal.AddVEvent(icalEvent)
|
||||
|
||||
}
|
||||
return cal
|
||||
}
|
||||
|
||||
// AddPropertyIfNotEmpty adds a property to the component if the value is not empty
|
||||
@@ -173,6 +177,5 @@ func replaceNameIfUserDefined(event *model.Event, mapping model.FeedCollection)
|
||||
if !functions.OnlyWhitespace(mapping.UserDefinedName) {
|
||||
return names.ReplaceTemplateSubStrings(mapping.UserDefinedName, *event)
|
||||
}
|
||||
|
||||
return event.Name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user