handlers/administration goroutines
This commit is contained in:
parent
c34d08ff70
commit
b54961b619
|
@ -8,6 +8,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||||
|
@ -27,79 +28,83 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var (
|
||||||
accounts, err := h.services.GetAccounts()
|
wg sync.WaitGroup
|
||||||
if err != nil {
|
accounts, beneficiaries []mobilityaccountsstorage.Account
|
||||||
fmt.Println(err)
|
bookings []fleetsstorage.Booking
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
accountsErr, beneficiariesErr, bookingsErr, groupsResponseErr, eventsResponseErr, groupsBatchErr error
|
||||||
return
|
groups = []groupstorage.Group{}
|
||||||
}
|
responses = []agendastorage.Event{}
|
||||||
|
groupsResponse *groupsmanagement.GetGroupsResponse
|
||||||
beneficiaries, err := h.services.GetBeneficiaries()
|
eventsResponse *agenda.GetEventsResponse
|
||||||
if err != nil {
|
groupids = []string{}
|
||||||
fmt.Println(err)
|
groupsBatchResponse *groupsmanagement.GetGroupsBatchResponse
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
)
|
||||||
return
|
// Retrieve accounts in a goroutine
|
||||||
}
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
bookings, err := h.services.GetBookings()
|
defer wg.Done()
|
||||||
if err != nil {
|
accounts, accountsErr = h.services.GetAccounts()
|
||||||
fmt.Println(err)
|
}()
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
// Retrieve beneficiaries in a goroutine
|
||||||
return
|
wg.Add(1)
|
||||||
}
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
request := &groupsmanagement.GetGroupsRequest{
|
beneficiaries, beneficiariesErr = h.services.GetBeneficiaries()
|
||||||
Namespaces: []string{"parcoursmob_organizations"},
|
}()
|
||||||
}
|
// Retrieve bookings in a goroutine
|
||||||
|
wg.Add(1)
|
||||||
resp, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), request)
|
go func() {
|
||||||
if err != nil {
|
defer wg.Done()
|
||||||
fmt.Println(err)
|
bookings, bookingsErr = h.services.GetBookings()
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
}()
|
||||||
return
|
// Retrieve groupsRequest in a goroutine
|
||||||
}
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
var groups = []groupstorage.Group{}
|
defer wg.Done()
|
||||||
|
request := &groupsmanagement.GetGroupsRequest{
|
||||||
for _, group := range resp.Groups {
|
Namespaces: []string{"parcoursmob_organizations"},
|
||||||
g := group.ToStorageType()
|
|
||||||
groups = append(groups, g)
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Sort(sorting.GroupsByName(groups))
|
|
||||||
////////////////////////////////////add event////////////////////////////////////////////
|
|
||||||
rresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
|
||||||
Namespaces: []string{"parcoursmob_dispositifs"},
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
responses := []agendastorage.Event{}
|
|
||||||
|
|
||||||
groupids := []string{}
|
|
||||||
for _, e := range rresp.Events {
|
|
||||||
groupids = append(groupids, e.Owners...)
|
|
||||||
responses = append(responses, e.ToStorageType())
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Sort(sorting.EventsByStartdate(responses))
|
|
||||||
|
|
||||||
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
|
||||||
Groupids: groupids,
|
|
||||||
})
|
|
||||||
groupps := map[string]any{}
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
for _, g := range groupsresp.Groups {
|
|
||||||
groupps[g.Id] = g.ToStorageType()
|
|
||||||
}
|
}
|
||||||
|
groupsResponse, groupsResponseErr = h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), request)
|
||||||
|
for _, group := range groupsResponse.Groups {
|
||||||
|
g := group.ToStorageType()
|
||||||
|
groups = append(groups, g)
|
||||||
|
}
|
||||||
|
sort.Sort(sorting.GroupsByName(groups))
|
||||||
|
}()
|
||||||
|
// Retrieve Events in a goroutine
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
eventsResponse, eventsResponseErr = h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||||
|
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||||
|
})
|
||||||
|
for _, e := range eventsResponse.Events {
|
||||||
|
groupids = append(groupids, e.Owners...)
|
||||||
|
responses = append(responses, e.ToStorageType())
|
||||||
|
}
|
||||||
|
sort.Sort(sorting.EventsByStartdate(responses))
|
||||||
|
}()
|
||||||
|
wg.Add(1)
|
||||||
|
// Retrieve groupsBatch in a goroutine
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
groupsBatchResponse, groupsBatchErr = h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||||
|
Groupids: groupids,
|
||||||
|
})
|
||||||
|
groupps := map[string]any{}
|
||||||
|
if groupsBatchErr == nil {
|
||||||
|
for _, g := range groupsBatchResponse.Groups {
|
||||||
|
groupps[g.Id] = g.ToStorageType()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
wg.Wait()
|
||||||
|
if accountsErr != nil || beneficiariesErr != nil || bookingsErr != nil || groupsResponseErr != nil || eventsResponseErr != nil {
|
||||||
|
fmt.Println(accountsErr, beneficiariesErr, bookingsErr, groupsResponseErr, eventsResponseErr, groupsBatchErr)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Renderer.Administration(w, r, accounts, beneficiaries, groups, bookings, responses)
|
h.Renderer.Administration(w, r, accounts, beneficiaries, groups, bookings, responses)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Request) {
|
func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Request) {
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
|
fmt.Println("invoked")
|
||||||
var beneficiary mobilityaccountsstorage.Account
|
var beneficiary mobilityaccountsstorage.Account
|
||||||
|
|
||||||
beneficiarydocuments := []filestorage.FileInfo{}
|
beneficiarydocuments := []filestorage.FileInfo{}
|
||||||
|
|
Loading…
Reference in New Issue