Skip to content

Commit a574532

Browse files
Merge pull request #1 from MykhailoIvchenko/develop
Add PUT /users/:id update endpoint
2 parents 19e97af + 9dbaa9f commit a574532

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

NOTES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
What was in the plan you approved, and did you edit anything before approving?
2+
The plan contained info about existing functions, their usage, files that should be changed. I haven't edited anything.
3+
4+
Which model did you choose, and why?
5+
I chose the Sonnet model as it is not routine task but is not complex at the same time.
6+
7+
How did you split your commits, and why that way?
8+
I asked claude to do this split
9+
10+
What did your review catch — or confirm was already fine?
11+
Everything was already fine

db/store.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,15 @@ function createUser({ name, email }) {
2424
return user;
2525
}
2626

27-
module.exports = { getAllUsers, getUserById, createUser };
27+
function updateUser(id, { name, email }) {
28+
const user = getUserById(id);
29+
if (!user) {
30+
return undefined;
31+
}
32+
33+
user.name = name;
34+
user.email = email;
35+
return user;
36+
}
37+
38+
module.exports = { getAllUsers, getUserById, createUser, updateUser };

routes/users.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,22 @@ router.post("/", (req, res) => {
3232
res.status(201).json(user);
3333
});
3434

35+
// PUT /users/:id — update an existing user; name and email are required
36+
router.put("/:id", (req, res) => {
37+
const id = Number(req.params.id);
38+
const { name, email } = req.body;
39+
40+
if (!name || !email) {
41+
return res.status(400).json({ error: "name and email are required" });
42+
}
43+
44+
const user = store.updateUser(id, { name, email });
45+
46+
if (!user) {
47+
return res.status(404).json({ error: "User not found" });
48+
}
49+
50+
res.json(user);
51+
});
52+
3553
module.exports = router;

0 commit comments

Comments
 (0)