edit config.yaml to add delete_booking route
This commit is contained in:
parent
78877f139f
commit
8f20a12bc5
|
@ -491,3 +491,118 @@ func (h ApplicationHandler) VehiclesFleetMakeUnavailable(w http.ResponseWriter,
|
|||
// fmt.Println(vehicles)
|
||||
// h.Renderer.UnbookingVehicles(w, r, vehicles)
|
||||
// }
|
||||
func (h *ApplicationHandler) UnbookingVehicle(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
bookingid := vars["bookingid"]
|
||||
|
||||
booking, err := h.services.GetBooking(bookingid)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if r.Method == "POST" {
|
||||
r.ParseForm()
|
||||
|
||||
newbooking, _ := fleets.BookingFromStorageType(&booking)
|
||||
|
||||
startdate := r.FormValue("startdate")
|
||||
if startdate != "" {
|
||||
newstartdate, _ := time.Parse("2006-01-02", startdate)
|
||||
newbooking.Startdate = timestamppb.New(newstartdate)
|
||||
|
||||
if newstartdate.Before(newbooking.Unavailablefrom.AsTime()) {
|
||||
newbooking.Unavailablefrom = timestamppb.New(newstartdate)
|
||||
}
|
||||
}
|
||||
|
||||
enddate := r.FormValue("enddate")
|
||||
if enddate != "" {
|
||||
newenddate, _ := time.Parse("2006-01-02", enddate)
|
||||
newbooking.Enddate = timestamppb.New(newenddate)
|
||||
|
||||
if newenddate.After(newbooking.Unavailableto.AsTime()) || newenddate.Equal(newbooking.Unavailableto.AsTime()) {
|
||||
newbooking.Unavailableto = timestamppb.New(newenddate.Add(24 * time.Hour))
|
||||
}
|
||||
}
|
||||
|
||||
unavailablefrom := r.FormValue("unavailablefrom")
|
||||
if unavailablefrom != "" {
|
||||
newunavailablefrom, _ := time.Parse("2006-01-02", unavailablefrom)
|
||||
newbooking.Unavailablefrom = timestamppb.New(newunavailablefrom)
|
||||
}
|
||||
|
||||
unavailableto := r.FormValue("unavailableto")
|
||||
if unavailableto != "" {
|
||||
newunavailableto, _ := time.Parse("2006-01-02", unavailableto)
|
||||
newbooking.Unavailableto = timestamppb.New(newunavailableto)
|
||||
}
|
||||
|
||||
request := &fleets.UpdateBookingRequest{
|
||||
Booking: newbooking,
|
||||
}
|
||||
|
||||
_, err := h.services.GRPC.Fleets.UpdateBooking(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
booking = newbooking.ToStorageType()
|
||||
}
|
||||
|
||||
beneficiary := mobilityaccountsstorage.Account{}
|
||||
|
||||
if booking.Driver != "" {
|
||||
beneficiaryrequest := &mobilityaccounts.GetAccountRequest{
|
||||
Id: booking.Driver,
|
||||
}
|
||||
|
||||
beneficiaryresp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), beneficiaryrequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
beneficiary = beneficiaryresp.Account.ToStorageType()
|
||||
}
|
||||
|
||||
grouprequest := &groupsmanagement.GetGroupRequest{
|
||||
Id: booking.Vehicle.Administrators[0],
|
||||
}
|
||||
|
||||
groupresp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), grouprequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
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)),
|
||||
}
|
||||
|
||||
alternativeresp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), alternativerequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
alternatives := []any{}
|
||||
|
||||
for _, a := range alternativeresp.Vehicles {
|
||||
alternatives = append(alternatives, a.ToStorageType())
|
||||
}
|
||||
|
||||
documents := h.filestorage.List(filestorage.PREFIX_BOOKINGS + "/" + bookingid)
|
||||
file_types_map := h.config.GetStringMapString("storage.files.file_types")
|
||||
|
||||
h.Renderer.UnbookingVehicle(w, r, booking, booking.Vehicle, beneficiary, groupresp.Group.ToStorageType(), documents, file_types_map, alternatives)
|
||||
|
||||
}
|
5
main.go
5
main.go
|
@ -106,6 +106,9 @@ func main() {
|
|||
application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList)
|
||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay)
|
||||
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("/agenda/", applicationHandler.AgendaHome)
|
||||
application.HandleFunc("/agenda/history", applicationHandler.AgendaHistory)
|
||||
|
@ -157,6 +160,8 @@ func main() {
|
|||
application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent)
|
||||
application.HandleFunc("/agenda/{eventid}/history", applicationHandler.AgendaHistoryEvent)
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
fmt.Println("-> HTTP server listening on", address)
|
||||
|
||||
srv := &http.Server{
|
||||
|
|
|
@ -78,3 +78,20 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter,
|
|||
|
||||
renderer.Render("vehicles search", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) UnbookingVehicle(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) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.delete_booking.files")
|
||||
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"booking": booking,
|
||||
"vehicle": vehicle,
|
||||
"beneficiary": beneficiary,
|
||||
"group": group,
|
||||
"documents": documents,
|
||||
"file_types_map": file_types_map,
|
||||
"alternative_vehicles": alternative_vehicles,
|
||||
}
|
||||
|
||||
renderer.Render("vehicles search", w, r, files, state)
|
||||
|
||||
}
|
Loading…
Reference in New Issue