Esempio n. 1
0
// Retrieve returns the specified user from the system.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (usersHandle) Retrieve(c *app.Context) error {
	u, err := services.Users.Retrieve(c, c.Params["id"])
	if err != nil {
		return err
	}

	c.Respond(u, http.StatusOK)
	return nil
}
Esempio n. 2
0
// List returns all the existing users in the system.
// 200 Success, 404 Not Found, 500 Internal
func (usersHandle) List(c *app.Context) error {
	u, err := services.Users.List(c)
	if err != nil {
		return err
	}

	c.Respond(u, http.StatusOK)
	return nil
}
Esempio n. 3
0
// Update updates the specified user in the system.
// 200 Success, 400 Bad Request, 500 Internal
func (usersHandle) Update(c *app.Context) error {
	var u models.User
	if err := json.NewDecoder(c.Request.Body).Decode(&u); err != nil {
		return err
	}

	if v, err := services.Users.Update(c, c.Params["id"], &u); err != nil {
		switch err {
		case app.ErrValidation:
			c.RespondInvalid(v)
			return nil

		default:
			return err
		}
	}

	return Users.Retrieve(c)
}