Compare commits
4 Commits
498b12de18
...
b4c59c7408
Author | SHA1 | Date |
---|---|---|
Nicolas CARON | b4c59c7408 | |
Nicolas CARON | 334351a0cf | |
Nicolas CARON | 7184f4735c | |
Nicolas CARON | 434be30074 |
8
go.mod
8
go.mod
|
@ -2,13 +2,13 @@ module git.coopgo.io/coopgo-apps/parcoursmob
|
|||
|
||||
go 1.18
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/mobility-accounts => ../../coopgo-platform/mobility-accounts/
|
||||
replace git.coopgo.io/coopgo-platform/mobility-accounts => ../../coopgo-platform/mobility-accounts/
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/groups-management => ../../coopgo-platform/groups-management/
|
||||
replace git.coopgo.io/coopgo-platform/groups-management => ../../coopgo-platform/groups-management/
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/fleets => ../../coopgo-platform/fleets/
|
||||
replace git.coopgo.io/coopgo-platform/fleets => ../../coopgo-platform/fleets/
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/agenda => ../../coopgo-platform/agenda/
|
||||
replace git.coopgo.io/coopgo-platform/agenda => ../../coopgo-platform/agenda/
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/emailing => ../../coopgo-platform/emailing/
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -13,11 +14,13 @@ import (
|
|||
formvalidators "git.coopgo.io/coopgo-apps/parcoursmob/utils/form-validators"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
|
||||
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
||||
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
"github.com/google/uuid"
|
||||
"github.com/gorilla/mux"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
@ -147,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) {
|
||||
|
@ -237,7 +275,13 @@ func (h *ApplicationHandler) AgendaDisplayEvent(w http.ResponseWriter, r *http.R
|
|||
}
|
||||
}
|
||||
|
||||
h.Renderer.AgendaDisplayEvent(w, r, resp.Event.ToStorageType(), groupresp.Group.ToStorageType(), subscribers, accounts)
|
||||
|
||||
documents := h.filestorage.List(filestorage.PREFIX_AGENDA + "/" + eventid)
|
||||
|
||||
events_file_types := h.config.GetStringSlice("modules.agenda.documents_types")
|
||||
file_types_map := h.config.GetStringMapString("storage.files.file_types")
|
||||
|
||||
h.Renderer.AgendaDisplayEvent(w, r, resp.Event.ToStorageType(), groupresp.Group.ToStorageType(), events_file_types, file_types_map, documents, subscribers, accounts)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -685,3 +729,61 @@ func (h *ApplicationHandler) AgendaHistoryEvent(w http.ResponseWriter, r *http.R
|
|||
|
||||
h.Renderer.AgendaHistoryEvent(w, r, resp.Event.ToStorageType(), groupresp.Group.ToStorageType(), subscribers, accounts)
|
||||
}
|
||||
////// ADD DOCUMENTS //////
|
||||
func (h *ApplicationHandler) EventDocuments(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
eventID := vars["eventid"]
|
||||
|
||||
//r.ParseForm()
|
||||
r.ParseMultipartForm(100 * 1024 * 1024)
|
||||
|
||||
document_type := r.FormValue("type")
|
||||
document_name := r.FormValue("name")
|
||||
|
||||
file, header, err := r.FormFile("file-upload")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
fileid := uuid.NewString()
|
||||
|
||||
metadata := map[string]string{
|
||||
"type": document_type,
|
||||
"name": document_name,
|
||||
}
|
||||
|
||||
if err := h.filestorage.Put(file, filestorage.PREFIX_AGENDA, fmt.Sprintf("%s/%s_%s", eventID, fileid, header.Filename), header.Size, metadata); err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", eventID), http.StatusFound)
|
||||
|
||||
}
|
||||
|
||||
|
||||
func (h *ApplicationHandler) EventDocumentDownload(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
eventID := vars["eventid"]
|
||||
document := vars["document"]
|
||||
|
||||
file, info, err := h.filestorage.Get(filestorage.PREFIX_AGENDA, fmt.Sprintf("%s/%s", eventID, document))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", info.ContentType)
|
||||
if _, err = io.Copy(w, file); err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", eventID), http.StatusFound)
|
||||
|
||||
}
|
|
@ -446,6 +446,8 @@ func (h *ApplicationHandler) BeneficiaryDocuments(w http.ResponseWriter, r *http
|
|||
"name": document_name,
|
||||
}
|
||||
|
||||
fmt.Println("metadata", metadata)
|
||||
|
||||
if err := h.filestorage.Put(file, filestorage.PREFIX_BENEFICIARIES, fmt.Sprintf("%s/%s_%s", beneficiaryID, fileid, header.Filename), header.Size, metadata); err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
|
3
main.go
3
main.go
|
@ -162,6 +162,9 @@ func main() {
|
|||
application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent)
|
||||
application.HandleFunc("/agenda/{eventid}/history", applicationHandler.AgendaHistoryEvent)
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////Add documents in event////////////////////////
|
||||
application.HandleFunc("/agenda/{eventid}/documents", applicationHandler.EventDocuments)
|
||||
application.HandleFunc("/agenda/{eventid}/documents/{document}", applicationHandler.EventDocumentDownload)
|
||||
|
||||
export := r.PathPrefix("/exports").Subrouter()
|
||||
export.HandleFunc("/fleets/bookings", exportsHandler.Bookings)
|
||||
|
|
|
@ -30,22 +30,31 @@ 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)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) AgendaDisplayEvent(w http.ResponseWriter, r *http.Request, event any, group any, subscribers map[string]any, beneficiaries any) {
|
||||
func (renderer *Renderer) AgendaDisplayEvent(w http.ResponseWriter, r *http.Request, event any, group any, events_file_types []string, file_types_map map[string]string, documents any, subscribers map[string]any, beneficiaries any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.agenda.display_event.files")
|
||||
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||
|
||||
state.ViewState = map[string]any{
|
||||
"event": event,
|
||||
"group": group,
|
||||
"subscribers": subscribers,
|
||||
"beneficiaries": beneficiaries,
|
||||
"event": event,
|
||||
"group": group,
|
||||
"events_file_types": events_file_types,
|
||||
"file_types_map": file_types_map,
|
||||
"documents": documents,
|
||||
"subscribers": subscribers,
|
||||
"beneficiaries": beneficiaries,
|
||||
}
|
||||
|
||||
renderer.Render("agenda create event", w, r, files, state)
|
||||
|
@ -100,3 +109,18 @@ func (renderer *Renderer) AgendaDeleteEvent(w http.ResponseWriter, r *http.Reque
|
|||
|
||||
renderer.Render("event_deleteEvent", w, r, files, state)
|
||||
}
|
||||
|
||||
////////Event documents////////////////////////
|
||||
// func (renderer *Renderer) EventDocuments(w http.ResponseWriter, r *http.Request, event any, documents []any) {
|
||||
// files := renderer.ThemeConfig.GetStringSlice("views.agenda.event_files.files")
|
||||
// state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||
|
||||
// state.ViewState = map[string]any{
|
||||
// "event": event,
|
||||
// "documents": documents,
|
||||
// "eventid": event.(map[string]any)["id"],
|
||||
// "eventtitle": event.(map[string]any)["title"],
|
||||
// }
|
||||
|
||||
// renderer.Render("event_files", w, r, files, state)
|
||||
// }
|
|
@ -10,6 +10,7 @@ import (
|
|||
const (
|
||||
PREFIX_BENEFICIARIES = "beneficiaries"
|
||||
PREFIX_BOOKINGS = "fleets_bookings"
|
||||
PREFIX_AGENDA = "event_files"
|
||||
)
|
||||
|
||||
type FileInfo struct {
|
||||
|
|
Loading…
Reference in New Issue