32 lines
1.0 KiB
Go
32 lines
1.0 KiB
Go
|
package buying_status
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||
|
)
|
||
|
|
||
|
type BuyingStatus struct {
|
||
|
utils.AbstractObject
|
||
|
BuyingDate time.Time `json:"buying_date" bson:"buying_date" validate:"required"`
|
||
|
EndBuyingDate *time.Time `json:"end_buying_date,omitempty" bson:"end_buying_date,omitempty"`
|
||
|
ResourceID string `json:"resource_id" bson:"resource_id" validate:"required"`
|
||
|
ResourceType tools.DataType `json:"resource_type" bson:"resource_type" validate:"required"`
|
||
|
}
|
||
|
|
||
|
func (d *BuyingStatus) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||
|
return NewAccessor(request) // Create a new instance of the accessor
|
||
|
}
|
||
|
|
||
|
func (r *BuyingStatus) CanUpdate(set utils.DBObject) (bool, utils.DBObject) {
|
||
|
return r.IsDraft, set // only draft buying can be updated
|
||
|
}
|
||
|
|
||
|
func (r *BuyingStatus) CanDelete() bool { // ENDBuyingDate is passed
|
||
|
if r.EndBuyingDate != nil {
|
||
|
return time.Now().UTC().After(*r.EndBuyingDate)
|
||
|
}
|
||
|
return false // only draft bookings can be deleted
|
||
|
}
|