Skip to content

Add PUT /users/:id endpoint for updating users - #30

Open
Pagnarith wants to merge 1 commit into
mate-academy:mainfrom
Pagnarith:main
Open

Add PUT /users/:id endpoint for updating users#30
Pagnarith wants to merge 1 commit into
mate-academy:mainfrom
Pagnarith:main

Conversation

@Pagnarith

Copy link
Copy Markdown

Summary

  • Implemented PUT /users/:id endpoint to update existing users
  • Added updateUser() helper to db/store.js for data access
  • Validates required fields (name, email) and returns 400 if missing
  • Returns 404 for non-existent users, 200 with updated user on success

Test Plan

✅ All 9 tests passing:

  • PUT /users/:id updates an existing user
  • PUT /users/:id returns 404 for a user that does not exist
  • PUT /users/:id with a missing field returns 400
  • All existing endpoints continue to pass

Implementation Notes

  • Follows existing patterns from GET and POST endpoints
  • Consistent error handling and status codes
  • Code review found no runtime-correctness issues

🤖 Generated with Claude Code

Add updateUser() helper to db/store.js that finds a user by id,
updates name and email fields, and returns the updated user or null.

Add PUT /users/:id route to handle updates with:
- Required field validation (return 400 if name or email missing)
- Not-found handling (return 404 for non-existent users)
- Success response with updated user (200)

Follows existing patterns from GET and POST endpoints for consistency.
All tests passing (9/9).

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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.

2 participants