作者:rlugoj
项目:gotrainin
// Retrieve returns the specified user from the system.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (uh 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
}
作者:rlugoj
项目:gotrainin
// List returns all the existing users in the system.
// 200 Success, 404 Not Found, 500 Internal
func (uh usersHandle) List(c *app.Context) error {
u, err := services.Users.List(c)
if err != nil {
return err
}
c.Respond(u, http.StatusOK)
return nil
}
作者:rlugoj
项目:gotrainin
// Update updates the specified user in the system.
// 200 Success, 400 Bad Request, 500 Internal
func (uh 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)
}