A question refers to the comment ! And if not Ooopsy
This commit is contained in:
		| @@ -8,11 +8,14 @@ import ( | ||||
| 	"github.com/google/uuid" | ||||
| ) | ||||
|  | ||||
| /* | ||||
| * Rule is a struct that represents a rule of a shared workspace | ||||
|  */ | ||||
| type Rule struct { | ||||
| 	utils.AbstractObject | ||||
| 	Description string   `json:"description,omitempty" bson:"description,omitempty"` | ||||
| 	Condition   string   `json:"condition,omitempty" bson:"condition,omitempty"` | ||||
| 	Actions     []string `json:"actions,omitempty" bson:"actions,omitempty"` | ||||
| 	utils.AbstractObject          // AbstractObject contains the basic fields of an object (id, name) | ||||
| 	Description          string   `json:"description,omitempty" bson:"description,omitempty"` // Description is the description of the rule | ||||
| 	Condition            string   `json:"condition,omitempty" bson:"condition,omitempty"`     // NOT DEFINITIVE TO SPECIFICATION | ||||
| 	Actions              []string `json:"actions,omitempty" bson:"actions,omitempty"`         // NOT DEFINITIVE TO SPECIFICATION | ||||
| } | ||||
|  | ||||
| func (ao *Rule) GetID() string { | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| package rule  | ||||
| package rule | ||||
|  | ||||
| import ( | ||||
| 	"cloud.o-forge.io/core/oc-lib/dbs" | ||||
| @@ -10,18 +10,22 @@ type ruleMongoAccessor struct { | ||||
| 	utils.AbstractAccessor | ||||
| } | ||||
|  | ||||
| // New creates a new instance of the ruleMongoAccessor | ||||
| func New() *ruleMongoAccessor { | ||||
| 	return &ruleMongoAccessor{} | ||||
| } | ||||
|  | ||||
| // GetType returns the type of the rule | ||||
| func (wfa *ruleMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) { | ||||
| 	return wfa.GenericDeleteOne(id, wfa) | ||||
| } | ||||
|  | ||||
| // UpdateOne updates a rule in the database | ||||
| func (wfa *ruleMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) { | ||||
| 	return wfa.GenericUpdateOne(set.(*Rule), id, wfa, &Rule{}) | ||||
| } | ||||
|  | ||||
| // StoreOne stores a rule in the database | ||||
| func (wfa *ruleMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) { | ||||
| 	return wfa.GenericStoreOne(data.(*Rule), wfa) | ||||
| } | ||||
| @@ -30,6 +34,7 @@ func (wfa *ruleMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, | ||||
| 	return wfa.GenericStoreOne(data, wfa) | ||||
| } | ||||
|  | ||||
| // LoadOne loads a rule from the database | ||||
| func (wfa *ruleMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) { | ||||
| 	var rule Rule | ||||
| 	res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType()) | ||||
| @@ -41,6 +46,7 @@ func (wfa *ruleMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) { | ||||
| 	return &rule, 200, nil | ||||
| } | ||||
|  | ||||
| // LoadAll loads all rules from the database | ||||
| func (wfa ruleMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) { | ||||
| 	objs := []utils.ShallowDBObject{} | ||||
| 	res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType()) | ||||
| @@ -58,11 +64,12 @@ func (wfa ruleMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) { | ||||
| 	return objs, 200, nil | ||||
| } | ||||
|  | ||||
| // Search searches for rules in the database, given some filters OR a search string | ||||
| func (wfa *ruleMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) { | ||||
| 	objs := []utils.ShallowDBObject{} | ||||
| 	if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" { | ||||
| 		filters = &dbs.Filters{ | ||||
| 			Or: map[string][]dbs.Filter{ | ||||
| 			Or: map[string][]dbs.Filter{ // filter by name if no filters are provided | ||||
| 				"abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}}, | ||||
| 			}, | ||||
| 		} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user