diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index b4c9f9d..b2b86ef 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -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 diff --git a/users/userservice/UserController.js b/users/userservice/UserController.js index f169f6e..8bdea1e 100644 --- a/users/userservice/UserController.js +++ b/users/userservice/UserController.js @@ -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); } } diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index 83305d7..5c5b2f1 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -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, () => {