Exemple #1
0
func (c users) Get(url string, queries url.Values, body io.Reader) (util.APIStatus, interface{}) {
	// retrive a specified user
	if id := url[len("/users/"):]; len(id) != 0 {
		user, found := models.GetUser(id)
		if !found {
			return util.Success(http.StatusOK), models.User{}
		}
		return util.Success(http.StatusOK), user
	}
	// list users
	users, _, err := models.GetUsers()
	if err != nil {
		return util.Fail(http.StatusInternalServerError, err.Error()), nil
	}
	return util.Success(http.StatusOK), users
}
Exemple #2
0
func (c users) Post(url string, queries url.Values, body io.Reader) (util.APIStatus, interface{}) {
	user := &models.User{}
	if err := misc.ReadMBJSON(body, user, 100); err != nil {
		logs.Error.Printf("Could not decode response body as a json. Error: %v", err)
		return util.Fail(http.StatusInternalServerError, err.Error()), nil
	}
	if err := user.Persist(); err != nil {
		return util.Fail(http.StatusInternalServerError, err.Error()), nil
	}
	return util.Success(http.StatusOK), user
}