light modification

This commit is contained in:
mr 2025-01-20 13:49:39 +01:00
parent 58b36f2823
commit 67b8215adf
4 changed files with 10 additions and 6 deletions

View File

@ -11,6 +11,7 @@ type ResourceInterface interface {
utils.DBObject
Trim()
ConvertToPricedResource(t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF
GetType() string
SetAllowedInstances(request *tools.APIRequest)
SetResourceModel(model *resource_model.ResourceModel)
}

View File

@ -34,7 +34,7 @@ type AbstractResource struct {
}
func (r *AbstractResource) GetType() string {
return r.Type
return tools.INVALID.String()
}
func (r *AbstractResource) StoreDraftDefault() {
@ -85,7 +85,6 @@ func (abs *AbstractIntanciatedResource[T]) SetAllowedInstances(request *tools.AP
}
func (d *AbstractIntanciatedResource[T]) Trim() {
d.AbstractResource.AbstractObject.Type = d.GetType()
if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: d.CreatorID}}).IsMySelf(); !ok {
for _, instance := range d.Instances {
instance.ClearPeerGroups()

View File

@ -69,10 +69,13 @@ func (dca *resourceMongoAccessor[T]) LoadOne(id string) (utils.DBObject, int, er
func (wfa *resourceMongoAccessor[T]) LoadAll(isDraft bool) ([]utils.ShallowDBObject, int, error) {
resources, _, err := wfa.ResourceModelAccessor.Search(nil, wfa.GetType().String(), isDraft)
return utils.GenericLoadAll[T](func(d utils.DBObject) utils.ShallowDBObject {
d.(T).SetAllowedInstances(wfa.Request)
if d.(T).GetType() != wfa.GetType().String() {
return nil
}
if err == nil && len(resources) > 0 {
d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel))
}
d.(T).SetAllowedInstances(wfa.Request)
return d
}, isDraft, wfa)
}
@ -81,10 +84,13 @@ func (wfa *resourceMongoAccessor[T]) Search(filters *dbs.Filters, search string,
resources, _, err := wfa.ResourceModelAccessor.Search(nil, wfa.GetType().String(), false)
return utils.GenericSearch[T](filters, search, wfa.getResourceFilter(search),
func(d utils.DBObject) utils.ShallowDBObject {
d.(T).SetAllowedInstances(wfa.Request)
if d.(T).GetType() != wfa.GetType().String() {
return nil
}
if err == nil && len(resources) > 0 {
d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel))
}
d.(T).SetAllowedInstances(wfa.Request)
return d
}, isDraft, wfa)
}
@ -96,7 +102,6 @@ func (abs *resourceMongoAccessor[T]) getResourceFilter(search string) *dbs.Filte
return &dbs.Filters{
Or: map[string][]dbs.Filter{ // filter by like name, short_description, description, owner, url if no filters are provided
"abstractintanciatedresource.abstractresource.abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
"abstractintanciatedresource.abstractresource.abstractobject.type": {{Operator: dbs.LIKE.String(), Value: search}},
"abstractintanciatedresource.abstractresource.short_description": {{Operator: dbs.LIKE.String(), Value: search}},
"abstractintanciatedresource.abstractresource.description": {{Operator: dbs.LIKE.String(), Value: search}},
"abstractintanciatedresource.abstractresource.owners.name": {{Operator: dbs.LIKE.String(), Value: search}},

View File

@ -31,7 +31,6 @@ type AbstractObject struct {
Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"`
IsDraft bool `json:"is_draft" bson:"is_draft" default:"false"`
CreatorID string `json:"creator_id" bson:"creator_id" default:"unknown"`
Type string `json:"type,omitempty" bson:"type,omitempty"`
CreationDate time.Time `json:"creation_date" bson:"creation_date"`
UpdateDate time.Time `json:"update_date" bson:"update_date"`
UpdaterID string `json:"updater_id" bson:"updater_id"`