84 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			84 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| 
								 | 
							
								package controllers
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import (
							 | 
						||
| 
								 | 
							
									"encoding/json"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									oclib "cloud.o-forge.io/core/oc-lib"
							 | 
						||
| 
								 | 
							
									beego "github.com/beego/beego/v2/server/web"
							 | 
						||
| 
								 | 
							
								)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// Operations about rule
							 | 
						||
| 
								 | 
							
								type RuleController struct {
							 | 
						||
| 
								 | 
							
									beego.Controller
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// @Title Search
							 | 
						||
| 
								 | 
							
								// @Description search rule
							 | 
						||
| 
								 | 
							
								// @Param	search		path 	string	true		"the word search you want to get"
							 | 
						||
| 
								 | 
							
								// @Success 200 {rule} models.rule
							 | 
						||
| 
								 | 
							
								// @router /search/:search [get]
							 | 
						||
| 
								 | 
							
								func (o *RuleController) Search() {
							 | 
						||
| 
								 | 
							
									// 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))
							 | 
						||
| 
								 | 
							
									o.ServeJSON()
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// @Title Update
							 | 
						||
| 
								 | 
							
								// @Description create rules
							 | 
						||
| 
								 | 
							
								// @Param	id		path 	string	true		"the rule id you want to get"
							 | 
						||
| 
								 | 
							
								// @Param	body		body 	models.rule	true		"The rule content"
							 | 
						||
| 
								 | 
							
								// @Success 200 {rule} models.rule
							 | 
						||
| 
								 | 
							
								// @router /:id [put]
							 | 
						||
| 
								 | 
							
								func (o *RuleController) Put() {
							 | 
						||
| 
								 | 
							
									// 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.ServeJSON()
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// @Title Create
							 | 
						||
| 
								 | 
							
								// @Description create rule
							 | 
						||
| 
								 | 
							
								// @Param	data		body 	json	true		"body for data content (Json format)"
							 | 
						||
| 
								 | 
							
								// @Success 200 {rule} models.rule
							 | 
						||
| 
								 | 
							
								// @router / [post]
							 | 
						||
| 
								 | 
							
								func (o *RuleController) Post() {
							 | 
						||
| 
								 | 
							
									var res map[string]interface{}
							 | 
						||
| 
								 | 
							
									json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
							 | 
						||
| 
								 | 
							
									o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(oclib.RULE), res)
							 | 
						||
| 
								 | 
							
									o.ServeJSON()
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// @Title GetAll
							 | 
						||
| 
								 | 
							
								// @Description find rule by id
							 | 
						||
| 
								 | 
							
								// @Success 200 {rule} models.rule
							 | 
						||
| 
								 | 
							
								// @router / [get]
							 | 
						||
| 
								 | 
							
								func (o *RuleController) GetAll() {
							 | 
						||
| 
								 | 
							
									o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.RULE))
							 | 
						||
| 
								 | 
							
									o.ServeJSON()
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// @Title Get
							 | 
						||
| 
								 | 
							
								// @Description find rule by id
							 | 
						||
| 
								 | 
							
								// @Param	id		path 	string	true		"the id you want to get"
							 | 
						||
| 
								 | 
							
								// @Success 200 {rule} models.rule
							 | 
						||
| 
								 | 
							
								// @router /:id [get]
							 | 
						||
| 
								 | 
							
								func (o *RuleController) Get() {
							 | 
						||
| 
								 | 
							
									id := o.Ctx.Input.Param(":id")
							 | 
						||
| 
								 | 
							
									o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.RULE), id)
							 | 
						||
| 
								 | 
							
									o.ServeJSON()
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// @Title Delete
							 | 
						||
| 
								 | 
							
								// @Description delete the rule
							 | 
						||
| 
								 | 
							
								// @Param	id		path 	string	true		"The id you want to delete"
							 | 
						||
| 
								 | 
							
								// @Success 200 {rule} delete success!
							 | 
						||
| 
								 | 
							
								// @router /:id [delete]
							 | 
						||
| 
								 | 
							
								func (o *RuleController) Delete() {
							 | 
						||
| 
								 | 
							
									id := o.Ctx.Input.Param(":id")
							 | 
						||
| 
								 | 
							
									o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.RULE), id)
							 | 
						||
| 
								 | 
							
									o.ServeJSON()
							 | 
						||
| 
								 | 
							
								}
							 |