65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package handlers
|
|
|
|
import (
|
|
"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()
|
|
}
|
|
|
|
// 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) UpdateBooking(booking storage.Booking) (*storage.Booking, error) {
|
|
|
|
// Store the account
|
|
if err := h.storage.UpdateBooking(booking); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &booking, nil
|
|
}
|
|
|
|
func (h FleetsHandler) DeleteBooking(id string) error {
|
|
return h.storage.DeleteBooking(id)
|
|
}
|
|
|
|
func (h FleetsHandler) GetBookings() ([]storage.Booking, error) {
|
|
bookings, err := h.storage.GetBookings()
|
|
return bookings, err
|
|
}
|
|
|
|
func (h FleetsHandler) GetDriverBookings(driver string) ([]storage.Booking, error) {
|
|
bookings, err := h.storage.GetBookingsForDriver(driver)
|
|
return bookings, err
|
|
}
|