fix agenda file to compile
This commit is contained in:
parent
3bfce72512
commit
e11514b6d5
|
@ -227,14 +227,13 @@ func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dis := fmt.Sprint(current_user_claims["first_name"]) + " " + fmt.Sprint(current_user_claims["last_name"])
|
|
||||||
subscriber := r.FormValue("subscriber")
|
subscriber := r.FormValue("subscriber")
|
||||||
data := map[string]any{
|
data := map[string]any{
|
||||||
"subscribed_by": map[string]any{
|
"subscribed_by": map[string]any{
|
||||||
"user": map[string]any{
|
"user": map[string]any{
|
||||||
"id": current_user_token.Subject,
|
"id": current_user_token.Subject,
|
||||||
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
||||||
"email": current_user_claims["email"].(string),
|
"email": current_user_claims["email"].(string),
|
||||||
},
|
},
|
||||||
"group": map[string]any{
|
"group": map[string]any{
|
||||||
"id": current_group.ID,
|
"id": current_group.ID,
|
||||||
|
@ -333,19 +332,6 @@ func contains(s []*agenda.Subscription, e string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////Delete subscriber///////////////////////////////
|
|
||||||
|
|
||||||
func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *http.Request) {
|
|
||||||
vars := mux.Vars(r)
|
|
||||||
eventId := vars["eventid"]
|
|
||||||
subscribeid := vars["subscribeid"]
|
|
||||||
s_b_id := ""
|
|
||||||
s_b_name := ""
|
|
||||||
s_b_email := ""
|
|
||||||
s_b_group_id := ""
|
|
||||||
s_b_group_name := ""
|
|
||||||
request := &agenda.GetEventRequest{
|
|
||||||
Id: eventId,
|
|
||||||
///////////////////////////////Update Event/////////////////////////////////////////
|
///////////////////////////////Update Event/////////////////////////////////////////
|
||||||
func (h *ApplicationHandler) AgendaUpdateEvent(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) AgendaUpdateEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
adm := strings.Split(r.URL.Path, "/")
|
adm := strings.Split(r.URL.Path, "/")
|
||||||
|
@ -360,86 +346,6 @@ func (h *ApplicationHandler) AgendaUpdateEvent(w http.ResponseWriter, r *http.Re
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range resp.Event.Subscriptions {
|
|
||||||
if resp.Event.Subscriptions[i].Subscriber == subscribeid {
|
|
||||||
subscribed_by_id := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["id"].GetStringValue()
|
|
||||||
subscribed_by_name := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["display_name"].GetStringValue()
|
|
||||||
subscribed_by_email := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["email"].GetStringValue()
|
|
||||||
subscribed_by_group_id := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["group"].GetStructValue().Fields["id"].GetStringValue()
|
|
||||||
subscribed_by_group_name := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["group"].GetStructValue().Fields["name"].GetStringValue()
|
|
||||||
s_b_id = subscribed_by_id
|
|
||||||
s_b_name = subscribed_by_name
|
|
||||||
s_b_email = subscribed_by_email
|
|
||||||
s_b_group_id = subscribed_by_group_id
|
|
||||||
s_b_group_name = subscribed_by_group_name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
current_group, err := h.currentGroup(r)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
current_user_token, current_user_claims, err := h.currentUser(r)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data := map[string]any{
|
|
||||||
"subscribed_by": map[string]any{
|
|
||||||
"user": map[string]any{
|
|
||||||
"id": s_b_id,
|
|
||||||
"display_name": s_b_name,
|
|
||||||
"email": s_b_email,
|
|
||||||
},
|
|
||||||
"group": map[string]any{
|
|
||||||
"id": s_b_group_id,
|
|
||||||
"name": s_b_group_name,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"unsubscribed_by": map[string]any{
|
|
||||||
"user": map[string]any{
|
|
||||||
"id": current_user_token.Subject,
|
|
||||||
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
|
||||||
"email": current_user_claims["email"],
|
|
||||||
},
|
|
||||||
"group": map[string]any{
|
|
||||||
"id": current_group.ID,
|
|
||||||
"name": current_group.Data["name"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"motif": r.FormValue("motif"),
|
|
||||||
}
|
|
||||||
|
|
||||||
datapb, err := structpb.NewStruct(data)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.Method == "POST" {
|
|
||||||
request := &agenda.DeleteSubscriptionRequest{
|
|
||||||
Subscriber: subscribeid,
|
|
||||||
Eventid: eventId,
|
|
||||||
Data: datapb,
|
|
||||||
}
|
|
||||||
|
|
||||||
data := map[string]any{
|
|
||||||
"key": r.FormValue("motif"),
|
|
||||||
"user": current_user_claims["email"],
|
|
||||||
}
|
|
||||||
|
|
||||||
// récupérer l'adresse mail de l'utilisateur qui a créé l'événement
|
|
||||||
mail := s_b_email;
|
|
||||||
fmt.Println(mail)
|
|
||||||
|
|
||||||
_, err := h.services.GRPC.Agenda.DeleteSubscription(context.TODO(), request)
|
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
g := r.Context().Value(identification.GroupKey)
|
g := r.Context().Value(identification.GroupKey)
|
||||||
if g == nil {
|
if g == nil {
|
||||||
|
@ -487,6 +393,170 @@ func (h *ApplicationHandler) AgendaUpdateEvent(w http.ResponseWriter, r *http.Re
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////Delete subscriber///////////////////////////////
|
||||||
|
func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
eventId := vars["eventid"]
|
||||||
|
subscribeid := vars["subscribeid"]
|
||||||
|
s_b_id := ""
|
||||||
|
s_b_name := ""
|
||||||
|
s_b_email := ""
|
||||||
|
s_b_group_id := ""
|
||||||
|
s_b_group_name := ""
|
||||||
|
request := &agenda.GetEventRequest{
|
||||||
|
Id: eventId,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range resp.Event.Subscriptions {
|
||||||
|
if resp.Event.Subscriptions[i].Subscriber == subscribeid {
|
||||||
|
subscribed_by_id := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["id"].GetStringValue()
|
||||||
|
subscribed_by_name := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["display_name"].GetStringValue()
|
||||||
|
subscribed_by_email := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["email"].GetStringValue()
|
||||||
|
subscribed_by_group_id := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["group"].GetStructValue().Fields["id"].GetStringValue()
|
||||||
|
subscribed_by_group_name := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["group"].GetStructValue().Fields["name"].GetStringValue()
|
||||||
|
s_b_id = subscribed_by_id
|
||||||
|
s_b_name = subscribed_by_name
|
||||||
|
s_b_email = subscribed_by_email
|
||||||
|
s_b_group_id = subscribed_by_group_id
|
||||||
|
s_b_group_name = subscribed_by_group_name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
current_group, err := h.currentGroup(r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
current_user_token, current_user_claims, err := h.currentUser(r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := map[string]any{
|
||||||
|
"subscribed_by": map[string]any{
|
||||||
|
"user": map[string]any{
|
||||||
|
"id": s_b_id,
|
||||||
|
"display_name": s_b_name,
|
||||||
|
"email": s_b_email,
|
||||||
|
},
|
||||||
|
"group": map[string]any{
|
||||||
|
"id": s_b_group_id,
|
||||||
|
"name": s_b_group_name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"unsubscribed_by": map[string]any{
|
||||||
|
"user": map[string]any{
|
||||||
|
"id": current_user_token.Subject,
|
||||||
|
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
||||||
|
"email": current_user_claims["email"],
|
||||||
|
},
|
||||||
|
"group": map[string]any{
|
||||||
|
"id": current_group.ID,
|
||||||
|
"name": current_group.Data["name"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"motif": r.FormValue("motif"),
|
||||||
|
}
|
||||||
|
|
||||||
|
datapb, err := structpb.NewStruct(data)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Method == "POST" {
|
||||||
|
request := &agenda.DeleteSubscriptionRequest{
|
||||||
|
Subscriber: subscribeid,
|
||||||
|
Eventid: eventId,
|
||||||
|
Data: datapb,
|
||||||
|
}
|
||||||
|
|
||||||
|
data := map[string]any{
|
||||||
|
"key": r.FormValue("motif"),
|
||||||
|
"user": current_user_claims["email"],
|
||||||
|
}
|
||||||
|
|
||||||
|
// récupérer l'adresse mail de l'utilisateur qui a créé l'événement
|
||||||
|
mail := s_b_email
|
||||||
|
fmt.Println(mail)
|
||||||
|
|
||||||
|
_, err := h.services.GRPC.Agenda.DeleteSubscription(context.TODO(), request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err := h.emailing.Send("delete_subscriber.request", mail, data); err != nil {
|
if err := h.emailing.Send("delete_subscriber.request", mail, data); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
@ -500,25 +570,12 @@ func (h *ApplicationHandler) AgendaUpdateEvent(w http.ResponseWriter, r *http.Re
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// /////////////////////History Event////////////////////////
|
// /////////////////////History Event////////////////////////
|
||||||
func (h *ApplicationHandler) AgendaHistoryEvent(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) AgendaHistoryEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
eventId := vars["eventid"]
|
eventId := vars["eventid"]
|
||||||
request := &agenda.GetEventRequest{
|
request := &agenda.GetEventRequest{
|
||||||
Id: eventId,
|
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)
|
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
|
||||||
|
@ -590,55 +647,5 @@ func (h *ApplicationHandler) AgendaDeleteEvent(w http.ResponseWriter, r *http.Re
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
h.Renderer.AgendaHistoryEvent(w, r, resp.Event.ToStorageType(), groupresp.Group.ToStorageType(), subscribers, accounts)
|
h.Renderer.AgendaHistoryEvent(w, r, resp.Event.ToStorageType(), groupresp.Group.ToStorageType(), subscribers, accounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
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 {
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
|
|
||||||
//test
|
|
||||||
|
|
Loading…
Reference in New Issue