add 'History' page
This commit is contained in:
parent
28c8fa8a90
commit
10bde53c5e
|
@ -432,6 +432,89 @@ func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////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.Subscriptions {
|
||||||
|
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.Subscriptions, 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 {
|
// func contains[V string](s []V, e V) bool {
|
||||||
// for _, a := range s {
|
// for _, a := range s {
|
||||||
// if a == e {
|
// if a == e {
|
||||||
|
|
1
main.go
1
main.go
|
@ -139,6 +139,7 @@ func main() {
|
||||||
|
|
||||||
/////////////////////////////////////Delete subscriber///////////////////////////////////////////////
|
/////////////////////////////////////Delete subscriber///////////////////////////////////////////////
|
||||||
application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent)
|
application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent)
|
||||||
|
application.HandleFunc("/agenda/{eventid}/history", applicationHandler.AgendaHistoryEvent)
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
fmt.Println("-> HTTP server listening on", address)
|
fmt.Println("-> HTTP server listening on", address)
|
||||||
|
|
||||||
|
|
|
@ -51,3 +51,18 @@ func (renderer *Renderer) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *h
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//////////////////////////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