diff --git a/handlers/application/agenda.go b/handlers/application/agenda.go index 70a1095..52391a2 100755 --- a/handlers/application/agenda.go +++ b/handlers/application/agenda.go @@ -255,7 +255,7 @@ func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http } vars := mux.Vars(r) eventid := vars["eventid"] - + fmt.Println(eventid) if err := r.ParseForm(); err != nil { fmt.Println(err) w.WriteHeader(http.StatusBadRequest) diff --git a/handlers/application/beneficiaries.go b/handlers/application/beneficiaries.go index ad4f22a..47b2a21 100755 --- a/handlers/application/beneficiaries.go +++ b/handlers/application/beneficiaries.go @@ -205,6 +205,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R subcriptionresp, err := h.services.GRPC.Agenda.GetSubscriptionByUser(context.TODO(), subscriptionrequest) if err != nil { + fmt.Println("icii") fmt.Println(err) w.WriteHeader(http.StatusInternalServerError) return @@ -212,13 +213,15 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R events := []agendastorage.Event{} currentTime := time.Now().Truncate(24 * time.Hour) - + fmt.Println(subcriptionresp) for _, e := range subcriptionresp.Subscription { eventresquest := &agenda.GetEventRequest{ Id: e.Eventid, } + fmt.Println(eventresquest) eventresp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), eventresquest) if err != nil { + fmt.Println("iciiiiii") fmt.Println(err) w.WriteHeader(http.StatusInternalServerError) return @@ -269,6 +272,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R } events_list = append(events_list, event) + } var status_booking int @@ -306,6 +310,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R } events_list = append(events_list, event) + } } sortByDate(events_list) diff --git a/handlers/application/vehicles-management.go b/handlers/application/vehicles-management.go index f56c833..c2326b8 100755 --- a/handlers/application/vehicles-management.go +++ b/handlers/application/vehicles-management.go @@ -302,12 +302,15 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite } alternativerequest := &fleets.GetVehiclesRequest{ - Namespaces: []string{"parcoursmob"}, - Types: []string{booking.Vehicle.Type}, - Administrators: booking.Vehicle.Administrators, - AvailabilityFrom: timestamppb.New(booking.Startdate), - AvailabilityTo: timestamppb.New(booking.Enddate.Add(24 * time.Hour)), + Namespaces: []string{"parcoursmob"}, + Types: []string{booking.Vehicle.Type}, + Administrators: booking.Vehicle.Administrators, + //AvailabilityFrom: timestamppb.New(booking.Startdate), + //AvailabilityTo: timestamppb.New(booking.Startdate.Add(After(time.Now()))), } + // if alternativerequest.AvailabilityFrom.After(time.Now()) { + // fmt.Println("loooool") + // } alternativeresp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), alternativerequest) if err != nil { @@ -319,11 +322,48 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite for _, a := range alternativeresp.Vehicles { alternatives = append(alternatives, a.ToStorageType()) } + /***************************************add list of vehicules ******************************************/ + requesst := &fleets.GetVehiclesRequest{ + Namespaces: []string{"parcoursmob"}, + } + ressp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), requesst) + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + } + vehicles := []fleetsstorage.Vehicle{} + bookings := []fleetsstorage.Booking{} + vehicles_map := map[string]fleetsstorage.Vehicle{} + + for _, vehicle := range ressp.Vehicles { + if filterVehicle(r, vehicle) { + v := vehicle.ToStorageType() + vehicleBookings := []fleetsstorage.Booking{} + for _, b := range v.Bookings { + if b.Status() != fleetsstorage.StatusOld { + if deleted, ok := b.Data["Deleted"].(bool); !ok && !deleted { + bookings = append(bookings, b) + } + } + if b.Unavailableto.After(time.Now()) { + vehicleBookings = append(vehicleBookings, b) + } + } + v.Bookings = vehicleBookings + vehicles = append(vehicles, v) + vehicles_map[v.ID] = v + + } + } + + //sort.Sort(sorting.VehiclesByLicencePlate(vehicles)) + //sort.Sort(sorting.BookingsByStartdate(bookings)) + /*********************************************************************************/ documents := h.filestorage.List(filestorage.PREFIX_BOOKINGS + "/" + bookingid) file_types_map := h.config.GetStringMapString("storage.files.file_types") - h.Renderer.VehicleManagementBookingDisplay(w, r, booking, booking.Vehicle, beneficiary, groupresp.Group.ToStorageType(), documents, file_types_map, alternatives) + h.Renderer.VehicleManagementBookingDisplay(w, r, booking, booking.Vehicle, beneficiary, groupresp.Group.ToStorageType(), documents, file_types_map, alternatives, vehicles, vehicles_map, bookings) } func (h ApplicationHandler) VehicleManagementBookingChangeVehicle(w http.ResponseWriter, r *http.Request) { @@ -553,8 +593,17 @@ func (h *ApplicationHandler) UnbookingVehicle(w http.ResponseWriter, r *http.Req Data: datapb, }, } + requestt := &fleets.DeleteBookingRequest{ + Id: bookingid, + } + _, errr := h.services.GRPC.Fleets.UpdateBooking(context.TODO(), request) - _, err := h.services.GRPC.Fleets.UpdateBooking(context.TODO(), request) + if errr != nil { + fmt.Println(errr) + w.WriteHeader(http.StatusInternalServerError) + return + } + _, err := h.services.GRPC.Fleets.DeleteBooking(context.TODO(), requestt) if err != nil { fmt.Println(err) diff --git a/handlers/auth/onboarding.go b/handlers/auth/onboarding.go index 20a3982..8957887 100755 --- a/handlers/auth/onboarding.go +++ b/handlers/auth/onboarding.go @@ -40,8 +40,8 @@ func (h *AuthHandler) Onboarding(w http.ResponseWriter, r *http.Request) { display_name := fmt.Sprint(r.FormValue("first_name")) + " " + fmt.Sprint(r.FormValue("last_name")) account := &ma.Account{ Authentication: ma.AccountAuth{ - Local: ma.LocalAuth{ - Username: onboardingmap["username"].(string), + Local: &ma.LocalAuth{ + Username: onboardingmap["username"].(*string), Password: r.FormValue("password"), }, }, diff --git a/renderer/vehicle-management.go b/renderer/vehicle-management.go index eda9d35..958f852 100755 --- a/renderer/vehicle-management.go +++ b/renderer/vehicle-management.go @@ -64,7 +64,7 @@ func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Req renderer.Render("fleet display vehicle", w, r, files, state) } -func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter, r *http.Request, booking any, vehicle any, beneficiary any, group any, documents []filestorage.FileInfo, file_types_map map[string]string, alternative_vehicles []any) { +func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter, r *http.Request, booking any, vehicle any, beneficiary any, group any, documents []filestorage.FileInfo, file_types_map map[string]string, alternative_vehicles []any, vehicles []fleetsstorage.Vehicle, vehicles_map map[string]fleetsstorage.Vehicle, bookings []fleetsstorage.Booking) { files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.booking_display.files") state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) state.ViewState = map[string]any{ @@ -75,6 +75,9 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter, "documents": documents, "file_types_map": file_types_map, "alternative_vehicles": alternative_vehicles, + "vehicles": vehicles, + "bookings": bookings, + "vehicles_map": vehicles_map, } renderer.Render("vehicles search", w, r, files, state) @@ -84,9 +87,9 @@ func (renderer *Renderer) UnbookingVehicle(w http.ResponseWriter, r *http.Reques files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.delete_booking.files") state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) state.ViewState = map[string]any{ - "booking": booking, + "booking": booking, } renderer.Render("vehicule unbooking", w, r, files, state) -} \ No newline at end of file +}