SearchExtended

This commit is contained in:
mr
2026-04-08 11:45:36 +02:00
parent ffa7dfe87d
commit 11649788f5
4 changed files with 137 additions and 0 deletions

View File

@@ -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"