mirror of
https://github.com/beego/bee.git
synced 2024-11-22 10:10:53 +00:00
change this to short name
This commit is contained in:
parent
930049f7de
commit
976602bc01
44
apiapp.go
44
apiapp.go
@ -303,12 +303,12 @@ type ObjectController struct {
|
|||||||
// @Success 200 {string} models.Object.Id
|
// @Success 200 {string} models.Object.Id
|
||||||
// @Failure 403 body is empty
|
// @Failure 403 body is empty
|
||||||
// @router / [post]
|
// @router / [post]
|
||||||
func (this *ObjectController) Post() {
|
func (o *ObjectController) Post() {
|
||||||
var ob models.Object
|
var ob models.Object
|
||||||
json.Unmarshal(this.Ctx.Input.RequestBody, &ob)
|
json.Unmarshal(o.Ctx.Input.RequestBody, &ob)
|
||||||
objectid := models.AddOne(ob)
|
objectid := models.AddOne(ob)
|
||||||
this.Data["json"] = map[string]string{"ObjectId": objectid}
|
o.Data["json"] = map[string]string{"ObjectId": objectid}
|
||||||
this.ServeJson()
|
o.ServeJson()
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Title Get
|
// @Title Get
|
||||||
@ -317,17 +317,17 @@ func (this *ObjectController) Post() {
|
|||||||
// @Success 200 {object} models.Object
|
// @Success 200 {object} models.Object
|
||||||
// @Failure 403 :objectId is empty
|
// @Failure 403 :objectId is empty
|
||||||
// @router /:objectId [get]
|
// @router /:objectId [get]
|
||||||
func (this *ObjectController) Get() {
|
func (o *ObjectController) Get() {
|
||||||
objectId := this.Ctx.Input.Params[":objectId"]
|
objectId := o.Ctx.Input.Params[":objectId"]
|
||||||
if objectId != "" {
|
if objectId != "" {
|
||||||
ob, err := models.GetOne(objectId)
|
ob, err := models.GetOne(objectId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Data["json"] = err
|
o.Data["json"] = err
|
||||||
} else {
|
} else {
|
||||||
this.Data["json"] = ob
|
o.Data["json"] = ob
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.ServeJson()
|
o.ServeJson()
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Title GetAll
|
// @Title GetAll
|
||||||
@ -335,10 +335,10 @@ func (this *ObjectController) Get() {
|
|||||||
// @Success 200 {object} models.Object
|
// @Success 200 {object} models.Object
|
||||||
// @Failure 403 :objectId is empty
|
// @Failure 403 :objectId is empty
|
||||||
// @router / [get]
|
// @router / [get]
|
||||||
func (this *ObjectController) GetAll() {
|
func (o *ObjectController) GetAll() {
|
||||||
obs := models.GetAll()
|
obs := models.GetAll()
|
||||||
this.Data["json"] = obs
|
o.Data["json"] = obs
|
||||||
this.ServeJson()
|
o.ServeJson()
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Title update
|
// @Title update
|
||||||
@ -348,18 +348,18 @@ func (this *ObjectController) GetAll() {
|
|||||||
// @Success 200 {object} models.Object
|
// @Success 200 {object} models.Object
|
||||||
// @Failure 403 :objectId is empty
|
// @Failure 403 :objectId is empty
|
||||||
// @router /:objectId [put]
|
// @router /:objectId [put]
|
||||||
func (this *ObjectController) Put() {
|
func (o *ObjectController) Put() {
|
||||||
objectId := this.Ctx.Input.Params[":objectId"]
|
objectId := o.Ctx.Input.Params[":objectId"]
|
||||||
var ob models.Object
|
var ob models.Object
|
||||||
json.Unmarshal(this.Ctx.Input.RequestBody, &ob)
|
json.Unmarshal(o.Ctx.Input.RequestBody, &ob)
|
||||||
|
|
||||||
err := models.Update(objectId, ob.Score)
|
err := models.Update(objectId, ob.Score)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Data["json"] = err
|
o.Data["json"] = err
|
||||||
} else {
|
} else {
|
||||||
this.Data["json"] = "update success!"
|
o.Data["json"] = "update success!"
|
||||||
}
|
}
|
||||||
this.ServeJson()
|
o.ServeJson()
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Title delete
|
// @Title delete
|
||||||
@ -368,11 +368,11 @@ func (this *ObjectController) Put() {
|
|||||||
// @Success 200 {string} delete success!
|
// @Success 200 {string} delete success!
|
||||||
// @Failure 403 objectId is empty
|
// @Failure 403 objectId is empty
|
||||||
// @router /:objectId [delete]
|
// @router /:objectId [delete]
|
||||||
func (this *ObjectController) Delete() {
|
func (o *ObjectController) Delete() {
|
||||||
objectId := this.Ctx.Input.Params[":objectId"]
|
objectId := o.Ctx.Input.Params[":objectId"]
|
||||||
models.Delete(objectId)
|
models.Delete(objectId)
|
||||||
this.Data["json"] = "delete success!"
|
o.Data["json"] = "delete success!"
|
||||||
this.ServeJson()
|
o.ServeJson()
|
||||||
}
|
}
|
||||||
|
|
||||||
`
|
`
|
||||||
|
78
g_appcode.go
78
g_appcode.go
@ -1147,12 +1147,12 @@ type {{ctrlName}}Controller struct {
|
|||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *{{ctrlName}}Controller) URLMapping() {
|
func (c *{{ctrlName}}Controller) URLMapping() {
|
||||||
this.Mapping("Post", this.Post)
|
c.Mapping("Post", c.Post)
|
||||||
this.Mapping("GetOne", this.GetOne)
|
c.Mapping("GetOne", c.GetOne)
|
||||||
this.Mapping("GetAll", this.GetAll)
|
c.Mapping("GetAll", c.GetAll)
|
||||||
this.Mapping("Put", this.Put)
|
c.Mapping("Put", c.Put)
|
||||||
this.Mapping("Delete", this.Delete)
|
c.Mapping("Delete", c.Delete)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Title Post
|
// @Title Post
|
||||||
@ -1161,15 +1161,15 @@ func (this *{{ctrlName}}Controller) URLMapping() {
|
|||||||
// @Success 200 {int} models.{{ctrlName}}.Id
|
// @Success 200 {int} models.{{ctrlName}}.Id
|
||||||
// @Failure 403 body is empty
|
// @Failure 403 body is empty
|
||||||
// @router / [post]
|
// @router / [post]
|
||||||
func (this *{{ctrlName}}Controller) Post() {
|
func (c *{{ctrlName}}Controller) Post() {
|
||||||
var v models.{{ctrlName}}
|
var v models.{{ctrlName}}
|
||||||
json.Unmarshal(this.Ctx.Input.RequestBody, &v)
|
json.Unmarshal(c.Ctx.Input.RequestBody, &v)
|
||||||
if id, err := models.Add{{ctrlName}}(&v); err == nil {
|
if id, err := models.Add{{ctrlName}}(&v); err == nil {
|
||||||
this.Data["json"] = map[string]int64{"id": id}
|
c.Data["json"] = map[string]int64{"id": id}
|
||||||
} else {
|
} else {
|
||||||
this.Data["json"] = err.Error()
|
c.Data["json"] = err.Error()
|
||||||
}
|
}
|
||||||
this.ServeJson()
|
c.ServeJson()
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Title Get
|
// @Title Get
|
||||||
@ -1178,16 +1178,16 @@ func (this *{{ctrlName}}Controller) Post() {
|
|||||||
// @Success 200 {object} models.{{ctrlName}}
|
// @Success 200 {object} models.{{ctrlName}}
|
||||||
// @Failure 403 :id is empty
|
// @Failure 403 :id is empty
|
||||||
// @router /:id [get]
|
// @router /:id [get]
|
||||||
func (this *{{ctrlName}}Controller) GetOne() {
|
func (c *{{ctrlName}}Controller) GetOne() {
|
||||||
idStr := this.Ctx.Input.Params[":id"]
|
idStr := c.Ctx.Input.Params[":id"]
|
||||||
id, _ := strconv.Atoi(idStr)
|
id, _ := strconv.Atoi(idStr)
|
||||||
v, err := models.Get{{ctrlName}}ById(id)
|
v, err := models.Get{{ctrlName}}ById(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Data["json"] = err.Error()
|
c.Data["json"] = err.Error()
|
||||||
} else {
|
} else {
|
||||||
this.Data["json"] = v
|
c.Data["json"] = v
|
||||||
}
|
}
|
||||||
this.ServeJson()
|
c.ServeJson()
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Title Get All
|
// @Title Get All
|
||||||
@ -1201,7 +1201,7 @@ func (this *{{ctrlName}}Controller) GetOne() {
|
|||||||
// @Success 200 {object} models.{{ctrlName}}
|
// @Success 200 {object} models.{{ctrlName}}
|
||||||
// @Failure 403
|
// @Failure 403
|
||||||
// @router / [get]
|
// @router / [get]
|
||||||
func (this *{{ctrlName}}Controller) GetAll() {
|
func (c *{{ctrlName}}Controller) GetAll() {
|
||||||
var fields []string
|
var fields []string
|
||||||
var sortby []string
|
var sortby []string
|
||||||
var order []string
|
var order []string
|
||||||
@ -1210,32 +1210,32 @@ func (this *{{ctrlName}}Controller) GetAll() {
|
|||||||
var offset int64 = 0
|
var offset int64 = 0
|
||||||
|
|
||||||
// fields: col1,col2,entity.col3
|
// fields: col1,col2,entity.col3
|
||||||
if v := this.GetString("fields"); v != "" {
|
if v := c.GetString("fields"); v != "" {
|
||||||
fields = strings.Split(v, ",")
|
fields = strings.Split(v, ",")
|
||||||
}
|
}
|
||||||
// limit: 10 (default is 10)
|
// limit: 10 (default is 10)
|
||||||
if v, err := this.GetInt64("limit"); err == nil {
|
if v, err := c.GetInt64("limit"); err == nil {
|
||||||
limit = v
|
limit = v
|
||||||
}
|
}
|
||||||
// offset: 0 (default is 0)
|
// offset: 0 (default is 0)
|
||||||
if v, err := this.GetInt64("offset"); err == nil {
|
if v, err := c.GetInt64("offset"); err == nil {
|
||||||
offset = v
|
offset = v
|
||||||
}
|
}
|
||||||
// sortby: col1,col2
|
// sortby: col1,col2
|
||||||
if v := this.GetString("sortby"); v != "" {
|
if v := c.GetString("sortby"); v != "" {
|
||||||
sortby = strings.Split(v, ",")
|
sortby = strings.Split(v, ",")
|
||||||
}
|
}
|
||||||
// order: desc,asc
|
// order: desc,asc
|
||||||
if v := this.GetString("order"); v != "" {
|
if v := c.GetString("order"); v != "" {
|
||||||
order = strings.Split(v, ",")
|
order = strings.Split(v, ",")
|
||||||
}
|
}
|
||||||
// query: k:v,k:v
|
// query: k:v,k:v
|
||||||
if v := this.GetString("query"); v != "" {
|
if v := c.GetString("query"); v != "" {
|
||||||
for _, cond := range strings.Split(v, ",") {
|
for _, cond := range strings.Split(v, ",") {
|
||||||
kv := strings.Split(cond, ":")
|
kv := strings.Split(cond, ":")
|
||||||
if len(kv) != 2 {
|
if len(kv) != 2 {
|
||||||
this.Data["json"] = errors.New("Error: invalid query key/value pair")
|
c.Data["json"] = errors.New("Error: invalid query key/value pair")
|
||||||
this.ServeJson()
|
c.ServeJson()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
k, v := kv[0], kv[1]
|
k, v := kv[0], kv[1]
|
||||||
@ -1245,11 +1245,11 @@ func (this *{{ctrlName}}Controller) GetAll() {
|
|||||||
|
|
||||||
l, err := models.GetAll{{ctrlName}}(query, fields, sortby, order, offset, limit)
|
l, err := models.GetAll{{ctrlName}}(query, fields, sortby, order, offset, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Data["json"] = err.Error()
|
c.Data["json"] = err.Error()
|
||||||
} else {
|
} else {
|
||||||
this.Data["json"] = l
|
c.Data["json"] = l
|
||||||
}
|
}
|
||||||
this.ServeJson()
|
c.ServeJson()
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Title Update
|
// @Title Update
|
||||||
@ -1259,17 +1259,17 @@ func (this *{{ctrlName}}Controller) GetAll() {
|
|||||||
// @Success 200 {object} models.{{ctrlName}}
|
// @Success 200 {object} models.{{ctrlName}}
|
||||||
// @Failure 403 :id is not int
|
// @Failure 403 :id is not int
|
||||||
// @router /:id [put]
|
// @router /:id [put]
|
||||||
func (this *{{ctrlName}}Controller) Put() {
|
func (c *{{ctrlName}}Controller) Put() {
|
||||||
idStr := this.Ctx.Input.Params[":id"]
|
idStr := c.Ctx.Input.Params[":id"]
|
||||||
id, _ := strconv.Atoi(idStr)
|
id, _ := strconv.Atoi(idStr)
|
||||||
v := models.{{ctrlName}}{Id: id}
|
v := models.{{ctrlName}}{Id: id}
|
||||||
json.Unmarshal(this.Ctx.Input.RequestBody, &v)
|
json.Unmarshal(c.Ctx.Input.RequestBody, &v)
|
||||||
if err := models.Update{{ctrlName}}ById(&v); err == nil {
|
if err := models.Update{{ctrlName}}ById(&v); err == nil {
|
||||||
this.Data["json"] = "OK"
|
c.Data["json"] = "OK"
|
||||||
} else {
|
} else {
|
||||||
this.Data["json"] = err.Error()
|
c.Data["json"] = err.Error()
|
||||||
}
|
}
|
||||||
this.ServeJson()
|
c.ServeJson()
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Title Delete
|
// @Title Delete
|
||||||
@ -1278,15 +1278,15 @@ func (this *{{ctrlName}}Controller) Put() {
|
|||||||
// @Success 200 {string} delete success!
|
// @Success 200 {string} delete success!
|
||||||
// @Failure 403 id is empty
|
// @Failure 403 id is empty
|
||||||
// @router /:id [delete]
|
// @router /:id [delete]
|
||||||
func (this *{{ctrlName}}Controller) Delete() {
|
func (c *{{ctrlName}}Controller) Delete() {
|
||||||
idStr := this.Ctx.Input.Params[":id"]
|
idStr := c.Ctx.Input.Params[":id"]
|
||||||
id, _ := strconv.Atoi(idStr)
|
id, _ := strconv.Atoi(idStr)
|
||||||
if err := models.Delete{{ctrlName}}(id); err == nil {
|
if err := models.Delete{{ctrlName}}(id); err == nil {
|
||||||
this.Data["json"] = "OK"
|
c.Data["json"] = "OK"
|
||||||
} else {
|
} else {
|
||||||
this.Data["json"] = err.Error()
|
c.Data["json"] = err.Error()
|
||||||
}
|
}
|
||||||
this.ServeJson()
|
c.ServeJson()
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
ROUTER_TPL = `// @APIVersion 1.0.0
|
ROUTER_TPL = `// @APIVersion 1.0.0
|
||||||
|
@ -68,12 +68,12 @@ type {{controllerName}}Controller struct {
|
|||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *{{controllerName}}Controller) URLMapping() {
|
func (c *{{controllerName}}Controller) URLMapping() {
|
||||||
this.Mapping("Post", this.Post)
|
c.Mapping("Post", c.Post)
|
||||||
this.Mapping("GetOne", this.GetOne)
|
c.Mapping("GetOne", c.GetOne)
|
||||||
this.Mapping("GetAll", this.GetAll)
|
c.Mapping("GetAll", c.GetAll)
|
||||||
this.Mapping("Put", this.Put)
|
c.Mapping("Put", c.Put)
|
||||||
this.Mapping("Delete", this.Delete)
|
c.Mapping("Delete", c.Delete)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Title Post
|
// @Title Post
|
||||||
@ -82,7 +82,7 @@ func (this *{{controllerName}}Controller) URLMapping() {
|
|||||||
// @Success 200 {int} models.{{controllerName}}.Id
|
// @Success 200 {int} models.{{controllerName}}.Id
|
||||||
// @Failure 403 body is empty
|
// @Failure 403 body is empty
|
||||||
// @router / [post]
|
// @router / [post]
|
||||||
func (this *{{controllerName}}Controller) Post() {
|
func (c *{{controllerName}}Controller) Post() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ func (this *{{controllerName}}Controller) Post() {
|
|||||||
// @Success 200 {object} models.{{controllerName}}
|
// @Success 200 {object} models.{{controllerName}}
|
||||||
// @Failure 403 :id is empty
|
// @Failure 403 :id is empty
|
||||||
// @router /:id [get]
|
// @router /:id [get]
|
||||||
func (this *{{controllerName}}Controller) GetOne() {
|
func (c *{{controllerName}}Controller) GetOne() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ func (this *{{controllerName}}Controller) GetOne() {
|
|||||||
// @Success 200 {object} models.{{controllerName}}
|
// @Success 200 {object} models.{{controllerName}}
|
||||||
// @Failure 403
|
// @Failure 403
|
||||||
// @router / [get]
|
// @router / [get]
|
||||||
func (this *{{controllerName}}Controller) GetAll() {
|
func (c *{{controllerName}}Controller) GetAll() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ func (this *{{controllerName}}Controller) GetAll() {
|
|||||||
// @Success 200 {object} models.{{controllerName}}
|
// @Success 200 {object} models.{{controllerName}}
|
||||||
// @Failure 403 :id is not int
|
// @Failure 403 :id is not int
|
||||||
// @router /:id [put]
|
// @router /:id [put]
|
||||||
func (this *{{controllerName}}Controller) Put() {
|
func (c *{{controllerName}}Controller) Put() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ func (this *{{controllerName}}Controller) Put() {
|
|||||||
// @Success 200 {string} delete success!
|
// @Success 200 {string} delete success!
|
||||||
// @Failure 403 id is empty
|
// @Failure 403 id is empty
|
||||||
// @router /:id [delete]
|
// @router /:id [delete]
|
||||||
func (this *{{controllerName}}Controller) Delete() {
|
func (c *{{controllerName}}Controller) Delete() {
|
||||||
|
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
8
new.go
8
new.go
@ -222,10 +222,10 @@ type MainController struct {
|
|||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MainController) Get() {
|
func (c *MainController) Get() {
|
||||||
this.Data["Website"] = "beego.me"
|
c.Data["Website"] = "beego.me"
|
||||||
this.Data["Email"] = "astaxie@gmail.com"
|
c.Data["Email"] = "astaxie@gmail.com"
|
||||||
this.TplNames = "index.tpl"
|
c.TplNames = "index.tpl"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
8
testdata/router/router.go
vendored
8
testdata/router/router.go
vendored
@ -8,21 +8,21 @@ type Router struct {
|
|||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Router) Get() {
|
func (r *Router) Get() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Router) Post() {
|
func (r *Router) Post() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Controller) Put() {
|
func (c *Controller) Put() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Controller) Delete() {
|
func (c *Controller) Delete() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user