package application import ( "net/http" "git.coopgo.io/coopgo-apps/parcoursmob/core/utils/identification" "git.coopgo.io/coopgo-platform/groups-management/storage" "github.com/rs/zerolog/log" ) func (h *Handler) GroupSettingsDisplayHTTPHandler() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { g := r.Context().Value(identification.GroupKey) if g == nil { http.Error(w, "Bad Request", http.StatusBadRequest) return } group := g.(storage.Group) result, err := h.applicationHandler.GetGroupSettings(r.Context(), group.ID) if err != nil { log.Error().Err(err).Msg("error getting group settings") http.Error(w, "Internal Server Error", http.StatusInternalServerError) return } h.renderer.GroupSettingsDisplay(w, r, result.Group, result.GroupMembers, result.Admins) } } func (h *Handler) GroupSettingsInviteMemberHTTPHandler() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { g := r.Context().Value(identification.GroupKey) if g == nil { http.Error(w, "Bad Request", http.StatusBadRequest) return } group := g.(storage.Group) r.ParseForm() username := r.FormValue("username") err := h.applicationHandler.InviteMemberToGroup(r.Context(), group.ID, username) if err != nil { log.Error().Err(err).Msg("error inviting member to group") http.Error(w, "Internal Server Error", http.StatusInternalServerError) return } http.Redirect(w, r, "/app/group/settings", http.StatusFound) } }