Skip to content

Commit

Permalink
leave group gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
pelazas committed Mar 13, 2024
1 parent 1f59e4d commit 041a71d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
13 changes: 13 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,20 @@ app.post('/joinGroup', async (req, res) => {
res.status(500).json({ error: error.message });
}
})

// leave group
app.post('/leaveGroup', async (req, res) => {
try{
const groupResponse = await axios.post(groupServiceUrl+'/leaveGroup', req.body);
console.log("---- GROUP LEFT SUCCESFULLY ----")
console.log(groupResponse.data)
const userResponse = await axios.delete(userServiceUrl+'/leaveGroup/'+req.body.expelledUUID);
res.json(groupResponse.data);
} catch(error){
res.status(500).json({ error: error.message });
}
})

// get group by id
app.get('/getGroup/:uuid', async (req, res) => {
try{
Expand Down
11 changes: 10 additions & 1 deletion users/userservice/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,17 @@ let UserController = {
users.push(user);
}
res.json(users);
},
leaveGroup: async (req, res) => {
const id = req.params.id;
console.log(id)
const user = await User.findOne({uuid: id});
if(user){
user.groupId = null;
}
const response = await user.save();
res.json(response);
}

}

module.exports = UserController;
1 change: 1 addition & 0 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ app.get('/getUser/:username', UserController.getUserByUsername);
app.post('/getUsersByIds', UserController.getUsersByIds);
app.get('/getUserById/:id', UserController.getUserById)
app.put('/addGroup/:userUUID', UserController.addGroupToUser)
app.delete('/leaveGroup/:id', UserController.leaveGroup)

const server = app.listen(port, () => {
console.log(`User Service listening at http://localhost:${port}`);
Expand Down

0 comments on commit 041a71d

Please sign in to comment.