Пример #1
0
// 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
// 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
// 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)
}