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 resource_model
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/utils"
)
@@ -53,12 +54,16 @@ func (wfa ResourceModelMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, e
return objs, 200, nil
}
func (wfa *ResourceModelMongoAccessor) Search(word string, options ...string) ([]utils.ShallowDBObject, int, error) {
func (wfa *ResourceModelMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
if len(options) == 0 {
options = []string{"resource_type"}
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
filters = &dbs.Filters{
Or: map[string]dbs.Filter{
"resource_type": {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