Adjust + Test
This commit is contained in:
@@ -4,23 +4,31 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
type computeUnitsMongoAccessor[T LiveInterface] struct {
|
||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
utils.AbstractAccessor[LiveInterface] // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
}
|
||||
|
||||
// New creates a new instance of the computeUnitsMongoAccessor
|
||||
func NewAccessor[T LiveInterface](t tools.DataType, request *tools.APIRequest) *computeUnitsMongoAccessor[T] {
|
||||
return &computeUnitsMongoAccessor[T]{
|
||||
AbstractAccessor: utils.AbstractAccessor{
|
||||
AbstractAccessor: utils.AbstractAccessor[LiveInterface]{
|
||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||
Request: request,
|
||||
Type: t,
|
||||
New: func() LiveInterface {
|
||||
switch t {
|
||||
case tools.LIVE_DATACENTER:
|
||||
return &LiveDatacenter{}
|
||||
case tools.LIVE_STORAGE:
|
||||
return &LiveStorage{}
|
||||
}
|
||||
return &LiveDatacenter{}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -28,19 +36,6 @@ func NewAccessor[T LiveInterface](t tools.DataType, request *tools.APIRequest) *
|
||||
/*
|
||||
* Nothing special here, just the basic CRUD operations
|
||||
*/
|
||||
func (a *computeUnitsMongoAccessor[T]) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return utils.GenericDeleteOne(id, a)
|
||||
}
|
||||
|
||||
func (a *computeUnitsMongoAccessor[T]) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
// should verify if a source is existing...
|
||||
return utils.GenericUpdateOne(set, id, a, &LiveDatacenter{})
|
||||
}
|
||||
|
||||
func (a *computeUnitsMongoAccessor[T]) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return utils.GenericStoreOne(data.(*LiveDatacenter), a)
|
||||
}
|
||||
|
||||
func (a *computeUnitsMongoAccessor[T]) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
// is a publisher... that become a resources.
|
||||
if data.IsDrafted() {
|
||||
@@ -95,23 +90,3 @@ func (a *computeUnitsMongoAccessor[T]) CopyOne(data utils.DBObject) (utils.DBObj
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *computeUnitsMongoAccessor[T]) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
return utils.GenericLoadOne[T](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||
return d, 200, nil
|
||||
}, a)
|
||||
}
|
||||
|
||||
func (a *computeUnitsMongoAccessor[T]) LoadAll(isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||
return utils.GenericLoadAll[T](a.getExec(), isDraft, a)
|
||||
}
|
||||
|
||||
func (a *computeUnitsMongoAccessor[T]) Search(filters *dbs.Filters, search string, isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||
return utils.GenericSearch[*LiveDatacenter](filters, search, (&LiveDatacenter{}).GetObjectFilters(search), a.getExec(), isDraft, a)
|
||||
}
|
||||
|
||||
func (a *computeUnitsMongoAccessor[T]) getExec() func(utils.DBObject) utils.ShallowDBObject {
|
||||
return func(d utils.DBObject) utils.ShallowDBObject {
|
||||
return d
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user