Offset + Limit
This commit is contained in:
@@ -2,6 +2,7 @@ package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
@@ -36,12 +37,16 @@ func (o *PurchaseController) Post() {
|
||||
// @Title GetAll
|
||||
// @Description find compute by id
|
||||
// @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
|
||||
// @router / [get]
|
||||
func (o *PurchaseController) GetAll() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -49,13 +54,17 @@ func (o *PurchaseController) GetAll() {
|
||||
// @Description find compute by key word
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @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
|
||||
// @router /search/:search [get]
|
||||
func (o *PurchaseController) Search() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"oc-catalog/infrastructure"
|
||||
"strconv"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
@@ -60,13 +62,15 @@ func (o *ResourceController) notFound() {
|
||||
func (o *ResourceController) GetAll() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
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{}
|
||||
for _, col := range o.collection(false) {
|
||||
if m[col.String()] == nil {
|
||||
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...)
|
||||
}
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
@@ -88,13 +92,15 @@ 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")
|
||||
offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset"))
|
||||
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
||||
|
||||
m := map[string][]utils.ShallowDBObject{}
|
||||
for _, col := range o.collection(false) {
|
||||
if m[col.String()] == nil {
|
||||
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...)
|
||||
|
||||
}
|
||||
@@ -116,7 +122,7 @@ func (o *ResourceController) Search() {
|
||||
func (o *ResourceController) Get() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user