Offset + Limit

This commit is contained in:
mr
2026-04-03 14:23:55 +02:00
parent 163a4165b8
commit 31e8a2589f
5 changed files with 28 additions and 7 deletions

View File

@@ -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()
}