示例#1
0
文件: posts.go 项目: mewben/onix
// GetOne post
func (*PostsController) GetOne(c echo.Context) error {
	var model models.Post

	ret, err := model.GetOne(c.P(0))
	if err != nil {
		return c.JSON(400, utils.ErrMarshal(err.Error()))
	}

	return c.JSON(200, ret)
}
示例#2
0
文件: posts.go 项目: mewben/onix
// Get posts
func (*PostsController) Get(c echo.Context) error {
	var model models.Post
	var title = c.QueryParam("title")

	ret, err := model.Get(title)
	if err != nil {
		return c.JSON(400, utils.ErrMarshal(err.Error()))
	}

	return c.JSON(200, ret)
}
示例#3
0
文件: posts.go 项目: mewben/onix
// Update post
func (*PostsController) Update(c echo.Context) error {
	var model models.Post
	var payload models.PostPayload
	var status = c.QueryParam("status")

	if err := c.Bind(&payload); err != nil {
		return c.JSON(400, utils.ErrMarshal(err.Error()))
	}

	iss := 1

	payload.UpdatedBy = iss
	ret, err := model.Update(c.P(0), payload, status)
	if err != nil {
		return c.JSON(400, utils.ErrMarshal(err.Error()))
	}
	return c.JSON(200, ret)
}