peer change
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
type PolicyController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description get all policies
|
||||
// @Param is_draft query string false
|
||||
// @Param offset query string false
|
||||
// @Param limit query string false
|
||||
// @Success 200 {policy} policy.Policy
|
||||
// @router / [get]
|
||||
func (o *PolicyController) 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"))
|
||||
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.POLICY), user, peerID, groups, nil).LoadAll(isDraft == "true", int64(offset), int64(limit))
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description get policy by id
|
||||
// @Param id path string true "the policy id"
|
||||
// @Success 200 {policy} policy.Policy
|
||||
// @router /:id [get]
|
||||
func (o *PolicyController) Get() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.POLICY), user, peerID, groups, nil).LoadOne(id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Post
|
||||
// @Description create a policy
|
||||
// @Param data body json true "policy body"
|
||||
// @Success 200 {policy} policy.Policy
|
||||
// @router / [post]
|
||||
func (o *PolicyController) Post() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
var body map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(100000), &body)
|
||||
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.POLICY), user, peerID, groups, nil).StoreOne(body)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Put
|
||||
// @Description update a policy
|
||||
// @Param id path string true "the policy id"
|
||||
// @Param data body json true "policy body"
|
||||
// @Success 200 {policy} policy.Policy
|
||||
// @router /:id [put]
|
||||
func (o *PolicyController) Put() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
var body map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(100000), &body)
|
||||
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.POLICY), user, peerID, groups, nil).UpdateOne(body, id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Delete
|
||||
// @Description delete a policy
|
||||
// @Param id path string true "the policy id"
|
||||
// @Success 200 {policy} policy.Policy
|
||||
// @router /:id [delete]
|
||||
func (o *PolicyController) Delete() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.POLICY), user, peerID, groups, nil).DeleteOne(id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
Reference in New Issue
Block a user