renderer agenda.go & handler agendo.go

This commit is contained in:
Nicolas CARON 2024-10-22 12:09:46 +02:00
parent 7184f4735c
commit 334351a0cf
2 changed files with 44 additions and 3 deletions

View File

@ -150,17 +150,52 @@ func (h *ApplicationHandler) AgendaCreateEvent(w http.ResponseWriter, r *http.Re
}
resp, err := h.services.GRPC.Agenda.CreateEvent(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
contentType := r.Header.Get("Content-Type")
if strings.HasPrefix(contentType, "multipart/form-data") {
err = r.ParseMultipartForm(100 * 1024 * 1024) // 100 MB limit
if err != nil {
fmt.Println("Error parsing multipart form:", err)
w.WriteHeader(http.StatusBadRequest)
return
}
file, header, err := r.FormFile("file-upload")
if err == nil {
defer file.Close()
document_type := r.FormValue("file_type")
document_name := r.FormValue("file_name")
fileid := uuid.NewString()
metadata := map[string]string{
"file_type": document_type,
"file_name": document_name,
}
if err := h.filestorage.Put(file, filestorage.PREFIX_AGENDA, fmt.Sprintf("%s/%s_%s", resp.Event.Id, fileid, header.Filename), header.Size, metadata); err != nil {
fmt.Println("Error uploading file:", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
} else if err != http.ErrMissingFile {
fmt.Println("Error retrieving file:", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
}
http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", resp.Event.Id), http.StatusFound)
return
}
h.Renderer.AgendaCreateEvent(w, r)
h.Renderer.AgendaCreateEvent(w, r, h.config.GetStringSlice("modules.agenda.documents_types"), h.config.GetStringMapString("storage.files.file_types"), nil)
}
func (h *ApplicationHandler) AgendaDisplayEvent(w http.ResponseWriter, r *http.Request) {

View File

@ -30,10 +30,16 @@ func (renderer *Renderer) AgendaHistory(w http.ResponseWriter, r *http.Request,
renderer.Render("agenda history", w, r, files, state)
}
func (renderer *Renderer) AgendaCreateEvent(w http.ResponseWriter, r *http.Request) {
func (renderer *Renderer) AgendaCreateEvent(w http.ResponseWriter, r *http.Request, events_file_types []string, file_types_map map[string]string, documents any) {
files := renderer.ThemeConfig.GetStringSlice("views.agenda.create_event.files")
state := NewState(r, renderer.ThemeConfig, agendaMenu)
state.ViewState = map[string]any{
"events_file_types": events_file_types,
"file_types_map": file_types_map,
"documents": documents,
}
renderer.Render("agenda create event", w, r, files, state)
}