Compare commits

...

2 Commits

Author SHA1 Message Date
Nicolas CARON 28c8fa8a90 add 'suscribed_by' in Data on DB 2023-02-03 15:23:49 +01:00
Nicolas CARON 11851fec61 add 'suscribed_by' in Data on DB 2023-02-03 15:23:37 +01:00
1 changed files with 38 additions and 21 deletions

View File

@ -330,31 +330,39 @@ func contains(s []*agenda.Subscription, e string) bool {
return false return false
} }
// /////////////////////////Delete subscriber/////////////////////////////// ///////////////////////////Delete subscriber///////////////////////////////
func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
eventId := vars["eventid"] eventId := vars["eventid"]
subscribeid := vars["subscribeid"] subscribeid := vars["subscribeid"]
s_b_id := ""
s_b_name := ""
s_b_group_id := ""
s_b_group_name := ""
request := &agenda.GetEventRequest{
Id: eventId,
}
/////////////////////////Test ajout motif/////////////////////////////// resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
// dd, _ := structpb.NewStruct(map[string]any{}) if err != nil {
// request := &agenda.GetEventRequest{ fmt.Println(err)
// Id: eventId, w.WriteHeader(http.StatusInternalServerError)
// } return
}
// resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request) for i := range resp.Event.Subscriptions {
// if err != nil { if resp.Event.Subscriptions[i].Subscriber == subscribeid {
// fmt.Println(err) subscribed_by_id := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["id"].GetStringValue()
// w.WriteHeader(http.StatusInternalServerError) subscribed_by_name := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["display_name"].GetStringValue()
// return 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
// for i := range resp.Event.Subscriptions { s_b_name = subscribed_by_name
// if resp.Event.Subscriptions[i].Subscriber == subscribeid { s_b_group_id = subscribed_by_group_id
// d := resp.Event.Subscriptions[i].Data s_b_group_name = subscribed_by_group_name
// dd = d }
// } }
// }
current_group, err := h.currentGroup(r) current_group, err := h.currentGroup(r)
if err != nil { if err != nil {
@ -371,6 +379,16 @@ func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r
} }
data := map[string]any{ data := map[string]any{
"subscribed_by": map[string]any{
"user": map[string]any{
"id": s_b_id,
"display_name": s_b_name,
},
"group": map[string]any{
"id": s_b_group_id,
"name": s_b_group_name,
},
},
"unsubscribed_by": map[string]any{ "unsubscribed_by": map[string]any{
"user": map[string]any{ "user": map[string]any{
"id": current_user_token.Subject, "id": current_user_token.Subject,
@ -383,6 +401,7 @@ func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r
}, },
"motif": r.FormValue("motif"), "motif": r.FormValue("motif"),
} }
datapb, err := structpb.NewStruct(data) datapb, err := structpb.NewStruct(data)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -397,8 +416,6 @@ func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r
Data: datapb, Data: datapb,
} }
_, err := h.services.GRPC.Agenda.DeleteSubscription(context.TODO(), request) _, err := h.services.GRPC.Agenda.DeleteSubscription(context.TODO(), request)
if err != nil { if err != nil {