36 lines
828 B
Go
36 lines
828 B
Go
package storage
|
|
|
|
import "time"
|
|
|
|
const (
|
|
StatusOld = -1
|
|
StatusOngoing = 0
|
|
StatusForthcoming = 1
|
|
)
|
|
|
|
type Booking struct {
|
|
ID string `json:"id" bson:"_id"`
|
|
Vehicleid string `json:"vehicleid"`
|
|
Driver string `json:"driver"`
|
|
Startdate time.Time `json:"startdate"`
|
|
Enddate time.Time `json:"enddate"`
|
|
Unavailablefrom time.Time `json:"unavailablefrom"`
|
|
Unavailableto time.Time `json:"unavailableto"`
|
|
Data map[string]any `json:"data"`
|
|
|
|
Deleted bool `json:"deleted"`
|
|
Vehicle Vehicle `json:"vehicle" bson:"-"`
|
|
}
|
|
|
|
func (b Booking) Status() int {
|
|
now := time.Now()
|
|
|
|
if b.Enddate.Before(now) {
|
|
return StatusOld
|
|
} else if b.Startdate.After(now) {
|
|
return StatusForthcoming
|
|
} else {
|
|
return StatusOngoing
|
|
}
|
|
}
|