Skip to content

Commit

Permalink
Added route to get user by username (/user/:username)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidCG-27 committed Mar 9, 2025
1 parent e02aca8 commit d272f96
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ app.get('/listUsers', async (req, res) => {
res.status(500).json({ error: error.message });
}
});

app.get('/user/:username', async (req, res) => {
try {
const user = await User.findOne({ username: req.params.username }, 'username friends'); // Return only the username and friends fields (password isn't included)
if (!user) {
return res.status(404).json({ error: "User not found" });
}
res.status(200).json(user);
} catch (error) {
res.status(500).json({ error: error.message });
}
});



const server = app.listen(port, () => {
Expand Down

0 comments on commit d272f96

Please sign in to comment.