diff --git a/api/common.go b/api/common.go index 26953f8..e57623b 100644 --- a/api/common.go +++ b/api/common.go @@ -42,8 +42,8 @@ func Init(mux *http.ServeMux) error { mux.HandleFunc("POST /account/login", handleAccountLogin) mux.HandleFunc("POST /account/changepw", handleAccountChangePW) mux.HandleFunc("GET /account/logout", handleAccountLogout) - mux.HandleFunc("POST /account/addfriend", handleAddFriend) - mux.HandleFunc("POST /account/removefriend", handleRemoveFriend) + mux.HandleFunc("POST /account/friends", handleAddFriend) + mux.HandleFunc("DELETE /account/friends", handleRemoveFriend) mux.HandleFunc("GET /account/friendsonline", handleFriendsOnlineStat) // game diff --git a/api/endpoints.go b/api/endpoints.go index 627f702..fe50373 100644 --- a/api/endpoints.go +++ b/api/endpoints.go @@ -160,19 +160,20 @@ func handleAddFriend(w http.ResponseWriter, r *http.Request) { } func handleRemoveFriend(w http.ResponseWriter, r *http.Request) { - formErr := r.ParseForm() - if formErr != nil { - httpError(w, r, fmt.Errorf("failed to parse request form: %s", formErr), http.StatusBadRequest) - return - } - uuid, err := uuidFromRequest(r) if err != nil { httpError(w, r, err, http.StatusBadRequest) return } - success, err := db.RemoveFriend(uuid, r.Form.Get("username")) + var friend string + if r.URL.Query().Has("username") { + friend = r.URL.Query().Get("username") + } else { + httpError(w, r, fmt.Errorf("No friend specified."), http.StatusBadRequest) + } + + success, err := db.RemoveFriend(uuid, friend) message := "Success" if !success { message = err.Error() diff --git a/db/account.go b/db/account.go index 71cf55e..ca8ee08 100644 --- a/db/account.go +++ b/db/account.go @@ -269,6 +269,11 @@ func FetchUUIDFromUsername(username string) ([]byte, error) { var uuid []byte err := handle.QueryRow("SELECT uuid FROM accounts WHERE username = ?", username).Scan(&uuid) if err != nil { + if err == sql.ErrNoRows { + // No rows is not an error in this context, it signifies that the user does not exists + // we reserve err for db errors. + return uuid, nil + } return nil, err }