From 372647b3b979d550560fe8ce76693a4e9cc030a6 Mon Sep 17 00:00:00 2001 From: soukainna Date: Wed, 1 Feb 2023 16:06:18 +0100 Subject: [PATCH] delete subscription and store it in the delete --- go.mod | 2 +- handlers/application/agenda.go | 43 ++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 9173408..9317ccc 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ go 1.18 // 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/ diff --git a/handlers/application/agenda.go b/handlers/application/agenda.go index ba38f1e..7fe1ddf 100644 --- a/handlers/application/agenda.go +++ b/handlers/application/agenda.go @@ -332,13 +332,46 @@ func contains(s []*agenda.Subscription, e string) bool { ///////////////////////////Delete subscriber/////////////////////////////// func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - eventid := vars["eventid"] + eventId := vars["eventid"] subscribeid := vars["subscribeid"] - fmt.Println(eventid) - fmt.Println(subscribeid) - h.Renderer.AgendaDeleteSubscribeEvent(w, r, eventid) + dd, _ := structpb.NewStruct(map[string]any{}) + 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 { + d := resp.Event.Subscriptions[i].Data + dd = d + } + } + if r.Method == "POST" { + request := &agenda.DeleteSubscriptionRequest{ + Subscriber: subscribeid, + Eventid: eventId, + Data: dd, + } + + _, err := h.services.GRPC.Agenda.DeleteSubscription(context.TODO(), request) + + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } + + http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", eventId), http.StatusFound) + return + } + h.Renderer.AgendaDeleteSubscribeEvent(w, r, eventId) } ////////////////////////////////////////////////////////