SearchExtended
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
oclib "cloud.o-forge.io/core/oc-lib"
|
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/models/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
beego "github.com/beego/beego/v2/server/web"
|
beego "github.com/beego/beego/v2/server/web"
|
||||||
@@ -116,6 +117,60 @@ func (o *ResourceController) Search() {
|
|||||||
o.ServeJSON()
|
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
|
// @Title Get
|
||||||
// @Description search resources across all types
|
// @Description search resources across all types
|
||||||
// @Param type path string true "the type you want to get"
|
// @Param type path string true "the type you want to get"
|
||||||
|
|||||||
@@ -214,6 +214,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: 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.GlobalControllerRouter["oc-catalog/controllers:ResourceController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:ResourceController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "Search",
|
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}": {
|
"/resource/{type}/search/{search}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
|
|||||||
@@ -390,6 +390,36 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: '{resource} models.resource'
|
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}:
|
/resource/{type}/search/{search}:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
Reference in New Issue
Block a user