1
0
mirror of https://github.com/beego/bee.git synced 2024-11-27 03:01:29 +00:00

Complete controller modification

This commit is contained in:
MingZong 2016-04-01 17:49:17 +08:00
parent e6815f495e
commit 48817da755
2 changed files with 4 additions and 3 deletions

View File

@ -146,6 +146,7 @@ var controllerModelTpl = `package {{packageName}}
import (
"{{pkgPath}}/models"
"{{pkgPath}}/structures"
"encoding/json"
"errors"
"strconv"
@ -174,7 +175,7 @@ func (c *{{controllerName}}Controller) URLMapping() {
// @Failure 403 body is empty
// @router / [post]
func (c *{{controllerName}}Controller) Post() {
var v models.{{controllerName}}
var v structures.{{controllerName}}
json.Unmarshal(c.Ctx.Input.RequestBody, &v)
if _, err := models.Add{{controllerName}}(&v); err == nil {
c.Ctx.Output.SetStatus(201)
@ -275,7 +276,7 @@ func (c *{{controllerName}}Controller) GetAll() {
func (c *{{controllerName}}Controller) Put() {
idStr := c.Ctx.Input.Param(":id")
id, _ := strconv.ParseInt(idStr, 0, 64)
v := models.{{controllerName}}{Id: id}
v := structures.{{controllerName}}{Id: id}
json.Unmarshal(c.Ctx.Input.RequestBody, &v)
if err := models.Update{{controllerName}}ById(&v); err == nil {
c.Data["json"] = "OK"

View File

@ -1,4 +1,4 @@
// Copyright 2013 Dylan LYU (mingzong.lyu@gmail.com)
// Copyright 2016 Dylan LYU (mingzong.lyu@gmail.com)
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain