package calendar import ( "math/rand" "time" "github.com/gin-gonic/gin" "kumoly.io/kumoly/app/server" "kumoly.io/kumoly/app/store" "kumoly.io/kumoly/app/util" ) type Service struct{} func (srv Service) GetName() string { return "calendar.Service" } func (srv Service) GetDependencies() []string { return []string{"server.Service"} } func (srv Service) IsService() bool { return false } func (srv Service) Main() error { return nil } func (srv Service) Del() {} func (srv Service) Health() error { return nil } func (srv Service) Init() error { rand.Seed(time.Now().UnixNano()) db = store.DB l = util.Klog.With().Str("mod", "calendar").Logger() l.Debug().Msg("Migrating database for calendar.Service ...") if err := store.Migrate(&Calendar{}, &EventGroup{}, &Event{}); err != nil { l.Error().Err(err).Msg("Migrating database") return err } return nil } func (srv Service) Load() error { calApi := server.API.Group("cal") calApi.GET("", ApiCalQuery) calApi.POST("", ApiCalNew) calApi.PUT("", ApiCalUpdate) calApi.DELETE("", ApiCalDelete) //+-30day server.Server.GET("ics/:cid/basic.ics", func(c *gin.Context) { cid := c.Param("cid") ics, err := ICS(cid, time.Now().Add(time.Hour*-720), time.Now().Add(time.Hour*720)) if err != nil { panic(err) } c.Header("Content-Type", "text/calendar; charset=utf-8") c.String(200, ics) }) eventApi := server.API.Group("event") eventApi.GET("", ApiEventQuery) eventApi.POST("", ApiEventNew) eventApi.PUT("", ApiEventUpdate) eventApi.DELETE("", ApiEventDelete) return nil }