COMPLEX SEARCH

This commit is contained in:
mr
2024-08-01 09:13:10 +02:00
parent ad455e0e3a
commit 924a688a9d
14 changed files with 240 additions and 90 deletions

View File

@@ -1,6 +1,7 @@
package workspace
import (
"cloud.o-forge.io/core/oc-lib/dbs"
"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"
@@ -135,12 +136,16 @@ func (wfa workspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error
return objs, 200, nil
}
func (wfa *workspaceMongoAccessor) Search(word string, options ...string) ([]utils.ShallowDBObject, int, error) {
func (wfa *workspaceMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
if len(options) == 0 {
options = []string{"abstractobject.name"}
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
filters = &dbs.Filters{
Or: map[string]dbs.Filter{
"abstractobject.name": {Operator: dbs.LIKE.String(), Value: search},
},
}
}
res_mongo, code, err := mongo.MONGOService.Search(word, options, wfa.GetType())
res_mongo, code, err := mongo.MONGOService.Search(*filters, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err