diff --git a/services/Meeting/controllers/meetingController.js b/services/Meeting/controllers/meetingController.js new file mode 100644 index 0000000..03743e0 --- /dev/null +++ b/services/Meeting/controllers/meetingController.js @@ -0,0 +1,102 @@ +const Meeting = require('../models/meetingModel'); + +const getAllMeetings = async (req, res) =>{ + try { + const meetings = await Meeting.find(); + res.status(200).json(meetings); + } catch (error) { + res.status(500).json({ message: 'Error retrieving meetings', error }); + } +} + +const getMeetingById = async (req, res)=> { + try { + const meeting = await Meeting.findById(req.params.id); + if (!meeting) { + return res.status(404).json({ message: 'Meeting not found' }); + } + res.status(200).json(meeting); + } catch (error) { + res.status(500).json({ message: 'Error retrieving meeting', error }); + } +} + +const createMeeting = async(req, res)=> { + try { + console.log(req.body); + const { title, description, host_id, start_time, end_time, participants } = req.body; + const newMeeting = new Meeting({ title, description, host_id, start_time, end_time, participants }); + const savedMeeting = await newMeeting.save(); + res.status(201).json(savedMeeting); + } catch (error) { + res.status(500).json({ message: 'Error creating meeting', error }); + } +} + +const updateMeeting = async(req, res) => { + try { + const { title, description, host_id, start_time, end_time, participants, status } = req.body; + const updatedMeeting = await Meeting.findByIdAndUpdate( + req.params.id, + { title, description, host_id, start_time, end_time, participants, status }, + { new: true } + ); + if (!updatedMeeting) { + return res.status(404).json({ message: 'Meeting not found' }); + } + res.status(200).json(updatedMeeting); + } catch (error) { + res.status(500).json({ message: 'Error updating meeting', error }); + } +} + +const deleteMeeting = async(req, res) => { + try { + const deletedMeeting = await Meeting.findByIdAndDelete(req.params.id); + if (!deletedMeeting) { + return res.status(404).json({ message: 'Meeting not found' }); + } + res.status(200).json({ message: 'Meeting deleted successfully' }); + } catch (error) { + res.status(500).json({ message: 'Error deleting meeting', error }); + } + } + +const joinMeeting = async (req, res) => { + try { + const meeting = await Meeting.findById(req.params.id); + if (!meeting) { + return res.status(404).json({ message: 'Meeting not found' }); + } + if (!meeting.participants.includes(req.body.user_id)) { + meeting.participants.push(req.body.user_id); + await meeting.save(); + } + res.status(200).json({ message: 'Successfully joined meeting' }); + } catch (error) { + res.status(500).json({ message: 'Error joining meeting', error }); + } + } + +const inviteParticipants = async (req, res) => { + try { + const { meeting_id, participants } = req.body; + const meeting = await Meeting.findById(meeting_id); + if (!meeting) { + return res.status(404).json({ message: 'Meeting not found' }); + } + // Assuming you have a function to send emails or notifications + await sendInvitations(participants, meeting); + res.status(200).json({ message: 'Invitations sent successfully' }); + } catch (error) { + res.status(500).json({ message: 'Error inviting participants', error }); + } + } + +// Mock function to send invitations +const sendInvitations = async (participants, meeting) => { + // Implement your email or notification sending logic here + console.log(`Sending invitations to: ${participants.join(', ')} for meeting: ${meeting.title}`); +} + +module.exports = {inviteParticipants, joinMeeting, deleteMeeting, updateMeeting, createMeeting, getMeetingById, getAllMeetings }; diff --git a/services/Meeting/index.js b/services/Meeting/index.js index 299fff0..e9c5689 100644 --- a/services/Meeting/index.js +++ b/services/Meeting/index.js @@ -2,6 +2,7 @@ const express = require('express'); const mongoose = require('mongoose'); const cors = require('cors'); const config = require('./config'); +const meetingRoutes = require('./routes/meetingRoute'); const app = express(); @@ -9,6 +10,7 @@ const app = express(); app.use(cors()); app.use(express.json()); +app.use('/meeting',meetingRoutes); const port = config.PORT; const dbUri = config.DB_URI; diff --git a/services/Meeting/models/meetingModel.js b/services/Meeting/models/meetingModel.js new file mode 100644 index 0000000..558c837 --- /dev/null +++ b/services/Meeting/models/meetingModel.js @@ -0,0 +1,38 @@ +const mongoose = require('mongoose'); + +const meetingSchema = new mongoose.Schema({ + title: { + type: String, + required: true + }, + description: { + type: String, + required: true + }, + host_id: { + type: mongoose.Schema.Types.ObjectId, + ref: 'User', + required: true + }, + start_time: { + type: Date, + required: true + }, + end_time: { + type: Date, + required: true + }, + participants: [{ + type: mongoose.Schema.Types.ObjectId, + ref: 'User' + }], + status: { + type: String, + enum: ['scheduled', 'ongoing', 'completed', 'cancelled'], + default: 'scheduled' + } +}); + +const Meeting = mongoose.model('Meeting', meetingSchema); + +module.exports = Meeting; diff --git a/services/Meeting/routes/meetingRoute.js b/services/Meeting/routes/meetingRoute.js new file mode 100644 index 0000000..71280d6 --- /dev/null +++ b/services/Meeting/routes/meetingRoute.js @@ -0,0 +1,26 @@ +const express = require('express'); +const router = express.Router(); +const {inviteParticipants, joinMeeting, deleteMeeting, updateMeeting, createMeeting, getMeetingById, getAllMeetings} = require('../controllers/meetingController'); // Adjust the path based on your folder structure + +// Route to get all meetings +router.get('/', getAllMeetings); + +// Route to get a meeting by ID +router.get('/:id', getMeetingById); + +// Route to create a new meeting +router.post('/', createMeeting); + +// Route to update an existing meeting +router.put('/:id', updateMeeting); + +// Route to delete a meeting +router.delete('/:id',deleteMeeting); + +// Route to join a meeting +router.post('/:id/join', joinMeeting); + +// Route to invite participants to a meeting +router.post('/:id/invite', inviteParticipants); + +module.exports = router;