delete reservation and history benef

This commit is contained in:
soukainna 2024-09-02 21:33:50 +02:00
parent b77403c674
commit 4ecefbc8e1
5 changed files with 71 additions and 14 deletions

View File

@ -255,7 +255,7 @@ func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http
} }
vars := mux.Vars(r) vars := mux.Vars(r)
eventid := vars["eventid"] eventid := vars["eventid"]
fmt.Println(eventid)
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
fmt.Println(err) fmt.Println(err)
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)

View File

@ -205,6 +205,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
subcriptionresp, err := h.services.GRPC.Agenda.GetSubscriptionByUser(context.TODO(), subscriptionrequest) subcriptionresp, err := h.services.GRPC.Agenda.GetSubscriptionByUser(context.TODO(), subscriptionrequest)
if err != nil { if err != nil {
fmt.Println("icii")
fmt.Println(err) fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
@ -212,13 +213,15 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
events := []agendastorage.Event{} events := []agendastorage.Event{}
currentTime := time.Now().Truncate(24 * time.Hour) currentTime := time.Now().Truncate(24 * time.Hour)
fmt.Println(subcriptionresp)
for _, e := range subcriptionresp.Subscription { for _, e := range subcriptionresp.Subscription {
eventresquest := &agenda.GetEventRequest{ eventresquest := &agenda.GetEventRequest{
Id: e.Eventid, Id: e.Eventid,
} }
fmt.Println(eventresquest)
eventresp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), eventresquest) eventresp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), eventresquest)
if err != nil { if err != nil {
fmt.Println("iciiiiii")
fmt.Println(err) fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
@ -269,6 +272,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
} }
events_list = append(events_list, event) events_list = append(events_list, event)
} }
var status_booking int var status_booking int
@ -306,6 +310,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
} }
events_list = append(events_list, event) events_list = append(events_list, event)
} }
} }
sortByDate(events_list) sortByDate(events_list)

View File

@ -302,12 +302,15 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite
} }
alternativerequest := &fleets.GetVehiclesRequest{ alternativerequest := &fleets.GetVehiclesRequest{
Namespaces: []string{"parcoursmob"}, Namespaces: []string{"parcoursmob"},
Types: []string{booking.Vehicle.Type}, Types: []string{booking.Vehicle.Type},
Administrators: booking.Vehicle.Administrators, Administrators: booking.Vehicle.Administrators,
AvailabilityFrom: timestamppb.New(booking.Startdate), //AvailabilityFrom: timestamppb.New(booking.Startdate),
AvailabilityTo: timestamppb.New(booking.Enddate.Add(24 * time.Hour)), //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) alternativeresp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), alternativerequest)
if err != nil { if err != nil {
@ -319,11 +322,48 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite
for _, a := range alternativeresp.Vehicles { for _, a := range alternativeresp.Vehicles {
alternatives = append(alternatives, a.ToStorageType()) 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) documents := h.filestorage.List(filestorage.PREFIX_BOOKINGS + "/" + bookingid)
file_types_map := h.config.GetStringMapString("storage.files.file_types") 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) { 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, 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 { if err != nil {
fmt.Println(err) fmt.Println(err)

View File

@ -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")) display_name := fmt.Sprint(r.FormValue("first_name")) + " " + fmt.Sprint(r.FormValue("last_name"))
account := &ma.Account{ account := &ma.Account{
Authentication: ma.AccountAuth{ Authentication: ma.AccountAuth{
Local: ma.LocalAuth{ Local: &ma.LocalAuth{
Username: onboardingmap["username"].(string), Username: onboardingmap["username"].(*string),
Password: r.FormValue("password"), Password: r.FormValue("password"),
}, },
}, },

View File

@ -64,7 +64,7 @@ func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Req
renderer.Render("fleet display vehicle", w, r, files, state) 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") files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.booking_display.files")
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
state.ViewState = map[string]any{ state.ViewState = map[string]any{
@ -75,6 +75,9 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter,
"documents": documents, "documents": documents,
"file_types_map": file_types_map, "file_types_map": file_types_map,
"alternative_vehicles": alternative_vehicles, "alternative_vehicles": alternative_vehicles,
"vehicles": vehicles,
"bookings": bookings,
"vehicles_map": vehicles_map,
} }
renderer.Render("vehicles search", w, r, files, state) 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") files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.delete_booking.files")
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
state.ViewState = map[string]any{ state.ViewState = map[string]any{
"booking": booking, "booking": booking,
} }
renderer.Render("vehicule unbooking", w, r, files, state) renderer.Render("vehicule unbooking", w, r, files, state)
} }