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"
|
||||
|
||||
@@ -214,6 +214,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["oc-catalog/controllers:ResourceController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:ResourceController"],
|
||||
beego.ControllerComments{
|
||||
Method: "SearchExtended",
|
||||
Router: `/:type/extended/search`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["oc-catalog/controllers:ResourceController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:ResourceController"],
|
||||
beego.ControllerComments{
|
||||
Method: "Search",
|
||||
|
||||
@@ -415,6 +415,49 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/resource/{type}/extended/search": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"resource"
|
||||
],
|
||||
"description": "search workspace\n\u003cbr\u003e",
|
||||
"operationId": "ResourceController.Search",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "is_draft",
|
||||
"description": "false",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "query",
|
||||
"name": "offset",
|
||||
"description": "false",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "query",
|
||||
"name": "limit",
|
||||
"description": "false",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "body",
|
||||
"name": "data",
|
||||
"description": "body for data content (Json format)",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "{workspace} models.workspace"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/resource/{type}/search/{search}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
|
||||
@@ -390,6 +390,36 @@ paths:
|
||||
responses:
|
||||
"200":
|
||||
description: '{resource} models.resource'
|
||||
/resource/{type}/extended/search:
|
||||
post:
|
||||
tags:
|
||||
- resource
|
||||
description: |-
|
||||
search workspace
|
||||
<br>
|
||||
operationId: ResourceController.Search
|
||||
parameters:
|
||||
- in: query
|
||||
name: is_draft
|
||||
description: "false"
|
||||
type: string
|
||||
- in: query
|
||||
name: offset
|
||||
description: "false"
|
||||
type: string
|
||||
- in: query
|
||||
name: limit
|
||||
description: "false"
|
||||
type: string
|
||||
- in: body
|
||||
name: data
|
||||
description: body for data content (Json format)
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/json'
|
||||
responses:
|
||||
"200":
|
||||
description: '{workspace} models.workspace'
|
||||
/resource/{type}/search/{search}:
|
||||
get:
|
||||
tags:
|
||||
|
||||
Reference in New Issue
Block a user