add logic fuction to update vehicles
This commit is contained in:
parent
850633eac7
commit
1aeb6d50ef
|
@ -52,14 +52,6 @@ func (h *ApplicationHandler) VehiclesManagementOverview(w http.ResponseWriter, r
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// vehiicles := []fleetsstorage.Vehicle{}
|
|
||||||
// for i, vehiicle := range resp.Vehicles {
|
|
||||||
// if len(resp.Vehicles[i].Bookings) == 0 {
|
|
||||||
// v := vehiicle.ToStorageType()
|
|
||||||
// vehiicles = append(vehiicles, v)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//fmt.Println(vehiicles)
|
|
||||||
sort.Sort(sorting.VehiclesByLicencePlate(vehicles))
|
sort.Sort(sorting.VehiclesByLicencePlate(vehicles))
|
||||||
sort.Sort(sorting.BookingsByStartdate(bookings))
|
sort.Sort(sorting.BookingsByStartdate(bookings))
|
||||||
h.Renderer.VehiclesManagementOverview(w, r, vehicles, vehicles_map, bookings)
|
h.Renderer.VehiclesManagementOverview(w, r, vehicles, vehicles_map, bookings)
|
||||||
|
@ -190,36 +182,10 @@ func (h *ApplicationHandler) VehiclesFleetDisplay(w http.ResponseWriter, r *http
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// if len(resp.Vehicle.ToStorageType().Bookings) == 0 {
|
|
||||||
// fmt.Println("lol")
|
|
||||||
// }
|
|
||||||
// fmt.Println(resp.Vehicle.ToStorageType().Bookings)
|
|
||||||
h.Renderer.VehiclesFleetDisplay(w, r, resp.Vehicle.ToStorageType())
|
h.Renderer.VehiclesFleetDisplay(w, r, resp.Vehicle.ToStorageType())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request) {
|
|
||||||
vars := mux.Vars(r)
|
|
||||||
vehicleid := vars["vehicleid"]
|
|
||||||
|
|
||||||
if r.Method == "POST" {
|
|
||||||
w.WriteHeader(http.StatusNotFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
request := &fleets.GetVehicleRequest{
|
|
||||||
Vehicleid: vehicleid,
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := h.services.GRPC.Fleets.GetVehicle(context.TODO(), request)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
h.Renderer.VehiclesFleetUpdate(w, r, resp.Vehicle.ToStorageType())
|
|
||||||
}
|
|
||||||
|
|
||||||
func filterVehicle(r *http.Request, v *fleets.Vehicle) bool {
|
func filterVehicle(r *http.Request, v *fleets.Vehicle) bool {
|
||||||
g := r.Context().Value(identification.GroupKey)
|
g := r.Context().Value(identification.GroupKey)
|
||||||
if g == nil {
|
if g == nil {
|
||||||
|
@ -467,27 +433,85 @@ 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) {
|
////////////////////////UpdateVehicle///////////////////////
|
||||||
// request := &fleets.GetVehiclesRequest{
|
|
||||||
// Namespaces: []string{"parcoursmob"},
|
func (h *ApplicationHandler) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
// }
|
vars := mux.Vars(r)
|
||||||
// resp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), request)
|
vehicleID := vars["vehicleid"]
|
||||||
// if err != nil {
|
request := &fleets.GetVehicleRequest{
|
||||||
// fmt.Println(err)
|
Vehicleid: vehicleID,
|
||||||
// w.WriteHeader(http.StatusInternalServerError)
|
}
|
||||||
// }
|
|
||||||
// vehicles := []fleetsstorage.Vehicle{}
|
resp, err := h.services.GRPC.Fleets.GetVehicle(context.TODO(), request)
|
||||||
// fmt.Println(resp.Vehicles[0].Bookings)
|
if err != nil {
|
||||||
// for i, vehicle := range resp.Vehicles {
|
fmt.Println(err)
|
||||||
// if len(resp.Vehicles[i].Bookings) == 0 {
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
// v := vehicle.ToStorageType()
|
return
|
||||||
// vehicles = append(vehicles, v)
|
}
|
||||||
// }
|
namespaceV := resp.Vehicle.Namespace
|
||||||
// }
|
//typeV := resp.Vehicle.Type
|
||||||
// // if len(resp.Vehicle.ToStorageType().Bookings) == 0 {
|
administratorsV := resp.Vehicle.Administrators
|
||||||
// // h.Renderer.UnbookingVehicles(w, r, resp.Vehicle.ToStorageType())
|
|
||||||
// // }
|
if r.Method == "POST" {
|
||||||
// // fmt.Println(resp.Vehicle.ToStorageType().Bookings)
|
fmt.Print(r.FormValue("vehicle_type"))
|
||||||
// fmt.Println(vehicles)
|
if err := r.ParseForm(); err != nil {
|
||||||
// h.Renderer.UnbookingVehicles(w, r, vehicles)
|
fmt.Println(err)
|
||||||
// }
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dataMap := map[string]any{}
|
||||||
|
if v := r.FormValue("name"); v != "" {
|
||||||
|
dataMap["name"] = v
|
||||||
|
}
|
||||||
|
if v := r.FormValue("address"); v != "" {
|
||||||
|
var address map[string]any
|
||||||
|
err := json.Unmarshal([]byte(v), &address)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dataMap["address"] = address
|
||||||
|
}
|
||||||
|
if v := r.FormValue("informations"); v != "" {
|
||||||
|
dataMap["informations"] = v
|
||||||
|
}
|
||||||
|
if v := r.FormValue("licence_plate"); v != "" {
|
||||||
|
dataMap["licence_plate"] = v
|
||||||
|
}
|
||||||
|
if v := r.FormValue("automatic"); v != "" {
|
||||||
|
fmt.Println(v)
|
||||||
|
dataMap["automatic"] = (v == "on")
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := structpb.NewValue(dataMap)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
request := &fleets.UpdateVehicleRequest{
|
||||||
|
Vehicle: &fleets.Vehicle{
|
||||||
|
Id: vehicleID,
|
||||||
|
Namespace: namespaceV,
|
||||||
|
Type: r.FormValue("type"),
|
||||||
|
Administrators: administratorsV,
|
||||||
|
Data: data.GetStructValue(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.Fleets.UpdateVehicle(context.TODO(), request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, fmt.Sprintf("/app/vehicles-management/fleet/%s", resp.Vehicle.Id), http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
vehicles_types := h.config.GetStringSlice("modules.fleets.vehicle_types")
|
||||||
|
h.Renderer.VehiclesFleetUpdate(w, r, resp.Vehicle.ToStorageType(), vehicles_types)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue