Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PXP-8992): PATCH /user/{username} #140

Merged
merged 8 commits into from
Nov 30, 2021

Conversation

johnfrancismccann
Copy link
Contributor

Jira Ticket: PXP-8992

New Features

  • Add PATCH /user/{username} endpoint

@coveralls
Copy link

coveralls commented Nov 29, 2021

Coverage Status

Coverage increased (+0.3%) to 75.093% when pulling a5b3529 on feat/update-user-username into 54f9383 on master.

assertUsernameAndEmail(t, originalUsername, newUserEmail)
})

t.Run("BothUsernameAndEmail", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about neither, can you test that error case too?

result, err := db.Exec(stmt, name, email, user.Name)
if err != nil {
// this should only fail because the target name was not unique
msg := fmt.Sprintf(`failed to update name to "%s": user with this name already exists`, *name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if a user with name = $3 doesn't exist at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case that name = $3 doesn't exist at all, the SQL query still executes successfully, but rowsAffected below is 0 and a 404 is returned.

@@ -133,6 +133,7 @@ func (server *Server) MakeRouter(out io.Writer) http.Handler {
router.Handle("/user", http.HandlerFunc(server.handleUserList)).Methods("GET")
router.Handle("/user", http.HandlerFunc(server.parseJSON(server.handleUserCreate))).Methods("POST")
router.Handle("/user/{username}", http.HandlerFunc(server.handleUserRead)).Methods("GET")
router.Handle("/user/{username}", http.HandlerFunc(server.parseJSON(server.handleUserUpdate))).Methods("PATCH")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this /user API is a little odd using username as the id, since it's mutable now. I don't think there's much to do at this point b/c we don't want to rework the whole API... but we'll want to watch out b/c now clients must update their internal representation of username only on a successful PATCH (which is fine and makes sense, but it leaves room for some weird errors where a client might keep trying to patch something that's already been updated and starts getting errors b/c the username they're trying to patch doesn't exist anymore).

Maybe they didn't parse the success from Arborist right or persist it or something. Anything, since this is a new API and we are the client in most cases, this is fine. Just thinking out loud

arborist/user.go Outdated
return newErrorResponse(msg, 409, &err)
}

rowsAffeted, _ := result.RowsAffected()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be rowsAffected, will correct this.

@johnfrancismccann johnfrancismccann merged commit 6b67a98 into master Nov 30, 2021
@johnfrancismccann johnfrancismccann deleted the feat/update-user-username branch November 30, 2021 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants