From f4e6aa638bc624781b3315c0fc07b7da0626e6df Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Wed, 13 Mar 2024 20:01:16 +0100 Subject: [PATCH] leave group gateway --- game/groupservice/GroupController.js | 5 +++-- gatewayservice/gateway-service.js | 28 ++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/game/groupservice/GroupController.js b/game/groupservice/GroupController.js index 4af391c..b8dcf86 100644 --- a/game/groupservice/GroupController.js +++ b/game/groupservice/GroupController.js @@ -35,6 +35,7 @@ let GroupController = { res.json(response); }catch(error){ + console.log(error) res.status(400).json({error: error.message}) } @@ -45,8 +46,8 @@ let GroupController = { requiredFields = ['expelledUUID','groupName', 'adminUUID'] validateRequiredFields(req, requiredFields); const group = await getGroupByName(req.body.groupName); - - if(req.body.adminUUID != group.admin && req.body.adminUUID == req.body.expelledUUID){ + console.log(req.body.adminUUID +" - "+ req.body.expelledUUID) + if(req.body.adminUUID != group.admin && req.body.adminUUID != req.body.expelledUUID){ console.log("entra en la condicion") res.json({ message: 'User is unable to perform this operation' }); return; diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index c4e82d2..b4c9f9d 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -100,13 +100,20 @@ app.post('/createGroup', async (req, res) => { try { const { creatorUUID } = req.body const groupResponse = await axios.post(groupServiceUrl+'/createGroup', req.body); - const groupName = groupResponse.data.groupName; + console.log("----Group created succesfully----") + console.log(groupResponse.data) const userResponse = await axios.put(userServiceUrl+'/addGroup/'+creatorUUID, {groupUUID: groupResponse.data.uuid}); - console.log(userResponse.data); + console.log("----User updated succesfully----"); + console.log(userResponse.data) if(userResponse.data.previousGroup){ + console.log("----User has a previous group----") + console.log(userResponse.data.previousGroup) const getGroupResponse = await axios.get(groupServiceUrl+'/getGroup/'+userResponse.data.previousGroup); + console.log("----Group retrieved succesfully----") console.log(getGroupResponse.data) const exitGroupResponse = await axios.post(groupServiceUrl+'/leaveGroup', {expelledUUID: creatorUUID, adminUUID: creatorUUID, groupName: getGroupResponse.data.groupName}); + console.log("----Group exited succesfully----") + console.log(exitGroupResponse.data) } res.json(groupResponse.data); } catch (error) { @@ -114,6 +121,23 @@ app.post('/createGroup', async (req, res) => { } }) // join group +app.post('/joinGroup', async (req, res) => { + try{ + const { uuid } = req.body + const groupResponse = await axios.post(groupServiceUrl+'/joinGroup', req.body); + const userResponse = await axios.put(userServiceUrl+'/addGroup/'+req.body.uuid, {groupUUID: groupResponse.data.uuid}); + if(userResponse.data.previousGroup){ + const getGroupResponse = await axios.get(groupServiceUrl+'/getGroup/'+userResponse.data.previousGroup); + console.log(getGroupResponse.data) + const exitGroupResponse = await axios.post(groupServiceUrl+'/leaveGroup', {expelledUUID: uuid, adminUUID: uuid, groupName: getGroupResponse.data.groupName}); + console.log(exitGroupResponse.data) + } + console.log(groupResponse.data) + res.json(groupResponse.data); + } catch(error){ + res.status(500).json({ error: error.message }); + } +}) // leave group // get group by id