massive draft for payment process (UNCOMPLETE)
This commit is contained in:
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
@@ -15,15 +15,12 @@ type bookingMongoAccessor struct {
|
||||
}
|
||||
|
||||
// New creates a new instance of the bookingMongoAccessor
|
||||
func New(t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller) *bookingMongoAccessor {
|
||||
func NewAccessor(request *tools.APIRequest) *bookingMongoAccessor {
|
||||
return &bookingMongoAccessor{
|
||||
AbstractAccessor: utils.AbstractAccessor{
|
||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||
Caller: caller,
|
||||
PeerID: peerID,
|
||||
Groups: groups,
|
||||
User: username, // Set the caller
|
||||
Type: t,
|
||||
Logger: logs.CreateLogger(tools.BOOKING.String()), // Create a logger with the data type
|
||||
Request: request,
|
||||
Type: tools.BOOKING,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -49,26 +46,29 @@ func (a *bookingMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int
|
||||
|
||||
func (a *bookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
return utils.GenericLoadOne[*Booking](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||
if d.(*Booking).State == workflow_execution.SCHEDULED && time.Now().UTC().After(*d.(*Booking).ExecDate) {
|
||||
d.(*Booking).State = workflow_execution.FORGOTTEN
|
||||
if (d.(*Booking).ExpectedEndDate) == nil {
|
||||
d.(*Booking).State = common.FORGOTTEN
|
||||
utils.GenericRawUpdateOne(d, id, a)
|
||||
} else if d.(*Booking).State == common.SCHEDULED && time.Now().UTC().After(*&d.(*Booking).ExpectedStartDate) {
|
||||
d.(*Booking).State = common.DELAYED
|
||||
utils.GenericRawUpdateOne(d, id, a)
|
||||
}
|
||||
return d, 200, nil
|
||||
}, a)
|
||||
}
|
||||
|
||||
func (a *bookingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
return utils.GenericLoadAll[*Booking](a.getExec(), a)
|
||||
func (a *bookingMongoAccessor) LoadAll(isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||
return utils.GenericLoadAll[*Booking](a.getExec(), isDraft, a)
|
||||
}
|
||||
|
||||
func (a *bookingMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
||||
return utils.GenericSearch[*Booking](filters, search, (&Booking{}).GetObjectFilters(search), a.getExec(), a)
|
||||
func (a *bookingMongoAccessor) Search(filters *dbs.Filters, search string, isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||
return utils.GenericSearch[*Booking](filters, search, (&Booking{}).GetObjectFilters(search), a.getExec(), isDraft, a)
|
||||
}
|
||||
|
||||
func (a *bookingMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
|
||||
return func(d utils.DBObject) utils.ShallowDBObject {
|
||||
if d.(*Booking).State == workflow_execution.SCHEDULED && time.Now().UTC().After(*d.(*Booking).ExecDate) {
|
||||
d.(*Booking).State = workflow_execution.FORGOTTEN
|
||||
if d.(*Booking).State == common.SCHEDULED && time.Now().UTC().After(*&d.(*Booking).ExpectedStartDate) {
|
||||
d.(*Booking).State = common.DELAYED
|
||||
utils.GenericRawUpdateOne(d, d.GetID(), a)
|
||||
}
|
||||
return d
|
||||
|
||||
Reference in New Issue
Block a user