2 Commits

3 changed files with 83 additions and 24 deletions

View File

@@ -467,27 +467,70 @@ func (h ApplicationHandler) VehiclesFleetMakeUnavailable(w http.ResponseWriter,
http.Redirect(w, r, fmt.Sprintf("/app/vehicles-management/fleet/%s", vehicleid), http.StatusFound) http.Redirect(w, r, fmt.Sprintf("/app/vehicles-management/fleet/%s", vehicleid), http.StatusFound)
} }
// func (h *ApplicationHandler) UnbookingVehicles(w http.ResponseWriter, r *http.Request) { // func (h *ApplicationHandler) UnbookingVehicles(w http.ResponseWriter, r *http.Request) {
// request := &fleets.GetVehiclesRequest{ // request := &fleets.GetVehiclesRequest{
// Namespaces: []string{"parcoursmob"}, // Namespaces: []string{"parcoursmob"},
// } // }
// resp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), request) // resp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), request)
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// w.WriteHeader(http.StatusInternalServerError) // w.WriteHeader(http.StatusInternalServerError)
// } // }
// vehicles := []fleetsstorage.Vehicle{} // vehicles := []fleetsstorage.Vehicle{}
// fmt.Println(resp.Vehicles[0].Bookings) // fmt.Println(resp.Vehicles[0].Bookings)
// for i, vehicle := range resp.Vehicles { // for i, vehicle := range resp.Vehicles {
// if len(resp.Vehicles[i].Bookings) == 0 { // if len(resp.Vehicles[i].Bookings) == 0 {
// v := vehicle.ToStorageType() // v := vehicle.ToStorageType()
// vehicles = append(vehicles, v) // vehicles = append(vehicles, v)
// } // }
// } // }
// // if len(resp.Vehicle.ToStorageType().Bookings) == 0 { // // if len(resp.Vehicle.ToStorageType().Bookings) == 0 {
// // h.Renderer.UnbookingVehicles(w, r, resp.Vehicle.ToStorageType()) // // h.Renderer.UnbookingVehicles(w, r, resp.Vehicle.ToStorageType())
// // } // // }
// // fmt.Println(resp.Vehicle.ToStorageType().Bookings) // // fmt.Println(resp.Vehicle.ToStorageType().Bookings)
// fmt.Println(vehicles) // fmt.Println(vehicles)
// h.Renderer.UnbookingVehicles(w, r, vehicles) // h.Renderer.UnbookingVehicles(w, r, vehicles)
// } // }
func (h *ApplicationHandler) UnbookingVehicle(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bookingid := vars["bookingid"]
request := &fleets.GetBookingRequest{
Bookingid: bookingid,
}
resp, err := h.services.GRPC.Fleets.GetBooking(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if r.Method == "POST" {
request := &fleets.UpdateBookingRequest{
Booking: &fleets.Booking{
Id: resp.Booking.Id,
Vehicleid: resp.Booking.Vehicleid,
Driver: resp.Booking.Driver,
Startdate: resp.Booking.Startdate,
Enddate: resp.Booking.Enddate,
Unavailablefrom: resp.Booking.Unavailablefrom,
Unavailableto: resp.Booking.Unavailableto,
Data: resp.Booking.Data,
Deleted: true,
},
}
_, err := h.services.GRPC.Fleets.UpdateBooking(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/app/vehicles-management/", http.StatusFound)
return
}
h.Renderer.UnbookingVehicle(w, r, bookingid)
}

View File

@@ -106,6 +106,9 @@ func main() {
application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList) application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList)
application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay) application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay)
application.HandleFunc("/vehicles-management/bookings/{bookingid}/change-vehicle", applicationHandler.VehicleManagementBookingChangeVehicle) application.HandleFunc("/vehicles-management/bookings/{bookingid}/change-vehicle", applicationHandler.VehicleManagementBookingChangeVehicle)
/////////////////////////////////////Remove booking vehicle/////////////////////////////////////////
application.HandleFunc("/vehicles-management/bookings/{bookingid}/delete", applicationHandler.UnbookingVehicle)
////////////////////////////////////////////////////////////////////////////////////////////////////
application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload) application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload)
application.HandleFunc("/agenda/", applicationHandler.AgendaHome) application.HandleFunc("/agenda/", applicationHandler.AgendaHome)
application.HandleFunc("/agenda/history", applicationHandler.AgendaHistory) application.HandleFunc("/agenda/history", applicationHandler.AgendaHistory)
@@ -157,6 +160,8 @@ func main() {
application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent) application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent)
application.HandleFunc("/agenda/{eventid}/history", applicationHandler.AgendaHistoryEvent) application.HandleFunc("/agenda/{eventid}/history", applicationHandler.AgendaHistoryEvent)
///////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////
fmt.Println("-> HTTP server listening on", address) fmt.Println("-> HTTP server listening on", address)
srv := &http.Server{ srv := &http.Server{

View File

@@ -78,3 +78,14 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter,
renderer.Render("vehicles search", w, r, files, state) renderer.Render("vehicles search", w, r, files, state)
} }
func (renderer *Renderer) UnbookingVehicle(w http.ResponseWriter, r *http.Request, booking string) {
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.delete_booking.files")
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
state.ViewState = map[string]any{
"booking": booking,
}
renderer.Render("vehicule unbooking", w, r, files, state)
}