Merge branch 'modifyAnEvent' into dev

This commit is contained in:
soukainna 2023-02-22 12:47:29 +01:00
commit 335656ec75
5 changed files with 135 additions and 9 deletions

View File

@ -7,6 +7,7 @@ import (
"net/http"
"sort"
"strconv"
"strings"
"time"
formvalidators "git.coopgo.io/coopgo-apps/parcoursmob/utils/form-validators"
@ -107,6 +108,7 @@ func (h *ApplicationHandler) AgendaCreateEvent(w http.ResponseWriter, r *http.Re
Allday: eventForm.Allday,
MaxSubscribers: int64(eventForm.MaxSubscribers),
Data: data,
Deleted: false,
},
}
@ -119,7 +121,7 @@ func (h *ApplicationHandler) AgendaCreateEvent(w http.ResponseWriter, r *http.Re
}
http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", resp.Event.Id), http.StatusFound)
return
}
h.Renderer.AgendaCreateEvent(w, r)
}
@ -225,7 +227,7 @@ func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http
w.WriteHeader(http.StatusBadRequest)
return
}
dis := fmt.Sprint(current_user_claims["first_name"]) + " " + fmt.Sprint(current_user_claims["last_name"])
subscriber := r.FormValue("subscriber")
data := map[string]any{
"subscribed_by": map[string]any{
@ -344,6 +346,12 @@ func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r
s_b_group_name := ""
request := &agenda.GetEventRequest{
Id: eventId,
///////////////////////////////Update Event/////////////////////////////////////////
func (h *ApplicationHandler) AgendaUpdateEvent(w http.ResponseWriter, r *http.Request) {
adm := strings.Split(r.URL.Path, "/")
eventID := adm[3]
request := &agenda.GetEventRequest{
Id: eventID,
}
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
@ -432,6 +440,46 @@ func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r
fmt.Println(mail)
_, err := h.services.GRPC.Agenda.DeleteSubscription(context.TODO(), request)
if r.Method == "POST" {
g := r.Context().Value(identification.GroupKey)
if g == nil {
w.WriteHeader(http.StatusBadRequest)
return
}
group := g.(storage.Group)
eventForm, err := parseEventsForm(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
data, _ := structpb.NewStruct(map[string]any{
"address": eventForm.Address,
})
request := &agenda.UpdateEventRequest{
Event: &agenda.Event{
Namespace: "parcoursmob_dispositifs",
Id: eventID,
Owners: []string{group.ID},
Type: eventForm.Type,
Name: eventForm.Name,
Description: eventForm.Description,
Startdate: timestamppb.New(*eventForm.Startdate),
Enddate: timestamppb.New(*eventForm.Enddate),
Starttime: eventForm.Starttime,
Endtime: eventForm.Endtime,
Allday: eventForm.Allday,
MaxSubscribers: int64(eventForm.MaxSubscribers),
Data: data,
Subscriptions: resp.Event.Subscriptions,
},
}
resp, err := h.services.GRPC.Agenda.UpdateEvent(context.TODO(), request)
if err != nil {
fmt.Println(err)
@ -459,6 +507,18 @@ func (h *ApplicationHandler) AgendaHistoryEvent(w http.ResponseWriter, r *http.R
eventId := vars["eventid"]
request := &agenda.GetEventRequest{
Id: eventId,
http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", resp.Event.Id), http.StatusFound)
return
}
h.Renderer.AgendaUpdateEvent(w, r, resp.Event.ToStorageType())
}
func (h *ApplicationHandler) AgendaDeleteEvent(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
eventID := vars["eventid"]
request := &agenda.GetEventRequest{
Id: eventID,
}
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
@ -536,6 +596,42 @@ func (h *ApplicationHandler) AgendaHistoryEvent(w http.ResponseWriter, r *http.R
/////////////////////////////////////////////////////////
if r.Method == "POST" {
request := &agenda.UpdateEventRequest{
Event: &agenda.Event{
Namespace: resp.Event.Namespace,
Id: resp.Event.Id,
Owners: resp.Event.Owners,
Type: resp.Event.Type,
Name: resp.Event.Name,
Description: resp.Event.Description,
Startdate: resp.Event.Startdate,
Enddate: resp.Event.Enddate,
Starttime: resp.Event.Starttime,
Endtime: resp.Event.Endtime,
Allday: resp.Event.Allday,
MaxSubscribers: int64(resp.Event.MaxSubscribers),
Data: resp.Event.Data,
Subscriptions: resp.Event.Subscriptions,
Deleted: true,
},
}
_, err := h.services.GRPC.Agenda.UpdateEvent(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/app/agenda/", http.StatusFound)
return
}
h.Renderer.AgendaDeleteEvent(w, r, resp.Event.ToStorageType())
}
// func contains[V string](s []V, e V) bool {
// for _, a := range s {
// if a == e {

View File

@ -76,7 +76,7 @@ func (h *ApplicationHandler) MemberUpdate(w http.ResponseWriter, r *http.Request
return
}
http.Redirect(w, r, fmt.Sprintf("/app/profile/%s", resp.Account.Id), http.StatusFound)
http.Redirect(w, r, fmt.Sprintf("/app/members/%s", resp.Account.Id), http.StatusFound)
return
}

View File

@ -37,7 +37,7 @@ func (h *AuthHandler) Onboarding(w http.ResponseWriter, r *http.Request) {
if onboardingmap["admin"].(bool) {
groups = append(groups, onboardingmap["group"].(string)+":admin")
}
display_name := fmt.Sprint(r.FormValue("first_name")) + " " + fmt.Sprint(r.FormValue("last_name"))
account := &ma.Account{
Authentication: ma.AccountAuth{
Local: ma.LocalAuth{
@ -46,11 +46,13 @@ func (h *AuthHandler) Onboarding(w http.ResponseWriter, r *http.Request) {
},
},
Namespace: "parcoursmob",
Data: map[string]any{
"first_name": r.FormValue("first_name"),
"last_name": r.FormValue("last_name"),
"email": onboardingmap["username"],
"groups": groups,
"display_name": display_name,
"first_name": r.FormValue("first_name"),
"last_name": r.FormValue("last_name"),
"email": onboardingmap["username"],
"groups": groups,
},
}

View File

@ -104,6 +104,11 @@ func main() {
application.HandleFunc("/agenda/", applicationHandler.AgendaHome)
application.HandleFunc("/agenda/create-event", applicationHandler.AgendaCreateEvent)
application.HandleFunc("/agenda/{eventid}", applicationHandler.AgendaDisplayEvent)
///////////////////////////////Code to modify event///////////////////////
application.HandleFunc("/agenda/{eventid}/update", applicationHandler.AgendaUpdateEvent)
application.HandleFunc("/agenda/{eventid}/delete", applicationHandler.AgendaDeleteEvent)
/////////////////////////////////////////////////////
application.HandleFunc("/agenda/{eventid}/subscribe", applicationHandler.AgendaSubscribeEvent)
application.HandleFunc("/directory/", applicationHandler.DirectoryHome)

View File

@ -29,6 +29,7 @@ func (renderer *Renderer) AgendaCreateEvent(w http.ResponseWriter, r *http.Reque
func (renderer *Renderer) AgendaDisplayEvent(w http.ResponseWriter, r *http.Request, event any, group 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,
@ -65,4 +66,26 @@ func (renderer *Renderer) AgendaHistoryEvent(w http.ResponseWriter, r *http.Requ
renderer.Render("agenda history event", w, r, files, state)
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
func (renderer *Renderer) AgendaUpdateEvent(w http.ResponseWriter, r *http.Request, event any) {
files := renderer.ThemeConfig.GetStringSlice("views.agenda.update.files")
state := NewState(r, renderer.ThemeConfig, agendaMenu)
state.ViewState = map[string]any{
"event": event,
}
renderer.Render("event_update", w, r, files, state)
}
func (renderer *Renderer) AgendaDeleteEvent(w http.ResponseWriter, r *http.Request, event any) {
files := renderer.ThemeConfig.GetStringSlice("views.agenda.delete.files")
state := NewState(r, renderer.ThemeConfig, agendaMenu)
state.ViewState = map[string]any{
"event": event,
}
renderer.Render("event_deleteEvent", w, r, files, state)
}