private accessor

This commit is contained in:
mr
2024-07-31 10:35:03 +02:00
parent 7ae1399a9a
commit 00fe19083b
10 changed files with 49 additions and 36 deletions

View File

@@ -1,8 +1,6 @@
package workspace
import (
"errors"
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
"cloud.o-forge.io/core/oc-lib/models/resources/data"
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
@@ -52,9 +50,6 @@ func (wfa *workspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject
d.StorageResources = nil
d.ProcessingResources = nil
d.WorkflowResources = nil
if res, _, _ := wfa.Search(d.Name); len(res) > 0 {
return nil, 409, errors.New("Workspace with name " + d.Name + " already exists")
}
return wfa.GenericStoreOne(d, wfa)
}
@@ -140,9 +135,12 @@ func (wfa workspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error
return objs, 200, nil
}
func (wfa *workspaceMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
func (wfa *workspaceMongoAccessor) Search(word string, options ...string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"abstractobject.name"}, wfa.GetType())
if len(options) == 0 {
options = []string{"abstractobject.name"}
}
res_mongo, code, err := mongo.MONGOService.Search(word, options, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err