Resource Buy & Limitation
This commit is contained in:
@@ -55,6 +55,16 @@ func NewAccessor[T ResourceInterface](t tools.DataType, request *tools.APIReques
|
||||
* Nothing special here, just the basic CRUD operations
|
||||
*/
|
||||
|
||||
func (dca *ResourceMongoAccessor[T]) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
data, code, err := dca.AbstractAccessor.LoadOne(id)
|
||||
if err == nil {
|
||||
data.(T).VerifyBuy()
|
||||
data.(T).SetAllowedInstances(dca.Request)
|
||||
return data, code, err
|
||||
}
|
||||
return data, code, err
|
||||
}
|
||||
|
||||
func (dca *ResourceMongoAccessor[T]) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
if dca.GetType() == tools.COMPUTE_RESOURCE {
|
||||
return nil, 404, errors.New("can't update a non existing computing units resource not reported onto compute units catalog")
|
||||
@@ -87,12 +97,14 @@ func (wfa *ResourceMongoAccessor[T]) LoadAll(isDraft bool, offset int64, limit i
|
||||
func (wfa *ResourceMongoAccessor[T]) Search(filters *dbs.Filters, search string, isDraft bool, offset int64, limit int64) ([]utils.ShallowDBObject, int, error) {
|
||||
if filters == nil && search == "*" {
|
||||
return utils.GenericLoadAll[T](func(d utils.DBObject) utils.ShallowDBObject {
|
||||
d.(T).VerifyBuy()
|
||||
d.(T).SetAllowedInstances(wfa.Request)
|
||||
return d
|
||||
}, isDraft, wfa, offset, limit)
|
||||
}
|
||||
return utils.GenericSearch[T](filters, search, wfa.GetObjectFilters(search),
|
||||
func(d utils.DBObject) utils.ShallowDBObject {
|
||||
d.(T).VerifyBuy()
|
||||
d.(T).SetAllowedInstances(wfa.Request)
|
||||
return d
|
||||
}, isDraft, wfa, offset, limit)
|
||||
@@ -100,6 +112,7 @@ func (wfa *ResourceMongoAccessor[T]) Search(filters *dbs.Filters, search string,
|
||||
|
||||
func (a *ResourceMongoAccessor[T]) GetExec(isDraft bool) func(utils.DBObject) utils.ShallowDBObject {
|
||||
return func(d utils.DBObject) utils.ShallowDBObject {
|
||||
d.(T).VerifyBuy()
|
||||
d.(T).SetAllowedInstances(a.Request)
|
||||
return d
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user