This commit is contained in:
mr 2024-10-30 10:16:13 +01:00
parent c34e5579fc
commit 1a55212378

View File

@ -1,6 +1,8 @@
package peer package peer
import ( import (
"strconv"
"cloud.o-forge.io/core/oc-lib/dbs" "cloud.o-forge.io/core/oc-lib/dbs"
"cloud.o-forge.io/core/oc-lib/dbs/mongo" "cloud.o-forge.io/core/oc-lib/dbs/mongo"
"cloud.o-forge.io/core/oc-lib/models/utils" "cloud.o-forge.io/core/oc-lib/models/utils"
@ -67,6 +69,14 @@ func (wfa peerMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
func (wfa *peerMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) { func (wfa *peerMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{} objs := []utils.ShallowDBObject{}
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" { if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
s, err := strconv.Atoi(search)
if err == nil {
filters = &dbs.Filters{
Or: map[string][]dbs.Filter{ // search by name if no filters are provided
"state": {{Operator: dbs.LIKE.String(), Value: s}},
},
}
} else {
filters = &dbs.Filters{ filters = &dbs.Filters{
Or: map[string][]dbs.Filter{ // search by name if no filters are provided Or: map[string][]dbs.Filter{ // search by name if no filters are provided
"abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}}, "abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
@ -74,6 +84,7 @@ func (wfa *peerMongoAccessor) Search(filters *dbs.Filters, search string) ([]uti
}, },
} }
} }
}
res_mongo, code, err := mongo.MONGOService.Search(filters, wfa.GetType()) res_mongo, code, err := mongo.MONGOService.Search(filters, wfa.GetType())
if err != nil { if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error()) wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())