actually test api before deploying
This commit is contained in:
parent
96aa9b1b34
commit
c4d226db22
@ -90,32 +90,33 @@ func createUser(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getUser(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
func getUser(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
||||||
var user *user.User
|
this := user.User{}
|
||||||
idString := params.ByName("id")
|
idString := params.ByName("id")
|
||||||
|
|
||||||
if err := _db.Get(user, db.Cond{"handle": idString}); err != nil {
|
if err := _db.Get(&this, db.Cond{"handle": idString}); err != nil {
|
||||||
sendError(w, err)
|
sendError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, user)
|
writeJSON(w, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUser(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
func updateUser(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
||||||
logrus.Infof("updating user: %s", params.ByName("id"))
|
logrus.Infof("updating user: %s", params.ByName("id"))
|
||||||
var user *user.User
|
user := user.User{}
|
||||||
if err := _db.Get(user, db.Cond{"handle": params.ByName("id")}); err != nil {
|
if err := _db.Get(&user, db.Cond{"handle": params.ByName("id")}); err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := userFromRequest(r, user)
|
modified, err := userFromRequest(r, &user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sendError(w, err)
|
sendError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := _db.Collection("user").UpdateReturning(user); err != nil {
|
if err := _db.Collection("user").UpdateReturning(modified); err != nil {
|
||||||
sendError(w, err)
|
sendError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user