lot of new functionalities
This commit is contained in:
51
servers/web/api/calendars.go
Normal file
51
servers/web/api/calendars.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (h *Handler) CalendarGlobal(w http.ResponseWriter, r *http.Request) {
|
||||
enabled := h.config.GetBool("modules.agenda.enabled") && h.config.GetBool("modules.agenda.calendars.global.enabled")
|
||||
if !enabled {
|
||||
log.Error().Msg("global calendar not activated in configuration")
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.applicationHandler.GenerateGlobalCalendar(r.Context())
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error generating global calendar")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/calendar; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(result.CalendarData))
|
||||
}
|
||||
|
||||
func (h *Handler) CalendarOrganizations(w http.ResponseWriter, r *http.Request) {
|
||||
enabled := h.config.GetBool("modules.agenda.enabled") && h.config.GetBool("modules.agenda.calendars.organizations.enabled")
|
||||
if !enabled {
|
||||
log.Error().Msg("organizations calendar not activated in configuration")
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
vars := mux.Vars(r)
|
||||
groupID := vars["groupid"]
|
||||
|
||||
result, err := h.applicationHandler.GenerateOrganizationCalendar(r.Context(), groupID)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error generating organization calendar")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/calendar; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(result.CalendarData))
|
||||
}
|
||||
Reference in New Issue
Block a user