This commit is contained in:
mr
2026-04-29 07:47:44 +02:00
parent 6a3ce4a35b
commit c03b43f844
11 changed files with 194 additions and 58 deletions

View File

@@ -3,8 +3,10 @@ package controllers
import (
"encoding/json"
"strconv"
"strings"
oclib "cloud.o-forge.io/core/oc-lib"
"cloud.o-forge.io/core/oc-lib/tools"
beego "github.com/beego/beego/v2/server/web"
)
@@ -36,6 +38,7 @@ func (o *PurchaseController) Post() {
// @Title GetAll
// @Description find compute by id
// @Param extend query string false "extend"
// @Param is_draft query string false "draft wished"
// @Param offset query string false "offset wished"
// @Param limit query string false "limit wished"
@@ -44,14 +47,21 @@ func (o *PurchaseController) Post() {
func (o *PurchaseController) 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"))
o.Data["json"] = oclib.NewRequest(purchase_collection, user, peerID, groups, nil).LoadAll(isDraft == "true", int64(offset), int64(limit))
s := oclib.NewRequest(purchase_collection, user, peerID, groups, nil).LoadAll(isDraft == "true", int64(offset), int64(limit))
o.Data["json"] = map[string]interface{}{
"data": oclib.GetExtends(s.Data, extend...),
"code": 200,
"err": nil,
}
o.ServeJSON()
}
// @Title Get
// @Description find compute by key word
// @Param extend query string false "extend"
// @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"
@@ -62,20 +72,38 @@ 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")
extend := strings.Split(o.Ctx.Input.Query("extend"), ",")
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))
s := oclib.NewRequest(purchase_collection, user, peerID, groups, nil).Search(nil, search, isDraft == "true", int64(offset), int64(limit))
o.Data["json"] = map[string]interface{}{
"data": oclib.GetExtends(s.Data, extend...),
"code": 200,
"err": nil,
}
o.ServeJSON()
}
// @Title Get
// @Description find compute by id
// @Param extend query string false "extend"
// @Param id path string true "the id you want to get"
// @Success 200 {compute} models.compute
// @router /:id [get]
func (o *PurchaseController) Get() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.NewRequest(purchase_collection, user, peerID, groups, nil).LoadOne(id)
extend := strings.Split(o.Ctx.Input.Query("extend"), ",")
data := oclib.NewRequest(purchase_collection, user, peerID, groups, nil).LoadOne(id)
if data.Data != nil {
m := oclib.GetExtend(data.Data, data.Data.Extend(extend...), map[tools.DataType]map[string]interface{}{})
o.Data["json"] = map[string]interface{}{
"data": m,
"code": 200,
"err": nil,
}
} else {
o.Data["json"] = data
}
o.ServeJSON()
}