Skip to content

Commit

Permalink
get group by id
Browse files Browse the repository at this point in the history
  • Loading branch information
pelazas committed Mar 13, 2024
1 parent f4e6aa6 commit 1f59e4d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ app.post('/joinGroup', async (req, res) => {
})
// leave group
// get group by id
app.get('/getGroup/:uuid', async (req, res) => {
try{
const uuid = req.params.uuid
const groupResponse = await axios.get(groupServiceUrl+'/getGroup/'+uuid);
console.log(groupResponse.data.members)
const userResponseAdmin = await axios.get(userServiceUrl+'/getUserById/'+groupResponse.data.admin);
groupResponse.data.admin = userResponseAdmin.data
const userIds = groupResponse.data.members
const userResponseMembers = await axios.post(userServiceUrl+'/getUsersByIds', {userIds});
groupResponse.data.members = userResponseMembers.data
console.log(groupResponse.data)
res.json(groupResponse.data);
}catch(error){
res.status(500).json({ error: error.message });
}
})


// Start the gateway service
Expand Down
17 changes: 17 additions & 0 deletions users/userservice/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ let UserController = {
previousGroup: previousGroup,
}
res.json(response);
},
getUserById: async (req, res) => {
console.log(req.params)
const userId = req.params.id;
console.log(userId)
const user = await User.findOne({ uuid: userId });
res.json(user);
},
getUsersByIds: async (req, res) => {
const userIds = req.body.userIds;
const users = [];
for(const id of userIds){
console.log(id)
const user = await User.findOne({ uuid: id });
users.push(user);
}
res.json(users);
}

}
Expand Down
2 changes: 2 additions & 0 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ app.post('/updateLastGame', UserController.updateLastGame);
app.post('/updateStatistics', UserController.updateStatistics);
app.get('/getStatistics/:id', UserController.getStatistics);
app.get('/getUser/:username', UserController.getUserByUsername);
app.post('/getUsersByIds', UserController.getUsersByIds);
app.get('/getUserById/:id', UserController.getUserById)
app.put('/addGroup/:userUUID', UserController.addGroupToUser)

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

0 comments on commit 1f59e4d

Please sign in to comment.