Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
sbouaram | 0e00a839a3 | |
sbouaram | c354bece5f | |
sbouaram | 6299a6c7be | |
sbouaram | 718c39de00 | |
sbouaram | 9f66851529 | |
sbouaram | aa13d60ca6 | |
sbouaram | d169566cd1 | |
root | b54961b619 | |
root | c34d08ff70 | |
root | 46a72e1aef |
|
@ -12,17 +12,41 @@ import (
|
||||||
func (h APIHandler) GetCache(w http.ResponseWriter, r *http.Request) {
|
func (h APIHandler) GetCache(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
cacheid := vars["cacheid"]
|
cacheid := vars["cacheid"]
|
||||||
|
// Use a channel to synchronize the goroutines
|
||||||
|
ch := make(chan []byte)
|
||||||
|
// Fetch data from cache asynchronously
|
||||||
|
go func() {
|
||||||
d, err := h.cache.Get(cacheid)
|
d, err := h.cache.Get(cacheid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
ch <- nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var data []any
|
||||||
|
if val, ok := d.([]any); ok {
|
||||||
|
data = val
|
||||||
|
} else {
|
||||||
|
data = []any{d}
|
||||||
|
}
|
||||||
|
j := toJSON(data, w, r)
|
||||||
|
ch <- j // Signal that the data has been fetched successfully
|
||||||
|
close(ch)
|
||||||
|
}()
|
||||||
|
// wait for the JSON marshaling goroutine to finish
|
||||||
|
j := <-ch
|
||||||
|
if j == nil {
|
||||||
|
return // Stop processing if an error occurred
|
||||||
|
}
|
||||||
|
// Send the JSON response to the client
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(j)
|
||||||
|
|
||||||
result := d
|
<-ch
|
||||||
|
}
|
||||||
if data, ok := d.([]any); ok {
|
func toJSON(data []any, w http.ResponseWriter, r *http.Request) []byte {
|
||||||
|
result := data
|
||||||
if limitsmin, ok := r.URL.Query()["limits.min"]; ok {
|
if limitsmin, ok := r.URL.Query()["limits.min"]; ok {
|
||||||
min, _ := strconv.Atoi(limitsmin[0])
|
min, _ := strconv.Atoi(limitsmin[0])
|
||||||
if limitsmax, ok := r.URL.Query()["limits.max"]; ok {
|
if limitsmax, ok := r.URL.Query()["limits.max"]; ok {
|
||||||
|
@ -36,16 +60,10 @@ func (h APIHandler) GetCache(w http.ResponseWriter, r *http.Request) {
|
||||||
result = data[min:]
|
result = data[min:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
j, err := json.Marshal(result)
|
j, err := json.Marshal(result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
return j
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.Write(j)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
beneficiaries, beneficiariesErr = h.services.GetBeneficiaries()
|
||||||
|
}()
|
||||||
|
// Retrieve bookings in a goroutine
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
bookings, bookingsErr = h.services.GetBookings()
|
||||||
|
}()
|
||||||
|
// Retrieve groupsRequest in a goroutine
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
request := &groupsmanagement.GetGroupsRequest{
|
request := &groupsmanagement.GetGroupsRequest{
|
||||||
Namespaces: []string{"parcoursmob_organizations"},
|
Namespaces: []string{"parcoursmob_organizations"},
|
||||||
}
|
}
|
||||||
|
groupsResponse, groupsResponseErr = h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), request)
|
||||||
resp, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), request)
|
for _, group := range groupsResponse.Groups {
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var groups = []groupstorage.Group{}
|
|
||||||
|
|
||||||
for _, group := range resp.Groups {
|
|
||||||
g := group.ToStorageType()
|
g := group.ToStorageType()
|
||||||
groups = append(groups, g)
|
groups = append(groups, g)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(sorting.GroupsByName(groups))
|
sort.Sort(sorting.GroupsByName(groups))
|
||||||
////////////////////////////////////add event////////////////////////////////////////////
|
}()
|
||||||
rresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
// 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"},
|
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||||
})
|
})
|
||||||
|
for _, e := range eventsResponse.Events {
|
||||||
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...)
|
groupids = append(groupids, e.Owners...)
|
||||||
responses = append(responses, e.ToStorageType())
|
responses = append(responses, e.ToStorageType())
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(sorting.EventsByStartdate(responses))
|
sort.Sort(sorting.EventsByStartdate(responses))
|
||||||
|
}()
|
||||||
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
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,
|
Groupids: groupids,
|
||||||
})
|
})
|
||||||
groupps := map[string]any{}
|
groupps := map[string]any{}
|
||||||
|
if groupsBatchErr == nil {
|
||||||
if err == nil {
|
for _, g := range groupsBatchResponse.Groups {
|
||||||
for _, g := range groupsresp.Groups {
|
|
||||||
groupps[g.Id] = g.ToStorageType()
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,22 +160,23 @@ func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r
|
||||||
Namespace: "parcoursmob_roles",
|
Namespace: "parcoursmob_roles",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
go func() {
|
||||||
_, err = h.services.GRPC.GroupsManagement.AddGroup(context.TODO(), request_organization)
|
_, err = h.services.GRPC.GroupsManagement.AddGroup(context.TODO(), request_organization)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
// Create the admin role for the organization
|
// Create the admin role for the organization
|
||||||
|
go func() {
|
||||||
_, err = h.services.GRPC.GroupsManagement.AddGroup(context.TODO(), request_role)
|
_, err = h.services.GRPC.GroupsManagement.AddGroup(context.TODO(), request_role)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
http.Redirect(w, r, fmt.Sprintf("/app/administration/groups/%s", groupid), http.StatusFound)
|
http.Redirect(w, r, fmt.Sprintf("/app/administration/groups/%s", groupid), http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -205,8 +211,13 @@ func (h *ApplicationHandler) AdministrationGroupDisplay(w http.ResponseWriter, r
|
||||||
func (h *ApplicationHandler) AdministrationGroupInviteAdmin(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) AdministrationGroupInviteAdmin(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
groupid := vars["groupid"]
|
groupid := vars["groupid"]
|
||||||
|
var (
|
||||||
groupresp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{
|
groupresp *groupsmanagement.GetGroupResponse
|
||||||
|
accountresp *accounts.GetAccountUsernameResponse
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
go func() {
|
||||||
|
groupresp, err = h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{
|
||||||
Id: groupid,
|
Id: groupid,
|
||||||
Namespace: "parcoursmob_organizations",
|
Namespace: "parcoursmob_organizations",
|
||||||
})
|
})
|
||||||
|
@ -216,14 +227,14 @@ func (h *ApplicationHandler) AdministrationGroupInviteAdmin(w http.ResponseWrite
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
|
|
||||||
accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{
|
go func() {
|
||||||
|
accountresp, err = h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{
|
||||||
Username: r.FormValue("username"),
|
Username: r.FormValue("username"),
|
||||||
Namespace: "parcoursmob",
|
Namespace: "parcoursmob",
|
||||||
})
|
})
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Account already exists : adding the existing account to admin list
|
// Account already exists : adding the existing account to admin list
|
||||||
account := accountresp.Account.ToStorageType()
|
account := accountresp.Account.ToStorageType()
|
||||||
|
@ -283,12 +294,16 @@ func (h *ApplicationHandler) AdministrationGroupInviteAdmin(w http.ResponseWrite
|
||||||
|
|
||||||
http.Redirect(w, r, fmt.Sprintf("/app/administration/groups/%s", groupid), http.StatusFound)
|
http.Redirect(w, r, fmt.Sprintf("/app/administration/groups/%s", groupid), http.StatusFound)
|
||||||
return
|
return
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
groupid := vars["groupid"]
|
groupid := vars["groupid"]
|
||||||
|
var (
|
||||||
|
group storage.Group
|
||||||
|
)
|
||||||
|
groupCh := make(chan storage.Group)
|
||||||
|
go func() {
|
||||||
groupresp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{
|
groupresp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{
|
||||||
Id: groupid,
|
Id: groupid,
|
||||||
Namespace: "parcoursmob_organizations",
|
Namespace: "parcoursmob_organizations",
|
||||||
|
@ -299,16 +314,16 @@ func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWrit
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
group := groupresp.Group.ToStorageType()
|
group := groupresp.Group.ToStorageType()
|
||||||
|
groupCh <- group
|
||||||
|
}()
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
|
go func() {
|
||||||
|
group = <-groupCh
|
||||||
accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{
|
accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{
|
||||||
Username: r.FormValue("username"),
|
Username: r.FormValue("username"),
|
||||||
Namespace: "parcoursmob",
|
Namespace: "parcoursmob",
|
||||||
})
|
})
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
account := accountresp.Account.ToStorageType()
|
account := accountresp.Account.ToStorageType()
|
||||||
account.Data["groups"] = append(account.Data["groups"].([]any), group.ID)
|
account.Data["groups"] = append(account.Data["groups"].([]any), group.ID)
|
||||||
|
@ -321,15 +336,11 @@ func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWrit
|
||||||
Account: as,
|
Account: as,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
fmt.Println(err)
|
|
||||||
|
|
||||||
data := map[string]any{
|
data := map[string]any{
|
||||||
"group": group.Data["name"],
|
"group": group.Data["name"],
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.emailing.Send("onboarding.existing_member", r.FormValue("username"), data); err != nil {
|
if err := h.emailing.Send("onboarding.existing_member", r.FormValue("username"), data); err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
http.Redirect(w, r, "/app/group/settings", http.StatusFound)
|
http.Redirect(w, r, "/app/group/settings", http.StatusFound)
|
||||||
|
@ -344,26 +355,23 @@ func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWrit
|
||||||
|
|
||||||
b := make([]byte, 16)
|
b := make([]byte, 16)
|
||||||
if _, err := io.ReadFull(rand.Reader, b); err != nil {
|
if _, err := io.ReadFull(rand.Reader, b); err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
key := base64.RawURLEncoding.EncodeToString(b)
|
key := base64.RawURLEncoding.EncodeToString(b)
|
||||||
|
|
||||||
h.cache.PutWithTTL("onboarding/"+key, onboarding, 168*time.Hour) // 1 week TTL
|
h.cache.PutWithTTL("onboarding/"+key, onboarding, 168*time.Hour) // 1 week TTL
|
||||||
|
|
||||||
data := map[string]any{
|
data := map[string]any{
|
||||||
"group": group.Data["name"],
|
"group": group.Data["name"],
|
||||||
"key": key,
|
"key": key,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.emailing.Send("onboarding.new_member", r.FormValue("username"), data); err != nil {
|
if err := h.emailing.Send("onboarding.new_member", r.FormValue("username"), data); err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
http.Redirect(w, r, "/app/administration/groups/"+group.ID, http.StatusFound)
|
http.Redirect(w, r, "/app/administration/groups/"+group.ID, http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,14 @@ var Arrive any
|
||||||
|
|
||||||
func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) {
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
|
var (
|
||||||
|
journeys_results *navitia.JourneyResults
|
||||||
|
carpool_results any
|
||||||
|
vehicle_results []any
|
||||||
|
)
|
||||||
|
vehiclech := make(chan []any, 1)
|
||||||
|
navitiaCh := make(chan *navitia.JourneyResults, 1)
|
||||||
|
carpoolCh := make(chan any, 1)
|
||||||
locTime, errTime := time.LoadLocation("Europe/Paris")
|
locTime, errTime := time.LoadLocation("Europe/Paris")
|
||||||
if errTime != nil {
|
if errTime != nil {
|
||||||
fmt.Println("Loading timezone location Europe/Paris error : ")
|
fmt.Println("Loading timezone location Europe/Paris error : ")
|
||||||
|
@ -70,7 +77,8 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
journeysRequest := func() {
|
||||||
//TODO make it a library
|
//TODO make it a library
|
||||||
session, _ := navitia.NewCustom(
|
session, _ := navitia.NewCustom(
|
||||||
h.config.GetString("services.navitia.api_key"),
|
h.config.GetString("services.navitia.api_key"),
|
||||||
|
@ -79,6 +87,7 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
navitiaCh <- nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,13 +104,12 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
|
||||||
// w.WriteHeader(http.StatusBadRequest)
|
// w.WriteHeader(http.StatusBadRequest)
|
||||||
// return
|
// return
|
||||||
}
|
}
|
||||||
|
navitiaCh <- journeys
|
||||||
|
|
||||||
|
}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//CARPOOL
|
//CARPOOL
|
||||||
// carpoolrequest := fmt.Sprintf(
|
carpoolRequest := func() {
|
||||||
// "https://api.rdex.ridygo.fr/journeys.json?p[driver][state]=1&frequency=punctual&p[passenger][state]=0&p[from][latitude]=%f&p[from][longitude]=%f&p[to][latitude]=%f&p[to][longitude]=%f&p[outward][mindate]=%s&p[outward][maxdate]=%s",
|
|
||||||
// departuregeo.Geometry.Point[1], departuregeo.Geometry.Point[0],
|
|
||||||
// destinationgeo.Geometry.Point[1], destinationgeo.Geometry.Point[0],
|
|
||||||
// departuredatetime.Format("2006-01-02"), departuredatetime.Add(24*time.Hour).Format("2006-01-02"))
|
|
||||||
carpoolrequest := "https://api.rdex.ridygo.fr/journeys.json"
|
carpoolrequest := "https://api.rdex.ridygo.fr/journeys.json"
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
@ -134,9 +142,11 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
|
||||||
} else {
|
} else {
|
||||||
carpoolresults = []any{}
|
carpoolresults = []any{}
|
||||||
}
|
}
|
||||||
|
carpoolCh <- carpoolresults
|
||||||
|
}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Vehicles
|
// Vehicles
|
||||||
|
vehicleRequest := func() {
|
||||||
vehiclerequest := &fleets.GetVehiclesRequest{
|
vehiclerequest := &fleets.GetVehiclesRequest{
|
||||||
Namespaces: []string{"parcoursmob"},
|
Namespaces: []string{"parcoursmob"},
|
||||||
}
|
}
|
||||||
|
@ -145,16 +155,23 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, vehicle := range vehicleresp.Vehicles {
|
for _, vehicle := range vehicleresp.Vehicles {
|
||||||
v := vehicle.ToStorageType()
|
v := vehicle.ToStorageType()
|
||||||
if v.Free(departuredatetime.Add(-24*time.Hour), departuredatetime.Add(168*time.Hour)) {
|
if v.Free(departuredatetime.Add(-24*time.Hour), departuredatetime.Add(168*time.Hour)) {
|
||||||
vehicles = append(vehicles, v)
|
vehicles = append(vehicles, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
vehiclech <- vehicles
|
||||||
|
}
|
||||||
|
go journeysRequest()
|
||||||
|
go carpoolRequest()
|
||||||
|
go vehicleRequest()
|
||||||
|
carpool_results = <-carpoolCh
|
||||||
|
journeys_results = <-navitiaCh
|
||||||
|
vehicle_results = <-vehiclech
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Renderer.JourneysSearch(w, r, carpoolresults, journeys, vehicles, searched, departuregeo, destinationgeo, departuredate, departuretime)
|
h.Renderer.JourneysSearch(w, r, carpool_results, journeys_results, vehicle_results, searched, departuregeo, destinationgeo, departuredate, departuretime)
|
||||||
}
|
}
|
||||||
|
|
||||||
type GroupsModule []groupstorage.Group
|
type GroupsModule []groupstorage.Group
|
||||||
|
|
|
@ -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{}
|
||||||
|
|
|
@ -3,9 +3,6 @@ package exports
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"sort"
|
|
||||||
|
|
||||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||||
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
||||||
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
||||||
|
@ -13,14 +10,19 @@ import (
|
||||||
groupsstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
groupsstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||||
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||||
accountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
accountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/xuri/excelize/v2"
|
"github.com/xuri/excelize/v2"
|
||||||
|
"net/http"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *ExportsHandler) Agenda(w http.ResponseWriter, r *http.Request) {
|
func (h *ExportsHandler) Agenda(filter string) func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch filter {
|
||||||
|
case "allEvents":
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||||
Namespaces: []string{"parcoursmob_dispositifs"},
|
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
@ -67,15 +69,70 @@ func (h *ExportsHandler) Agenda(w http.ResponseWriter, r *http.Request) {
|
||||||
beneficiaries_map[ben.Id] = ben.ToStorageType()
|
beneficiaries_map[ben.Id] = ben.ToStorageType()
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////// Generate file
|
f := h.generateExcel(events, groups, beneficiaries_map)
|
||||||
|
|
||||||
|
h.writeFileResponse(f, w)
|
||||||
|
}
|
||||||
|
|
||||||
|
case "oneEvent":
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
eventId := vars["eventid"]
|
||||||
|
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), &agenda.GetEventRequest{
|
||||||
|
Id: eventId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
groupids := []string{}
|
||||||
|
beneficiaries_ids := []string{}
|
||||||
|
groupids = append(groupids, resp.Event.Owners...)
|
||||||
|
for _, subscriptions := range resp.Event.Subscriptions {
|
||||||
|
beneficiaries_ids = append(beneficiaries_ids, subscriptions.Subscriber)
|
||||||
|
}
|
||||||
|
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||||
|
Groupids: groupids,
|
||||||
|
})
|
||||||
|
groups := map[string]groupsstorage.Group{}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
for _, g := range groupsresp.Groups {
|
||||||
|
groups[g.Id] = g.ToStorageType()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
beneficiaries, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), &accounts.GetAccountsBatchRequest{
|
||||||
|
Accountids: beneficiaries_ids,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
beneficiaries_map := map[string]accountsstorage.Account{}
|
||||||
|
for _, ben := range beneficiaries.Accounts {
|
||||||
|
beneficiaries_map[ben.Id] = ben.ToStorageType()
|
||||||
|
}
|
||||||
|
|
||||||
|
f := h.generateExcel([]agendastorage.Event{resp.Event.ToStorageType()}, groups, beneficiaries_map)
|
||||||
|
h.writeFileResponse(f, w)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ExportsHandler) generateExcel(events []agendastorage.Event, groups map[string]groupsstorage.Group,
|
||||||
|
beneficiaries_map map[string]accountsstorage.Account) *excelize.File {
|
||||||
f := excelize.NewFile()
|
f := excelize.NewFile()
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := f.Close(); err != nil {
|
if err := f.Close(); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
f.SetCellValue("Sheet1", "A1", "Evénement")
|
f.SetCellValue("Sheet1", "A1", "Evénement")
|
||||||
f.SetCellValue("Sheet1", "B1", "Date de début")
|
f.SetCellValue("Sheet1", "B1", "Date de début")
|
||||||
f.SetCellValue("Sheet1", "C1", "Date de fin")
|
f.SetCellValue("Sheet1", "C1", "Date de fin")
|
||||||
|
@ -85,8 +142,6 @@ func (h *ExportsHandler) Agenda(w http.ResponseWriter, r *http.Request) {
|
||||||
f.SetCellValue("Sheet1", "G1", "Prescipteur")
|
f.SetCellValue("Sheet1", "G1", "Prescipteur")
|
||||||
f.SetCellValue("Sheet1", "H1", "Prescipteur Nom")
|
f.SetCellValue("Sheet1", "H1", "Prescipteur Nom")
|
||||||
f.SetCellValue("Sheet1", "I1", "Gestionnaire événement")
|
f.SetCellValue("Sheet1", "I1", "Gestionnaire événement")
|
||||||
// f.SetCellValue("Sheet1", "I1", "Prescripteur téléphone")
|
|
||||||
|
|
||||||
i := 2
|
i := 2
|
||||||
for _, e := range events {
|
for _, e := range events {
|
||||||
if len(e.Owners) == 0 {
|
if len(e.Owners) == 0 {
|
||||||
|
@ -128,10 +183,14 @@ func (h *ExportsHandler) Agenda(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return f
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ExportsHandler) writeFileResponse(file *excelize.File, w http.ResponseWriter) {
|
||||||
w.Header().Set("Content-Type", "application/octet-stream")
|
w.Header().Set("Content-Type", "application/octet-stream")
|
||||||
w.Header().Set("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
|
w.Header().Set("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
|
||||||
w.Header().Set("Content-Transfer-Encoding", "binary")
|
w.Header().Set("Content-Transfer-Encoding", "binary")
|
||||||
w.Header().Set("Expires", "0")
|
w.Header().Set("Expires", "0")
|
||||||
f.Write(w)
|
file.Write(w)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cfg, err := ReadConfig()
|
cfg, err := ReadConfig()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -29,17 +30,15 @@ func main() {
|
||||||
templates_public_dir = cfg.GetString("templates.public_dir")
|
templates_public_dir = cfg.GetString("templates.public_dir")
|
||||||
dev_env = cfg.GetBool("dev_env")
|
dev_env = cfg.GetBool("dev_env")
|
||||||
)
|
)
|
||||||
|
|
||||||
svc, err := services.NewServicesHandler(cfg)
|
svc, err := services.NewServicesHandler(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
fmt.Println(cfg)
|
||||||
kv, err := cache.NewKVHandler(cfg)
|
kv, err := cache.NewKVHandler(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
filestorage, err := cache.NewFileStorage(cfg)
|
filestorage, err := cache.NewFileStorage(cfg)
|
||||||
|
|
||||||
idp, err := identification.NewIdentificationProvider(cfg, svc, kv)
|
idp, err := identification.NewIdentificationProvider(cfg, svc, kv)
|
||||||
|
@ -163,12 +162,11 @@ func main() {
|
||||||
|
|
||||||
export := r.PathPrefix("/exports").Subrouter()
|
export := r.PathPrefix("/exports").Subrouter()
|
||||||
export.HandleFunc("/fleets/bookings", exportsHandler.Bookings)
|
export.HandleFunc("/fleets/bookings", exportsHandler.Bookings)
|
||||||
export.HandleFunc("/agenda/subscriptions", exportsHandler.Agenda)
|
export.HandleFunc("/agenda/subscriptions", exportsHandler.Agenda("allEvents"))
|
||||||
|
export.HandleFunc("/agenda/{eventid}", exportsHandler.Agenda("oneEvent"))
|
||||||
export.Use(idp.Middleware)
|
export.Use(idp.Middleware)
|
||||||
export.Use(idp.GroupsMiddleware)
|
export.Use(idp.GroupsMiddleware)
|
||||||
|
|
||||||
fmt.Println("-> HTTP server listening on", address)
|
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Handler: r,
|
Handler: r,
|
||||||
Addr: address,
|
Addr: address,
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit d6de19d8e238fec2f03957abdfa7b49a463d4a3c
|
|
@ -0,0 +1 @@
|
||||||
|
package storage
|
|
@ -74,6 +74,7 @@ func NewEtcdHandler(cfg *viper.Viper) (*EtcdHandler, error) {
|
||||||
Password: password,
|
Password: password,
|
||||||
DialTimeout: 5 * time.Second,
|
DialTimeout: 5 * time.Second,
|
||||||
})
|
})
|
||||||
|
fmt.Println(endpoints,prefix,username,password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
package storage
|
|
@ -1,6 +1,7 @@
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -14,5 +15,18 @@ type KVHandler interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKVHandler(cfg *viper.Viper) (KVHandler, error) {
|
func NewKVHandler(cfg *viper.Viper) (KVHandler, error) {
|
||||||
|
cacheType := cfg.GetString("storage.kv.dbType")
|
||||||
|
switch cacheType {
|
||||||
|
case "etcd":
|
||||||
return NewEtcdHandler(cfg)
|
return NewEtcdHandler(cfg)
|
||||||
|
case "badger":
|
||||||
|
return NewBadgerHandler(cfg)
|
||||||
|
case "etcdGroupcache":
|
||||||
|
return NewGroupCacheHandler(cfg)
|
||||||
|
fmt.Println("here")
|
||||||
|
case "badgerGroupcache":
|
||||||
|
return NewGroupCacheHandler(cfg)
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue