Offset + Limit
This commit is contained in:
@@ -2,6 +2,7 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
oclib "cloud.o-forge.io/core/oc-lib"
|
oclib "cloud.o-forge.io/core/oc-lib"
|
||||||
beego "github.com/beego/beego/v2/server/web"
|
beego "github.com/beego/beego/v2/server/web"
|
||||||
@@ -36,12 +37,16 @@ func (o *PurchaseController) Post() {
|
|||||||
// @Title GetAll
|
// @Title GetAll
|
||||||
// @Description find compute by id
|
// @Description find compute by id
|
||||||
// @Param is_draft query string false "draft wished"
|
// @Param is_draft query string false "draft wished"
|
||||||
|
// @Param offset query string false "offset wished"
|
||||||
|
// @Param limit query string false "limit wished"
|
||||||
// @Success 200 {compute} models.compute
|
// @Success 200 {compute} models.compute
|
||||||
// @router / [get]
|
// @router / [get]
|
||||||
func (o *PurchaseController) GetAll() {
|
func (o *PurchaseController) 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")
|
||||||
o.Data["json"] = oclib.NewRequest(purchase_collection, user, peerID, groups, nil).LoadAll(isDraft == "true")
|
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
||||||
|
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
||||||
|
o.Data["json"] = oclib.NewRequest(purchase_collection, user, peerID, groups, nil).LoadAll(isDraft == "true", int64(offset), int64(limit))
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,13 +54,17 @@ func (o *PurchaseController) GetAll() {
|
|||||||
// @Description find compute by key word
|
// @Description find compute by key word
|
||||||
// @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 offset query string false "offset wished"
|
||||||
|
// @Param limit query string false "limit wished"
|
||||||
// @Success 200 {compute} models.compute
|
// @Success 200 {compute} models.compute
|
||||||
// @router /search/:search [get]
|
// @router /search/:search [get]
|
||||||
func (o *PurchaseController) Search() {
|
func (o *PurchaseController) 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")
|
||||||
o.Data["json"] = oclib.NewRequest(purchase_collection, user, peerID, groups, nil).Search(nil, search, isDraft == "true")
|
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
||||||
|
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
||||||
|
o.Data["json"] = oclib.NewRequest(purchase_collection, user, peerID, groups, nil).Search(nil, search, isDraft == "true", int64(offset), int64(limit))
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"oc-catalog/infrastructure"
|
"oc-catalog/infrastructure"
|
||||||
|
"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/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
@@ -60,13 +62,15 @@ 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")
|
||||||
|
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
||||||
|
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
||||||
|
|
||||||
m := map[string][]utils.ShallowDBObject{}
|
m := map[string][]utils.ShallowDBObject{}
|
||||||
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()] = []utils.ShallowDBObject{}
|
||||||
}
|
}
|
||||||
s := oclib.NewRequest(col, user, peerID, groups, nil).LoadAll(isDraft == "true")
|
s := oclib.NewRequest(col, user, peerID, groups, nil).LoadAll(isDraft == "true", int64(offset), int64(limit))
|
||||||
m[col.String()] = append(m[col.String()], s.Data...)
|
m[col.String()] = append(m[col.String()], s.Data...)
|
||||||
}
|
}
|
||||||
o.Data["json"] = map[string]interface{}{
|
o.Data["json"] = map[string]interface{}{
|
||||||
@@ -88,13 +92,15 @@ 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")
|
||||||
|
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
||||||
|
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
||||||
|
|
||||||
m := map[string][]utils.ShallowDBObject{}
|
m := map[string][]utils.ShallowDBObject{}
|
||||||
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()] = []utils.ShallowDBObject{}
|
||||||
}
|
}
|
||||||
s := oclib.NewRequest(col, user, peerID, groups, nil).Search(nil, search, isDraft == "true")
|
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...)
|
m[col.String()] = append(m[col.String()], s.Data...)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -116,7 +122,7 @@ func (o *ResourceController) Search() {
|
|||||||
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")
|
||||||
|
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"] = 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-20260401110447-20cac09f9d6f
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260403121807-913d9b3dfb0a
|
||||||
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
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -4,6 +4,12 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20260331181901-f3b5a54545ee h1:iJ1kgMbBOBIHw
|
|||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20260331181901-f3b5a54545ee/go.mod h1:+ENuvBfZdESSvecoqGY/wSvRlT3vinEolxKgwbOhUpA=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260331181901-f3b5a54545ee/go.mod h1:+ENuvBfZdESSvecoqGY/wSvRlT3vinEolxKgwbOhUpA=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20260401110447-20cac09f9d6f h1:yyp4UIBTEQWcmoD2T+Acb6dZfl7PWaLSRPwlpEOQxnE=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260401110447-20cac09f9d6f h1:yyp4UIBTEQWcmoD2T+Acb6dZfl7PWaLSRPwlpEOQxnE=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20260401110447-20cac09f9d6f/go.mod h1:+ENuvBfZdESSvecoqGY/wSvRlT3vinEolxKgwbOhUpA=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260401110447-20cac09f9d6f/go.mod h1:+ENuvBfZdESSvecoqGY/wSvRlT3vinEolxKgwbOhUpA=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260402074304-ad12f02a7024 h1:xxadsmNJoXdbzK+GsHtCLoKBmowe3n52iZtFZy0PVjk=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260402074304-ad12f02a7024/go.mod h1:+ENuvBfZdESSvecoqGY/wSvRlT3vinEolxKgwbOhUpA=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260402080126-2bc45557938b h1:jkvJ1+aiitFPlc+/8U1Z3Ss8UwxdUQhoh3NarZuT/ow=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260402080126-2bc45557938b/go.mod h1:+ENuvBfZdESSvecoqGY/wSvRlT3vinEolxKgwbOhUpA=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260403121807-913d9b3dfb0a h1:H7K91js08Vyx307MW6BwQ/kqNGTrQVMaR3xvrIrc2W8=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20260403121807-913d9b3dfb0a/go.mod h1:+ENuvBfZdESSvecoqGY/wSvRlT3vinEolxKgwbOhUpA=
|
||||||
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=
|
||||||
|
|||||||
@@ -442,7 +442,7 @@ func findProcessingResourceByName(accessor utils.Accessor, name string) *resourc
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, draft := range []bool{false, true} {
|
for _, draft := range []bool{false, true} {
|
||||||
results, _, _ := accessor.Search(filters, "", draft)
|
results, _, _ := accessor.Search(filters, "", draft, 0, 10)
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
if pr, ok := r.(*resources.ProcessingResource); ok && pr.GetName() == name {
|
if pr, ok := r.(*resources.ProcessingResource); ok && pr.GetName() == name {
|
||||||
return pr
|
return pr
|
||||||
|
|||||||
Reference in New Issue
Block a user