SearchExtended
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
@@ -116,6 +117,60 @@ func (o *ResourceController) Search() {
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
func GetResource(typ oclib.LibDataEnum) interface{} {
|
||||
if typ == oclib.LibDataEnum(oclib.PROCESSING_RESOURCE) {
|
||||
return &resources.ProcessingResource{}
|
||||
}
|
||||
if typ == oclib.LibDataEnum(oclib.STORAGE_RESOURCE) {
|
||||
return &resources.StorageResource{}
|
||||
}
|
||||
if typ == oclib.LibDataEnum(oclib.COMPUTE_RESOURCE) {
|
||||
return &resources.ComputeResource{}
|
||||
}
|
||||
if typ == oclib.LibDataEnum(oclib.DATA_RESOURCE) {
|
||||
return &resources.DataResource{}
|
||||
}
|
||||
if typ == oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE) {
|
||||
return &resources.WorkflowResource{}
|
||||
}
|
||||
return &resources.AbstractResource{}
|
||||
}
|
||||
|
||||
// @Title Search
|
||||
// @Description search workspace
|
||||
// @Param is_draft query string false
|
||||
// @Param offset query string false
|
||||
// @Param limit query string false
|
||||
// @Param data body json true "body for data content (Json format)"
|
||||
// @Success 200 {workspace} models.workspace
|
||||
// @router /:type/extended/search [post]
|
||||
func (o *ResourceController) SearchExtended() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
// store and return Id or post with UUIDLibDataEnum
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
||||
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
||||
var res map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(100000), &res)
|
||||
m := map[string][]utils.ShallowDBObject{}
|
||||
for _, col := range o.collection(false) {
|
||||
if m[col.String()] == nil {
|
||||
m[col.String()] = []utils.ShallowDBObject{}
|
||||
}
|
||||
fmt.Println(res, oclib.FiltersFromFlatMap(res, GetResource(col)))
|
||||
|
||||
s := oclib.NewRequest(col, user, peerID, groups, nil).Search(
|
||||
oclib.FiltersFromFlatMap(res, GetResource(col)), "", isDraft == "true", int64(offset), int64(limit))
|
||||
m[col.String()] = append(m[col.String()], s.Data...)
|
||||
}
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": m,
|
||||
"code": 200,
|
||||
"err": nil,
|
||||
}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description search resources across all types
|
||||
// @Param type path string true "the type you want to get"
|
||||
|
||||
Reference in New Issue
Block a user