Adjust + Test
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"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/enum"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
@@ -12,16 +11,17 @@ import (
|
||||
)
|
||||
|
||||
type BookingMongoAccessor struct {
|
||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
utils.AbstractAccessor[*Booking] // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
}
|
||||
|
||||
// New creates a new instance of the BookingMongoAccessor
|
||||
func NewAccessor(request *tools.APIRequest) *BookingMongoAccessor {
|
||||
return &BookingMongoAccessor{
|
||||
AbstractAccessor: utils.AbstractAccessor{
|
||||
AbstractAccessor: utils.AbstractAccessor[*Booking]{
|
||||
Logger: logs.CreateLogger(tools.BOOKING.String()), // Create a logger with the data type
|
||||
Request: request,
|
||||
Type: tools.BOOKING,
|
||||
New: func() *Booking { return &Booking{} },
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,6 @@ func NewAccessor(request *tools.APIRequest) *BookingMongoAccessor {
|
||||
/*
|
||||
* Nothing special here, just the basic CRUD operations
|
||||
*/
|
||||
func (a *BookingMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return utils.GenericDeleteOne(id, a)
|
||||
}
|
||||
|
||||
func (a *BookingMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
if set.(*Booking).State == 0 {
|
||||
return nil, 400, errors.New("state is required")
|
||||
@@ -41,14 +37,6 @@ func (a *BookingMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.D
|
||||
return utils.GenericUpdateOne(realSet, id, a, &Booking{})
|
||||
}
|
||||
|
||||
func (a *BookingMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return utils.GenericStoreOne(data, a)
|
||||
}
|
||||
|
||||
func (a *BookingMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return utils.GenericStoreOne(data, a)
|
||||
}
|
||||
|
||||
func (a *BookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
return utils.GenericLoadOne[*Booking](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||
now := time.Now()
|
||||
@@ -67,15 +55,7 @@ func (a *BookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
}, 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, 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 {
|
||||
func (a *BookingMongoAccessor) GetExec(isDraft bool) func(utils.DBObject) utils.ShallowDBObject {
|
||||
return func(d utils.DBObject) utils.ShallowDBObject {
|
||||
now := time.Now()
|
||||
now = now.Add(time.Second * -60)
|
||||
|
||||
Reference in New Issue
Block a user