Compare commits
12 Commits
1b847ea216
...
f698891865
Author | SHA1 | Date |
---|---|---|
Nicolas CARON | f698891865 | |
Nicolas CARON | 193f5dfb6f | |
Nicolas CARON | 49de2f22c4 | |
Nicolas CARON | ab8cbf6f73 | |
Nicolas CARON | 10bde53c5e | |
Nicolas CARON | 28c8fa8a90 | |
Nicolas CARON | 11851fec61 | |
Nicolas CARON | 696cd1d87f | |
soukainna | 372647b3b9 | |
soukainna | 56c1b45f45 | |
soukainna | 62f64747c3 | |
Nicolas CARON | 56d0914568 |
2
go.mod
2
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/
|
||||
|
||||
|
|
|
@ -231,7 +231,8 @@ func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http
|
|||
"subscribed_by": map[string]any{
|
||||
"user": map[string]any{
|
||||
"id": current_user_token.Subject,
|
||||
"display_name": current_user_claims["display_name"],
|
||||
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
||||
"email": current_user_claims["email"].(string),
|
||||
},
|
||||
"group": map[string]any{
|
||||
"id": current_group.ID,
|
||||
|
@ -330,6 +331,211 @@ func contains(s []*agenda.Subscription, e string) bool {
|
|||
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,
|
||||
}
|
||||
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
// /////////////////////History Event////////////////////////
|
||||
func (h *ApplicationHandler) AgendaHistoryEvent(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
|
||||
}
|
||||
|
||||
grouprequest := &groupsmanagement.GetGroupRequest{
|
||||
Id: resp.Event.Owners[0],
|
||||
}
|
||||
|
||||
groupresp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), grouprequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
subscribers := map[string]any{}
|
||||
|
||||
accids := []string{}
|
||||
for _, v := range resp.Event.DeletedSubscription {
|
||||
accids = append(accids, v.Subscriber)
|
||||
}
|
||||
|
||||
subscriberresp, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(
|
||||
context.TODO(),
|
||||
&mobilityaccounts.GetAccountsBatchRequest{
|
||||
Accountids: accids,
|
||||
},
|
||||
)
|
||||
|
||||
if err == nil {
|
||||
for _, sub := range subscriberresp.Accounts {
|
||||
subscribers[sub.Id] = sub.ToStorageType()
|
||||
}
|
||||
}
|
||||
|
||||
g := r.Context().Value(identification.GroupKey)
|
||||
if g == nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
group := g.(storage.Group)
|
||||
|
||||
accountids := []string{}
|
||||
for _, m := range group.Members {
|
||||
if !contains(resp.Event.DeletedSubscription, m) {
|
||||
accountids = append(accountids, m)
|
||||
}
|
||||
}
|
||||
|
||||
accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(
|
||||
context.TODO(),
|
||||
&mobilityaccounts.GetAccountsBatchRequest{
|
||||
Accountids: accountids,
|
||||
},
|
||||
)
|
||||
|
||||
accounts := []any{}
|
||||
|
||||
if err == nil {
|
||||
for _, acc := range accountresp.Accounts {
|
||||
accounts = append(accounts, acc)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
h.Renderer.AgendaHistoryEvent(w, r, resp.Event.ToStorageType(), groupresp.Group.ToStorageType(), subscribers, accounts)
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
// func contains[V string](s []V, e V) bool {
|
||||
// for _, a := range s {
|
||||
// if a == e {
|
||||
|
@ -338,3 +544,5 @@ func contains(s []*agenda.Subscription, e string) bool {
|
|||
// }
|
||||
// return false
|
||||
// }
|
||||
|
||||
//test
|
||||
|
|
4
main.go
4
main.go
|
@ -137,6 +137,10 @@ func main() {
|
|||
appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember)
|
||||
appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles)
|
||||
|
||||
/////////////////////////////////////Delete subscriber///////////////////////////////////////////////
|
||||
application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent)
|
||||
application.HandleFunc("/agenda/{eventid}/history", applicationHandler.AgendaHistoryEvent)
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
fmt.Println("-> HTTP server listening on", address)
|
||||
|
||||
srv := &http.Server{
|
||||
|
|
|
@ -38,3 +38,31 @@ func (renderer *Renderer) AgendaDisplayEvent(w http.ResponseWriter, r *http.Requ
|
|||
|
||||
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)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////History Event//////////////////////////////////
|
||||
func (renderer *Renderer) AgendaHistoryEvent(w http.ResponseWriter, r *http.Request, event any, group any, subscribers map[string]any, beneficiaries any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.agenda.history_event.files")
|
||||
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"event": event,
|
||||
"group": group,
|
||||
"subscribers": subscribers,
|
||||
"beneficiaries": beneficiaries,
|
||||
}
|
||||
|
||||
renderer.Render("agenda history event", w, r, files, state)
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////
|
Loading…
Reference in New Issue