All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 5m22s
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package storage
|
|
|
|
import "time"
|
|
|
|
const (
|
|
StatusOld = -1
|
|
StatusOngoing = 0
|
|
StatusForthcoming = 1
|
|
)
|
|
|
|
type StatusHistoryEntry struct {
|
|
FromStatus string `json:"from_status" bson:"from_status"`
|
|
ToStatus string `json:"to_status" bson:"to_status"`
|
|
UserID string `json:"user_id" bson:"user_id"`
|
|
UserName string `json:"user_name" bson:"user_name"`
|
|
GroupID string `json:"group_id" bson:"group_id"`
|
|
GroupName string `json:"group_name" bson:"group_name"`
|
|
Date time.Time `json:"date" bson:"date"`
|
|
Comment string `json:"comment" bson:"comment"`
|
|
}
|
|
|
|
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:"-"`
|
|
|
|
ManualStatus string `json:"manual_status" bson:"manual_status"`
|
|
StatusHistory []StatusHistoryEntry `json:"status_history" bson:"status_history"`
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|