add Groups
This commit is contained in:
24
models/group/group.go
Normal file
24
models/group/group.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package group
|
||||||
|
|
||||||
|
import (
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Group is a struct that represents a Group
|
||||||
|
type Group struct {
|
||||||
|
utils.AbstractObject
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ao *Group) VerifyAuth(callName string, request *tools.APIRequest) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Group) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||||
|
data := NewAccessor(request) // Create a new instance of the accessor
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Group) CanDelete() bool {
|
||||||
|
return false // only draft order can be deleted
|
||||||
|
}
|
||||||
78
models/group/group_mongo_accessor.go
Normal file
78
models/group/group_mongo_accessor.go
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
package group
|
||||||
|
|
||||||
|
import (
|
||||||
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/logs"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
|
)
|
||||||
|
|
||||||
|
type groupMongoAccessor struct {
|
||||||
|
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates a new instance of the groupMongoAccessor
|
||||||
|
func NewShallowAccessor() *groupMongoAccessor {
|
||||||
|
return &groupMongoAccessor{
|
||||||
|
AbstractAccessor: utils.AbstractAccessor{
|
||||||
|
Logger: logs.CreateLogger(tools.GROUP.String()), // Create a logger with the data type
|
||||||
|
Type: tools.GROUP,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAccessor(request *tools.APIRequest) *groupMongoAccessor {
|
||||||
|
return &groupMongoAccessor{
|
||||||
|
AbstractAccessor: utils.AbstractAccessor{
|
||||||
|
Logger: logs.CreateLogger(tools.GROUP.String()), // Create a logger with the data type
|
||||||
|
Request: request,
|
||||||
|
Type: tools.GROUP,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Nothing special here, just the basic CRUD operations
|
||||||
|
*/
|
||||||
|
|
||||||
|
func (wfa *groupMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||||
|
return utils.GenericDeleteOne(id, wfa)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (wfa *groupMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||||
|
return utils.GenericUpdateOne(set.(*Group), id, wfa, &Group{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (wfa *groupMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||||
|
return utils.GenericStoreOne(data.(*Group), wfa)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (wfa *groupMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||||
|
return utils.GenericStoreOne(data, wfa)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dca *groupMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
|
return utils.GenericLoadOne[*Group](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||||
|
return d, 200, nil
|
||||||
|
}, dca)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (wfa *groupMongoAccessor) LoadAll(isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||||
|
return utils.GenericLoadAll[*Group](func(d utils.DBObject) utils.ShallowDBObject {
|
||||||
|
return d
|
||||||
|
}, isDraft, wfa)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (wfa *groupMongoAccessor) Search(filters *dbs.Filters, search string, isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||||
|
return utils.GenericSearch[*Group](filters, search, wfa.GetDefaultFilter(search),
|
||||||
|
func(d utils.DBObject) utils.ShallowDBObject {
|
||||||
|
return d
|
||||||
|
}, isDraft, wfa)
|
||||||
|
}
|
||||||
|
func (a *groupMongoAccessor) GetDefaultFilter(search string) *dbs.Filters {
|
||||||
|
return &dbs.Filters{
|
||||||
|
Or: map[string][]dbs.Filter{ // search by name if no filters are provided
|
||||||
|
"abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package models
|
|||||||
import (
|
import (
|
||||||
"cloud.o-forge.io/core/oc-lib/logs"
|
"cloud.o-forge.io/core/oc-lib/logs"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/bill"
|
"cloud.o-forge.io/core/oc-lib/models/bill"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/group"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/live"
|
"cloud.o-forge.io/core/oc-lib/models/live"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/order"
|
"cloud.o-forge.io/core/oc-lib/models/order"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/purchase_resource"
|
"cloud.o-forge.io/core/oc-lib/models/resources/purchase_resource"
|
||||||
@@ -44,6 +45,7 @@ var ModelsCatalog = map[string]func() utils.DBObject{
|
|||||||
tools.LIVE_DATACENTER.String(): func() utils.DBObject { return &live.LiveDatacenter{} },
|
tools.LIVE_DATACENTER.String(): func() utils.DBObject { return &live.LiveDatacenter{} },
|
||||||
tools.LIVE_STORAGE.String(): func() utils.DBObject { return &live.LiveStorage{} },
|
tools.LIVE_STORAGE.String(): func() utils.DBObject { return &live.LiveStorage{} },
|
||||||
tools.BILL.String(): func() utils.DBObject { return &bill.Bill{} },
|
tools.BILL.String(): func() utils.DBObject { return &bill.Bill{} },
|
||||||
|
tools.GROUP.String(): func() utils.DBObject { return &group.Group{} },
|
||||||
}
|
}
|
||||||
|
|
||||||
// Model returns the model object based on the model type
|
// Model returns the model object based on the model type
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const (
|
|||||||
WORKFLOW_EXECUTION
|
WORKFLOW_EXECUTION
|
||||||
WORKSPACE
|
WORKSPACE
|
||||||
PEER
|
PEER
|
||||||
|
GROUP
|
||||||
COLLABORATIVE_AREA
|
COLLABORATIVE_AREA
|
||||||
RULE
|
RULE
|
||||||
BOOKING
|
BOOKING
|
||||||
@@ -61,6 +62,7 @@ var DefaultAPI = [...]string{
|
|||||||
NOAPI,
|
NOAPI,
|
||||||
WORKSPACEAPI,
|
WORKSPACEAPI,
|
||||||
PEERSAPI,
|
PEERSAPI,
|
||||||
|
PEERSAPI,
|
||||||
SHAREDAPI,
|
SHAREDAPI,
|
||||||
SHAREDAPI,
|
SHAREDAPI,
|
||||||
DATACENTERAPI,
|
DATACENTERAPI,
|
||||||
@@ -93,6 +95,7 @@ var Str = [...]string{
|
|||||||
"workflow_execution",
|
"workflow_execution",
|
||||||
"workspace",
|
"workspace",
|
||||||
"peer",
|
"peer",
|
||||||
|
"peer",
|
||||||
"collaborative_area",
|
"collaborative_area",
|
||||||
"rule",
|
"rule",
|
||||||
"booking",
|
"booking",
|
||||||
@@ -132,7 +135,7 @@ func (d DataType) EnumIndex() int {
|
|||||||
|
|
||||||
func DataTypeList() []DataType {
|
func DataTypeList() []DataType {
|
||||||
return []DataType{DATA_RESOURCE, PROCESSING_RESOURCE, STORAGE_RESOURCE, COMPUTE_RESOURCE, WORKFLOW_RESOURCE,
|
return []DataType{DATA_RESOURCE, PROCESSING_RESOURCE, STORAGE_RESOURCE, COMPUTE_RESOURCE, WORKFLOW_RESOURCE,
|
||||||
WORKFLOW, WORKFLOW_EXECUTION, WORKSPACE, PEER, COLLABORATIVE_AREA, RULE, BOOKING, WORKFLOW_HISTORY, WORKSPACE_HISTORY,
|
WORKFLOW, WORKFLOW_EXECUTION, WORKSPACE, PEER, GROUP, COLLABORATIVE_AREA, RULE, BOOKING, WORKFLOW_HISTORY, WORKSPACE_HISTORY,
|
||||||
ORDER, PURCHASE_RESOURCE, ADMIRALTY_SOURCE, ADMIRALTY_TARGET, ADMIRALTY_SECRET, ADMIRALTY_KUBECONFIG, ADMIRALTY_NODES,
|
ORDER, PURCHASE_RESOURCE, ADMIRALTY_SOURCE, ADMIRALTY_TARGET, ADMIRALTY_SECRET, ADMIRALTY_KUBECONFIG, ADMIRALTY_NODES,
|
||||||
LIVE_DATACENTER, LIVE_STORAGE, BILL, NATIVE_TOOL}
|
LIVE_DATACENTER, LIVE_STORAGE, BILL, NATIVE_TOOL}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user