Admin stat vehicles

This commit is contained in:
2023-01-17 08:31:07 +01:00
parent d531fe63ff
commit 0c0a9d0496
12 changed files with 124 additions and 72 deletions

View File

@@ -11,6 +11,8 @@ import (
"time"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
"git.coopgo.io/coopgo-platform/fleets/storage"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
@@ -331,6 +333,31 @@ func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWrit
return
}
func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Request) {
request := &fleets.GetBookingsRequest{}
resp, err := h.services.GRPC.Fleets.GetBookings(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusNotFound)
return
}
bookings := []storage.Booking{}
for _, b := range resp.Bookings {
booking := b.ToStorageType()
bookings = append(bookings, booking)
}
sort.Sort(sorting.BookingsByStartdate(bookings))
vehicles, _ := h.services.GetVehiclesMap()
groups, _ := h.services.GetGroupsMap()
h.Renderer.VehicleBookingsList(w, r, bookings, vehicles, groups)
}
func (h *ApplicationHandler) members() ([]*accounts.Account, error) {
resp, err := h.services.GRPC.MobilityAccounts.GetAccounts(context.TODO(), &accounts.GetAccountsRequest{
Namespaces: []string{"parcoursmob"},

View File

@@ -61,6 +61,7 @@ func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Re
func (h *ApplicationHandler) BeneficiaryCreate(w http.ResponseWriter, r *http.Request) {
g := r.Context().Value(identification.GroupKey)
if g == nil {
fmt.Println("Create beneficiary : could not find group")
w.WriteHeader(http.StatusBadRequest)
return
}

View File

@@ -21,7 +21,7 @@ type UserForm struct {
Gender string `json:"gender"`
}
func (h *ApplicationHandler) ConseillerDisplay(w http.ResponseWriter, r *http.Request) {
func (h *ApplicationHandler) MemberDisplay(w http.ResponseWriter, r *http.Request) {
adm := strings.Split(r.URL.Path, "/")
adminid := adm[3]
@@ -37,10 +37,10 @@ func (h *ApplicationHandler) ConseillerDisplay(w http.ResponseWriter, r *http.Re
return
}
h.Renderer.ConseillerDisplay(w, r, resp.Account.ToStorageType())
h.Renderer.MemberDisplay(w, r, resp.Account.ToStorageType())
}
func (h *ApplicationHandler) ConseillerUpdate(w http.ResponseWriter, r *http.Request) {
func (h *ApplicationHandler) MemberUpdate(w http.ResponseWriter, r *http.Request) {
adm := strings.Split(r.URL.Path, "/")
userID := adm[3]
@@ -92,7 +92,7 @@ func (h *ApplicationHandler) ConseillerUpdate(w http.ResponseWriter, r *http.Req
return
}
h.Renderer.ConseillerUpdate(w, r, resp.Account.ToStorageType())
h.Renderer.MemberUpdate(w, r, resp.Account.ToStorageType())
}
func parseUserForm(r *http.Request) (map[string]any, error) {

View File

@@ -136,14 +136,7 @@ func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Reques
}
func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
// Get Group
// g := r.Context().Value(identification.GroupKey)
// if g == nil {
// fmt.Println("no current group")
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// current_group := g.(storage.Group)
fmt.Println("Book")
current_group, err := h.currentGroup(r)
if err != nil {
fmt.Println(err)
@@ -151,24 +144,6 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
return
}
// Get current user ID
// u := r.Context().Value(identification.IdtokenKey)
// if u == nil {
// fmt.Println("no current user")
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// current_user_token := u.(*oidc.IDToken)
// // Get current user claims
// c := r.Context().Value(identification.ClaimsKey)
// if c == nil {
// fmt.Println("no current user claims")
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// current_user_claims := c.(map[string]any)
current_user_token, current_user_claims, err := h.currentUser(r)
if err != nil {
fmt.Println(err)
@@ -191,7 +166,7 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
return
}
r.ParseMultipartForm(10 * 1024 * 1024)
r.ParseMultipartForm(100 * 1024 * 1024)
start := r.FormValue("startdate")
end := r.FormValue("enddate")
@@ -203,7 +178,7 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
"booked_by": map[string]any{
"user": map[string]any{
"id": current_user_token.Subject,
"display_name": current_user_claims["display_name"],
"display_name": fmt.Sprintf("%s %s", current_user_claims["first_name"], current_user_claims["last_name"]),
},
"group": map[string]any{
"id": current_group.ID,
@@ -233,7 +208,6 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
Booking: booking,
}
fmt.Println(r.FormFile("doc-identity_proof"))
for _, v := range h.config.GetStringSlice("modules.fleets.booking_documents.mandatory") {
existing_file := r.FormValue("type-" + v)
if existing_file == "" {
@@ -282,9 +256,11 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
fmt.Println(err)
} else {
for _, m := range members {
h.emailing.Send("fleets.bookings.creation_admin_alert", m.Data["email"].(string), map[string]string{
"bookingid": booking.Id,
})
if email, ok := m.Data["email"].(string); ok {
h.emailing.Send("fleets.bookings.creation_admin_alert", email, map[string]string{
"bookingid": booking.Id,
})
}
}
}
@@ -314,9 +290,9 @@ func (h ApplicationHandler) VehicleBookingDisplay(w http.ResponseWriter, r *http
beneficiaryresp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), beneficiaryrequest)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
beneficiaryresp = &mobilityaccounts.GetAccountResponse{
Account: &mobilityaccounts.Account{},
}
}
grouprequest := &groupsmanagement.GetGroupRequest{
@@ -370,7 +346,10 @@ func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.
sort.Sort(sorting.BookingsByStartdate(bookings))
h.Renderer.VehicleBookingsList(w, r, bookings)
vehicles, _ := h.services.GetVehiclesMap()
groups, _ := h.services.GetGroupsMap()
h.Renderer.VehicleBookingsList(w, r, bookings, vehicles, groups)
}
func (h *ApplicationHandler) BookingDocumentDownload(w http.ResponseWriter, r *http.Request) {

View File

@@ -0,0 +1,13 @@
package auth
import "net/http"
func (h *AuthHandler) Disconnect(w http.ResponseWriter, r *http.Request) {
session, err := h.idp.SessionsStore.Get(r, "parcoursmob_session")
if err == nil {
session.Options.MaxAge = -1
session.Save(r, w)
}
http.Redirect(w, r, "/", http.StatusOK)
}