add extend
This commit is contained in:
@@ -5,10 +5,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"oc-catalog/infrastructure"
|
"oc-catalog/infrastructure"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
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/resources"
|
||||||
"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"
|
||||||
)
|
)
|
||||||
@@ -56,6 +56,7 @@ func (o *ResourceController) notFound() {
|
|||||||
|
|
||||||
// @Title GetAll
|
// @Title GetAll
|
||||||
// @Description list all resources across all types
|
// @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 type path string true "the type you want to get"
|
||||||
// @Param is_draft query string false "draft wished"
|
// @Param is_draft query string false "draft wished"
|
||||||
// @Param offset query string false "offset wished"
|
// @Param offset query string false "offset wished"
|
||||||
@@ -65,16 +66,20 @@ func (o *ResourceController) notFound() {
|
|||||||
func (o *ResourceController) GetAll() {
|
func (o *ResourceController) GetAll() {
|
||||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||||
isDraft := o.Ctx.Input.Query("is_draft")
|
isDraft := o.Ctx.Input.Query("is_draft")
|
||||||
|
extend := strings.Split(o.Ctx.Input.Query("extend"), ",")
|
||||||
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
||||||
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
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) {
|
for _, col := range o.collection(false) {
|
||||||
if m[col.String()] == nil {
|
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))
|
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{}{
|
o.Data["json"] = map[string]interface{}{
|
||||||
"data": m,
|
"data": m,
|
||||||
@@ -88,7 +93,8 @@ func (o *ResourceController) GetAll() {
|
|||||||
// @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"
|
||||||
// @Param search path string true "the search 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 offset query string false "offset wished"
|
||||||
// @Param limit query string false "limit wished"
|
// @Param limit query string false "limit wished"
|
||||||
// @Success 200 {resource} models.resource
|
// @Success 200 {resource} models.resource
|
||||||
@@ -97,16 +103,19 @@ func (o *ResourceController) Search() {
|
|||||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||||
isDraft := o.Ctx.Input.Query("is_draft")
|
isDraft := o.Ctx.Input.Query("is_draft")
|
||||||
search := o.Ctx.Input.Param(":search")
|
search := o.Ctx.Input.Param(":search")
|
||||||
|
extend := strings.Split(o.Ctx.Input.Query("extend"), ",")
|
||||||
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
||||||
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
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) {
|
for _, col := range o.collection(false) {
|
||||||
if m[col.String()] == nil {
|
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))
|
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{}{
|
o.Data["json"] = map[string]interface{}{
|
||||||
@@ -139,6 +148,7 @@ func GetResource(typ oclib.LibDataEnum) interface{} {
|
|||||||
// @Title Search
|
// @Title Search
|
||||||
// @Description search workspace
|
// @Description search workspace
|
||||||
// @Param is_draft query string false
|
// @Param is_draft query string false
|
||||||
|
// @Param extend query string false "extend"
|
||||||
// @Param offset query string false
|
// @Param offset query string false
|
||||||
// @Param limit query string false
|
// @Param limit query string false
|
||||||
// @Param data body json true "body for data content (Json format)"
|
// @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)
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||||
// store and return Id or post with UUIDLibDataEnum
|
// store and return Id or post with UUIDLibDataEnum
|
||||||
isDraft := o.Ctx.Input.Query("is_draft")
|
isDraft := o.Ctx.Input.Query("is_draft")
|
||||||
|
extend := strings.Split(o.Ctx.Input.Query("extend"), ",")
|
||||||
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
||||||
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
||||||
var res map[string]interface{}
|
var res map[string]interface{}
|
||||||
json.Unmarshal(o.Ctx.Input.CopyBody(100000), &res)
|
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) {
|
for _, col := range o.collection(false) {
|
||||||
if m[col.String()] == nil {
|
if m[col.String()] == nil {
|
||||||
m[col.String()] = []utils.ShallowDBObject{}
|
m[col.String()] = []map[string]interface{}{}
|
||||||
}
|
}
|
||||||
fmt.Println(res, oclib.FiltersFromFlatMap(res, GetResource(col)))
|
fmt.Println(res, oclib.FiltersFromFlatMap(res, GetResource(col)))
|
||||||
|
|
||||||
s := oclib.NewRequest(col, user, peerID, groups, nil).Search(
|
s := oclib.NewRequest(col, user, peerID, groups, nil).Search(
|
||||||
oclib.FiltersFromFlatMap(res, GetResource(col)), "", isDraft == "true", int64(offset), int64(limit))
|
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{}{
|
o.Data["json"] = map[string]interface{}{
|
||||||
"data": m,
|
"data": m,
|
||||||
@@ -176,15 +190,17 @@ func (o *ResourceController) SearchExtended() {
|
|||||||
// @Param type path string true "the type you want to get"
|
// @Param type path string true "the type you want to get"
|
||||||
// @Param id path string true "the id you want to get"
|
// @Param id path string true "the id 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"
|
||||||
// @Success 200 {resource} models.resource
|
// @Success 200 {resource} models.resource
|
||||||
// @router /:type/:id [get]
|
// @router /:type/:id [get]
|
||||||
func (o *ResourceController) Get() {
|
func (o *ResourceController) Get() {
|
||||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||||
id := o.Ctx.Input.Param(":id")
|
id := o.Ctx.Input.Param(":id")
|
||||||
|
extend := strings.Split(o.Ctx.Input.Query("extend"), ",")
|
||||||
fmt.Println(user, groups, peerID)
|
fmt.Println(user, groups, peerID)
|
||||||
for _, col := range o.collection(false) {
|
for _, col := range o.collection(false) {
|
||||||
if d := oclib.NewRequest(col, user, peerID, groups, nil).LoadOne(id); d.Data != nil {
|
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
|
break
|
||||||
} else {
|
} else {
|
||||||
o.Data["json"] = d
|
o.Data["json"] = d
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module oc-catalog
|
|||||||
go 1.25.0
|
go 1.25.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20260408143421-92eb2663bc69
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260421124504-0c6efee27626
|
||||||
github.com/beego/beego/v2 v2.3.8
|
github.com/beego/beego/v2 v2.3.8
|
||||||
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674
|
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674
|
||||||
github.com/smartystreets/goconvey v1.7.2
|
github.com/smartystreets/goconvey v1.7.2
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -16,6 +16,10 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20260407073631-5dbe55e63081 h1:Fl08ZK6LrzkyF
|
|||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20260407073631-5dbe55e63081/go.mod h1:+ENuvBfZdESSvecoqGY/wSvRlT3vinEolxKgwbOhUpA=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260407073631-5dbe55e63081/go.mod h1:+ENuvBfZdESSvecoqGY/wSvRlT3vinEolxKgwbOhUpA=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20260408143421-92eb2663bc69 h1:3QmJSTWSUoq1pVXsCLv0+nmmKBVwcdHXMp+GTFaVZQA=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260408143421-92eb2663bc69 h1:3QmJSTWSUoq1pVXsCLv0+nmmKBVwcdHXMp+GTFaVZQA=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20260408143421-92eb2663bc69/go.mod h1:+ENuvBfZdESSvecoqGY/wSvRlT3vinEolxKgwbOhUpA=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260408143421-92eb2663bc69/go.mod h1:+ENuvBfZdESSvecoqGY/wSvRlT3vinEolxKgwbOhUpA=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260421123652-bbaea4fec401 h1:S4Bz4mudEx7IUthnHdmZVKwVmc2r2Tw5L6J9hYiXqr8=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260421123652-bbaea4fec401/go.mod h1:JynnOb3eMr9VZW1mHq+Vsl3tzx6gPhPsGKpQD/dtEBc=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260421124504-0c6efee27626 h1:JOXbpVUlz5D3ajT48+2N4lmULb+c4/o2WAAHc60XbeA=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260421124504-0c6efee27626/go.mod h1:JynnOb3eMr9VZW1mHq+Vsl3tzx6gPhPsGKpQD/dtEBc=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
|
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
|
||||||
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
|
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
|
||||||
|
|||||||
Reference in New Issue
Block a user