add extend
This commit is contained in:
@@ -5,10 +5,10 @@ import (
|
||||
"fmt"
|
||||
"oc-catalog/infrastructure"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
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"
|
||||
)
|
||||
@@ -56,6 +56,7 @@ func (o *ResourceController) notFound() {
|
||||
|
||||
// @Title GetAll
|
||||
// @Description list all resources across all types
|
||||
// @Param extend query string false "extend"
|
||||
// @Param type path string true "the type you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Param offset query string false "offset wished"
|
||||
@@ -65,16 +66,20 @@ func (o *ResourceController) notFound() {
|
||||
func (o *ResourceController) GetAll() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
extend := strings.Split(o.Ctx.Input.Query("extend"), ",")
|
||||
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
||||
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
||||
|
||||
m := map[string][]utils.ShallowDBObject{}
|
||||
m := map[string][]map[string]interface{}{}
|
||||
for _, col := range o.collection(false) {
|
||||
if m[col.String()] == nil {
|
||||
m[col.String()] = []utils.ShallowDBObject{}
|
||||
m[col.String()] = []map[string]interface{}{}
|
||||
}
|
||||
s := oclib.NewRequest(col, user, peerID, groups, nil).LoadAll(isDraft == "true", int64(offset), int64(limit))
|
||||
m[col.String()] = append(m[col.String()], s.Data...)
|
||||
for _, d := range s.Data {
|
||||
m[col.String()] = append(m[col.String()], oclib.GetExtend(d, d.Extend(extend...)))
|
||||
}
|
||||
|
||||
}
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": m,
|
||||
@@ -88,7 +93,8 @@ func (o *ResourceController) GetAll() {
|
||||
// @Description search resources across all types
|
||||
// @Param type path string true "the type you want to get"
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Param is_draft query string false "draft wished"$
|
||||
// @Param extend query string false "extend"
|
||||
// @Param offset query string false "offset wished"
|
||||
// @Param limit query string false "limit wished"
|
||||
// @Success 200 {resource} models.resource
|
||||
@@ -97,16 +103,19 @@ func (o *ResourceController) Search() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
extend := strings.Split(o.Ctx.Input.Query("extend"), ",")
|
||||
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
||||
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
||||
|
||||
m := map[string][]utils.ShallowDBObject{}
|
||||
m := map[string][]map[string]interface{}{}
|
||||
for _, col := range o.collection(false) {
|
||||
if m[col.String()] == nil {
|
||||
m[col.String()] = []utils.ShallowDBObject{}
|
||||
m[col.String()] = []map[string]interface{}{}
|
||||
}
|
||||
s := oclib.NewRequest(col, user, peerID, groups, nil).Search(nil, search, isDraft == "true", int64(offset), int64(limit))
|
||||
m[col.String()] = append(m[col.String()], s.Data...)
|
||||
for _, d := range s.Data {
|
||||
m[col.String()] = append(m[col.String()], oclib.GetExtend(d, d.Extend(extend...)))
|
||||
}
|
||||
|
||||
}
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
@@ -139,6 +148,7 @@ func GetResource(typ oclib.LibDataEnum) interface{} {
|
||||
// @Title Search
|
||||
// @Description search workspace
|
||||
// @Param is_draft query string false
|
||||
// @Param extend query string false "extend"
|
||||
// @Param offset query string false
|
||||
// @Param limit query string false
|
||||
// @Param data body json true "body for data content (Json format)"
|
||||
@@ -148,20 +158,24 @@ 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")
|
||||
extend := strings.Split(o.Ctx.Input.Query("extend"), ",")
|
||||
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{}
|
||||
m := map[string][]map[string]interface{}{}
|
||||
for _, col := range o.collection(false) {
|
||||
if m[col.String()] == nil {
|
||||
m[col.String()] = []utils.ShallowDBObject{}
|
||||
m[col.String()] = []map[string]interface{}{}
|
||||
}
|
||||
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...)
|
||||
for _, d := range s.Data {
|
||||
m[col.String()] = append(m[col.String()], oclib.GetExtend(d, d.Extend(extend...)))
|
||||
}
|
||||
|
||||
}
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": m,
|
||||
@@ -176,15 +190,17 @@ func (o *ResourceController) SearchExtended() {
|
||||
// @Param type path string true "the type you want to get"
|
||||
// @Param id path string true "the id you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Param extend query string false "extend"
|
||||
// @Success 200 {resource} models.resource
|
||||
// @router /:type/:id [get]
|
||||
func (o *ResourceController) Get() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
extend := strings.Split(o.Ctx.Input.Query("extend"), ",")
|
||||
fmt.Println(user, groups, peerID)
|
||||
for _, col := range o.collection(false) {
|
||||
if d := oclib.NewRequest(col, user, peerID, groups, nil).LoadOne(id); d.Data != nil {
|
||||
o.Data["json"] = d
|
||||
o.Data["json"] = oclib.GetExtend(d.Data, d.Data.Extend(extend...))
|
||||
break
|
||||
} else {
|
||||
o.Data["json"] = d
|
||||
|
||||
Reference in New Issue
Block a user