53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
|
package application
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
|
||
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||
|
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||
|
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||
|
)
|
||
|
|
||
|
func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
|
||
|
|
||
|
g := r.Context().Value(identification.GroupKey)
|
||
|
if g == nil {
|
||
|
w.WriteHeader(http.StatusBadRequest)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
group := g.(storage.Group)
|
||
|
|
||
|
request := &mobilityaccounts.GetAccountsBatchRequest{
|
||
|
Accountids: group.Members,
|
||
|
}
|
||
|
|
||
|
resp, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), request)
|
||
|
if err != nil {
|
||
|
fmt.Println(err)
|
||
|
w.WriteHeader(http.StatusInternalServerError)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
var accounts = []any{}
|
||
|
|
||
|
// We only display the 10 last here
|
||
|
count := len(resp.Accounts)
|
||
|
min := count - 10
|
||
|
if min < 0 {
|
||
|
min = 0
|
||
|
}
|
||
|
|
||
|
for _, account := range resp.Accounts[min:] {
|
||
|
if filterAccount(r, account) {
|
||
|
a := account.ToStorageType()
|
||
|
accounts = append([]any{a}, accounts...)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
h.Renderer.Dashboard(w, r, accounts, count)
|
||
|
|
||
|
}
|