5 Commits

Author SHA1 Message Date
696cd1d87f add 'Motif' in DB 2023-02-03 10:04:19 +01:00
soukainna
372647b3b9 delete subscription and store it in the delete 2023-02-01 16:06:18 +01:00
soukainna
56c1b45f45 store eventid and subid 2023-02-01 11:51:46 +01:00
soukainna
62f64747c3 add function to store eventid and subscriberid 2023-02-01 10:47:19 +01:00
56d0914568 init 2023-02-01 10:06:32 +01:00
4 changed files with 104 additions and 1 deletions

2
go.mod
View File

@@ -8,7 +8,7 @@ go 1.18
// 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/ // replace git.coopgo.io/coopgo-platform/emailing => ../../coopgo-platform/emailing/

View File

@@ -330,6 +330,91 @@ 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"]
/////////////////////////Test ajout motif///////////////////////////////
// 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
// }
// }
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{
"unsubscribed_by": map[string]any{
"user": map[string]any{
"id": current_user_token.Subject,
"display_name": current_user_claims["display_name"],
},
"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,
}
_, 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)
}
////////////////////////////////////////////////////////
// func contains[V string](s []V, e V) bool { // func contains[V string](s []V, e V) bool {
// for _, a := range s { // for _, a := range s {
// if a == e { // if a == e {
@@ -338,3 +423,5 @@ func contains(s []*agenda.Subscription, e string) bool {
// } // }
// return false // return false
// } // }
//test

View File

@@ -137,6 +137,9 @@ func main() {
appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember) appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember)
appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles) appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles)
/////////////////////////////////////Delete subscriber///////////////////////////////////////////////
application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent)
/////////////////////////////////////////////////////////////////////////////////////////////////////
fmt.Println("-> HTTP server listening on", address) fmt.Println("-> HTTP server listening on", address)
srv := &http.Server{ srv := &http.Server{

View File

@@ -38,3 +38,16 @@ func (renderer *Renderer) AgendaDisplayEvent(w http.ResponseWriter, r *http.Requ
renderer.Render("agenda create event", w, r, files, state) renderer.Render("agenda create event", w, r, files, state)
} }
//////////////////////////DElete subscriber//////////////////////////////////
func (renderer *Renderer) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *http.Request, eventid string) {
files := renderer.ThemeConfig.GetStringSlice("views.agenda.delete_subscriber.files")
state := NewState(r, renderer.ThemeConfig, agendaMenu)
state.ViewState = map[string]any{
"eventid": eventid,
}
renderer.Render("agenda delete subscriber", w, r, files, state)
}
//////////////////////////////////////////////////////////