Adjust + Test
This commit is contained in:
@@ -11,8 +11,8 @@ import (
|
||||
)
|
||||
|
||||
type ResourceMongoAccessor[T ResourceInterface] struct {
|
||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
generateData func() utils.DBObject
|
||||
utils.AbstractAccessor[ResourceInterface] // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
generateData func() utils.DBObject
|
||||
}
|
||||
|
||||
// New creates a new instance of the computeMongoAccessor
|
||||
@@ -25,10 +25,27 @@ func NewAccessor[T ResourceInterface](t tools.DataType, request *tools.APIReques
|
||||
return nil
|
||||
}
|
||||
return &ResourceMongoAccessor[T]{
|
||||
AbstractAccessor: utils.AbstractAccessor{
|
||||
AbstractAccessor: utils.AbstractAccessor[ResourceInterface]{
|
||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||
Request: request,
|
||||
Type: t,
|
||||
New: func() ResourceInterface {
|
||||
switch t {
|
||||
case tools.COMPUTE_RESOURCE:
|
||||
return &ComputeResource{}
|
||||
case tools.STORAGE_RESOURCE:
|
||||
return &StorageResource{}
|
||||
case tools.PROCESSING_RESOURCE:
|
||||
return &ProcessingResource{}
|
||||
case tools.WORKFLOW_RESOURCE:
|
||||
return &WorkflowResource{}
|
||||
case tools.DATA_RESOURCE:
|
||||
return &DataResource{}
|
||||
case tools.NATIVE_TOOL:
|
||||
return &NativeTool{}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
generateData: g,
|
||||
}
|
||||
@@ -37,9 +54,6 @@ func NewAccessor[T ResourceInterface](t tools.DataType, request *tools.APIReques
|
||||
/*
|
||||
* Nothing special here, just the basic CRUD operations
|
||||
*/
|
||||
func (dca *ResourceMongoAccessor[T]) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return utils.GenericDeleteOne(id, dca)
|
||||
}
|
||||
|
||||
func (dca *ResourceMongoAccessor[T]) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
if dca.GetType() == tools.COMPUTE_RESOURCE {
|
||||
@@ -75,20 +89,6 @@ func (dca *ResourceMongoAccessor[T]) CopyOne(data utils.DBObject) (utils.DBObjec
|
||||
return dca.StoreOne(data)
|
||||
}
|
||||
|
||||
func (dca *ResourceMongoAccessor[T]) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
return utils.GenericLoadOne[T](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||
d.(T).SetAllowedInstances(dca.Request)
|
||||
return d, 200, nil
|
||||
}, dca)
|
||||
}
|
||||
|
||||
func (wfa *ResourceMongoAccessor[T]) LoadAll(isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||
return utils.GenericLoadAll[T](func(d utils.DBObject) utils.ShallowDBObject {
|
||||
d.(T).SetAllowedInstances(wfa.Request)
|
||||
return d
|
||||
}, isDraft, wfa)
|
||||
}
|
||||
|
||||
func (wfa *ResourceMongoAccessor[T]) Search(filters *dbs.Filters, search string, isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||
if filters == nil && search == "*" {
|
||||
return utils.GenericLoadAll[T](func(d utils.DBObject) utils.ShallowDBObject {
|
||||
@@ -96,14 +96,21 @@ func (wfa *ResourceMongoAccessor[T]) Search(filters *dbs.Filters, search string,
|
||||
return d
|
||||
}, isDraft, wfa)
|
||||
}
|
||||
return utils.GenericSearch[T](filters, search, wfa.getResourceFilter(search),
|
||||
return utils.GenericSearch[T](filters, search, wfa.GetObjectFilters(search),
|
||||
func(d utils.DBObject) utils.ShallowDBObject {
|
||||
d.(T).SetAllowedInstances(wfa.Request)
|
||||
return d
|
||||
}, isDraft, wfa)
|
||||
}
|
||||
|
||||
func (abs *ResourceMongoAccessor[T]) getResourceFilter(search string) *dbs.Filters {
|
||||
func (a *ResourceMongoAccessor[T]) GetExec(isDraft bool) func(utils.DBObject) utils.ShallowDBObject {
|
||||
return func(d utils.DBObject) utils.ShallowDBObject {
|
||||
d.(T).SetAllowedInstances(a.Request)
|
||||
return d
|
||||
}
|
||||
}
|
||||
|
||||
func (abs *ResourceMongoAccessor[T]) GetObjectFilters(search string) *dbs.Filters {
|
||||
return &dbs.Filters{
|
||||
Or: map[string][]dbs.Filter{ // filter by like name, short_description, description, owner, url if no filters are provided
|
||||
"abstractintanciatedresource.abstractresource.abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
|
||||
Reference in New Issue
Block a user