working oc-shared

This commit is contained in:
mr
2025-01-17 17:20:37 +01:00
parent 3b65fb934b
commit 7d391e4059
7 changed files with 201 additions and 40 deletions

View File

@@ -15,12 +15,15 @@ type RuleController struct {
// @Title Search
// @Description search rule
// @Param search path string true "the word search you want to get"
// @Param is_draft query string false "draft wished"
// @Success 200 {rule} models.rule
// @router /search/:search [get]
func (o *RuleController) Search() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
// store and return Id or post with UUID
search := o.Ctx.Input.Param(":search")
o.Data["json"] = oclib.Search(nil, search, oclib.LibDataEnum(oclib.RULE))
isDraft := o.Ctx.Input.Query("is_draft")
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.RULE), user, peerID, groups, nil).Search(nil, search, isDraft == "true")
o.ServeJSON()
}
@@ -31,11 +34,12 @@ func (o *RuleController) Search() {
// @Success 200 {rule} models.rule
// @router /:id [put]
func (o *RuleController) Put() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
// store and return ID or post with UUID
var res map[string]interface{}
id := o.Ctx.Input.Param(":id")
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.RULE), res, id)
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.RULE), user, peerID, groups, nil).UpdateOne(res, id)
o.ServeJSON()
}
@@ -45,18 +49,22 @@ func (o *RuleController) Put() {
// @Success 200 {rule} models.rule
// @router / [post]
func (o *RuleController) Post() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
var res map[string]interface{}
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(oclib.RULE), res)
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.RULE), user, peerID, groups, nil).StoreOne(res)
o.ServeJSON()
}
// @Title GetAll
// @Description find rule by id
// @Param is_draft query string false "draft wished"
// @Success 200 {rule} models.rule
// @router / [get]
func (o *RuleController) GetAll() {
o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.RULE))
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
isDraft := o.Ctx.Input.Query("is_draft")
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.RULE), user, peerID, groups, nil).LoadAll(isDraft == "true")
o.ServeJSON()
}
@@ -66,8 +74,9 @@ func (o *RuleController) GetAll() {
// @Success 200 {rule} models.rule
// @router /:id [get]
func (o *RuleController) Get() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.RULE), id)
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.RULE), user, peerID, groups, nil).LoadOne(id)
o.ServeJSON()
}
@@ -77,7 +86,8 @@ func (o *RuleController) Get() {
// @Success 200 {rule} delete success!
// @router /:id [delete]
func (o *RuleController) Delete() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.RULE), id)
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.RULE), user, peerID, groups, nil).DeleteOne(id)
o.ServeJSON()
}