package handlers import ( "time" "git.coopgo.io/coopgo-platform/fleets/storage" "github.com/google/uuid" ) func (h FleetsHandler) AddVehicle(vehicle storage.Vehicle) (*storage.Vehicle, error) { if vehicle.ID == "" { vehicle.ID = uuid.NewString() } vehicle.Metadata = map[string]any{ "created": time.Now(), } // Store the account if err := h.storage.CreateVehicle(vehicle); err != nil { return nil, err } return &vehicle, nil } func (h FleetsHandler) GetVehicle(id string) (vehicle *storage.Vehicle, err error) { vehicle, err = h.storage.GetVehicle(id) if err != nil { return nil, err } bookings, err := h.storage.GetBookingsForVehicle(id) if err != nil { return nil, err } vehicle.Bookings = bookings return vehicle, nil } func (h FleetsHandler) GetVehicles(namespaces []string) ([]storage.Vehicle, error) { vehicles, err := h.storage.GetVehicles(namespaces) newvehicles := []storage.Vehicle{} for _, v := range vehicles { bookings, err := h.storage.GetBookingsForVehicle(v.ID) if err != nil { return nil, err } v.Bookings = bookings newvehicles = append(newvehicles, v) } return newvehicles, err }