56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
|
package handlers
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
|
||
|
"git.coopgo.io/coopgo-platform/fleets/storage"
|
||
|
"github.com/google/uuid"
|
||
|
)
|
||
|
|
||
|
func (h FleetsHandler) AddBooking(booking storage.Booking) (*storage.Booking, error) {
|
||
|
if booking.ID == "" {
|
||
|
booking.ID = uuid.NewString()
|
||
|
}
|
||
|
|
||
|
// vehicle.Metadata = map[string]any{
|
||
|
// "created": time.Now(),
|
||
|
// }
|
||
|
|
||
|
// Store the account
|
||
|
if err := h.storage.CreateBooking(booking); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return &booking, nil
|
||
|
}
|
||
|
|
||
|
func (h FleetsHandler) GetBooking(id string) (booking *storage.Booking, err error) {
|
||
|
booking, err = h.storage.GetBooking(id)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
if booking.Deleted {
|
||
|
return nil, errors.New("booking was deleted")
|
||
|
}
|
||
|
|
||
|
vehicle, err := h.storage.GetVehicle(booking.Vehicleid)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
booking.Vehicle = *vehicle
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (h FleetsHandler) DeleteBooking(id string) error {
|
||
|
return h.storage.DeleteBooking(id)
|
||
|
}
|
||
|
|
||
|
// func (h FleetsHandler) GetVehicles(namespaces []string) ([]storage.Vehicle, error) {
|
||
|
// vehicles, err := h.storage.GetVehicles(namespaces)
|
||
|
// return vehicles, err
|
||
|
// }
|