diff --git a/backend/controllers/alumni.controller.js b/backend/controllers/alumni.controller.js new file mode 100644 index 0000000..a19501f --- /dev/null +++ b/backend/controllers/alumni.controller.js @@ -0,0 +1,111 @@ +import Alumni from '../models/Alumni.model.js'; + +const getAlumni = async (req, res) => { + try { + const AlumniData = await Alumni.find().sort({ createdAt: -1 }); + res.status(200).json({ + message: 'Alumni data retrieved successfully', + alumni: AlumniData + }); + + } catch (error) { + console.error(error); + } +} + +const addAlumni = async (req, res) => { + try { + const newAlumni = await Alumni({ ...req.body }); + await newAlumni.save(); + res.send(201).json({ + message: 'Alumni added successfully', + alumni: newAlumni + }); + } catch (error) { + console.error(error); + } +} + +const deleteAlumni = async (req, res) => { + try { + const { email } = req.params; + const deletedAlumni = await Alumni.findOneAndDelete({email: email}); + if (!deletedAlumni) { + return res.status(404).json({ + message: 'Alumni not found' + }); + }else{ + res.status(200).json({ + message: 'Alumni deleted successfully', + alumni: deletedAlumni + }); + } + } catch (error) { + console.error(error); + + } +} + +const getSingleAlumni = async (req, res) => { + try { + const { email } = req.params; + const alumni = await Alumni.findOne({email: email}); + if (!alumni) { + return res.status(404).json({ + message: 'Alumni not found' + }); + }else{ + res.status(200).json({ + message: 'Alumni retrieved successfully', + alumni: alumni + }); + } + } catch (error) { + console.error(error); + + } +} + +const updateAlumni = async (req, res) => { + try { + const { email } = req.params; + + // Validate if the email parameter is provided + if (!email) { + return res.status(400).json({ + message: 'Email is required to update an alumni record', + }); + } + + const updateAlumni = await Alumni.findOneAndUpdate( + { email: email }, + req.body, + { new: true } + ); + + if (!updateAlumni) { + return res.status(404).json({ + message: 'Alumni not found', + }); + } else { + res.status(200).json({ + message: 'Alumni updated successfully', + alumni: updateAlumni, + }); + } + } catch (error) { + console.error(error); + res.status(500).json({ + message: 'An error occurred while updating the alumni', + }); + } +}; + + +export default { + getAlumni, + addAlumni, + deleteAlumni, + getSingleAlumni, + updateAlumni +} \ No newline at end of file diff --git a/backend/controllers/jobs.controllers.js b/backend/controllers/jobs.controllers.js index e5a9e9f..43b9e62 100644 --- a/backend/controllers/jobs.controllers.js +++ b/backend/controllers/jobs.controllers.js @@ -113,7 +113,7 @@ export const jobList = async (req, res) => { } }; -import JobPosting from '../models/jobPosting.js'; + export const jobRelevanceScoreUpvote = async (req, res) => { try { diff --git a/backend/models/Alumni.model.js b/backend/models/Alumni.model.js index 1726f5a..1def9c2 100644 --- a/backend/models/Alumni.model.js +++ b/backend/models/Alumni.model.js @@ -11,17 +11,18 @@ const alumniSchema = new mongoose.Schema({ linkedin:{ type: String, }, - InstituteId:{ + instituteId:{ type: String, required: true }, - MobileNumber:{ + mobileNumber:{ type:Number, required:true }, - Email:{ + email:{ type: String, - required: true + required: true, + unique: true } }) diff --git a/backend/routes/alumni.route.js b/backend/routes/alumni.route.js new file mode 100644 index 0000000..59c640e --- /dev/null +++ b/backend/routes/alumni.route.js @@ -0,0 +1,17 @@ +import express from 'express'; +import alumniController from '../controllers/alumni.controller.js'; + +const { getAlumni, addAlumni, deleteAlumni, getSingleAlumni, updateAlumni } = alumniController; +const router = express.Router(); + +router.get('/getAlumni', getAlumni); + +router.post('/addAlumni', addAlumni); + +router.delete('/deleteAlumni/:email', deleteAlumni); + +router.get('/getSingleAlumni/:email', getSingleAlumni); + +router.put('/updateAlumni/:email', updateAlumni); + +export default router; \ No newline at end of file diff --git a/backend/routes/router.js b/backend/routes/router.js index e6c6e72..31a7c6f 100644 --- a/backend/routes/router.js +++ b/backend/routes/router.js @@ -1,8 +1,8 @@ //importing all the necessary dependencies import express from "express"; -import {jobCreate,jobUpdate,jobRelevanceScoreUpvote,jobRelevanceScoreDownvote} from "../controllers/jobs.controllers.js" +import {jobCreate,jobUpdate,jobRelevanceScoreUpvote,jobRelevanceScoreDownvote, jobDelete, jobList} from "../controllers/jobs.controllers.js" import { ViewRes } from "../controllers/studentview.js"; -import SavedApplications from "../../frontend/src/pages/Savedapplications.jsx"; + //using the router const router = express.Router(); diff --git a/backend/server.js b/backend/server.js index beddac6..bd93a14 100644 --- a/backend/server.js +++ b/backend/server.js @@ -20,7 +20,9 @@ app.use(express.json()); const port = 3000; //apis +import alumniRoute from "./routes/alumni.route.js"; app.use("/api", router); +app.use("/api/alumni", alumniRoute); //listener app.listen(port, () => { diff --git a/frontend/src/api/alumniAPI/ReadMe.md b/frontend/src/api/alumniAPI/ReadMe.md new file mode 100644 index 0000000..48923c1 --- /dev/null +++ b/frontend/src/api/alumniAPI/ReadMe.md @@ -0,0 +1,27 @@ +# Alumni Management API + +This document outlines how to add or update alumni data in the database using a CSV file and the `alumniAPI` function. + +## Prerequisites + +1. You need a CSV file containing alumni data. +2. Ensure your backend is running and connected to the database. +3. Use the correct backend URL for API requests. +4. Email should be unique for each row of CSV file +5. After add email to database you can't change it +6. import alumniAPI from alumniAPI.js file in frontend file + +## Setup + +1. **CSV File Format:** + Your CSV file should include the following columns: + - `id` (for updating existing records) + - Other fields (e.g., name, email, etc.) + +## APIs + +1. GET ALL ALUMNI ::: "http://localhost:3000/api/alumni/getAlumni" +2. POST ALUMNI ::: aluminAPI("csv_file", "add") +3. UPDATE ALUMNI ::: alumniAPI("csv_file", "update") +4. DELETE ALUMIN ::: "http://localhost:3000/api/alumni/deleteAlumni/:email" +5. GET SINGLE ALUMNI ::: "http://localhost:3000/api/alumni/getSingleAlumni/:email" diff --git a/frontend/src/api/alumniAPI/alumniAPI.js b/frontend/src/api/alumniAPI/alumniAPI.js new file mode 100644 index 0000000..ee68390 --- /dev/null +++ b/frontend/src/api/alumniAPI/alumniAPI.js @@ -0,0 +1,41 @@ + + +const alumniAPI = (asvData, status) => { + if (!['update', 'add'].includes(status)) { + console.error('Invalid status! Use either "update" or "add".'); + return; + } + + asvData.array.forEach( async (row) => { + try{ + if(status === "add"){ + // Add alumni + const response = await fetch('http://localhost:3000/api/alumni/addAlumni', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(row) + }); + const data = await response.json(); + console.log(data); + } + if(status === "update"){ + // Update alumni + const response = await fetch(`http://localhost:3000/api/alumni/updateAlumni/${row.email}`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(row) + }); + const data = await response.json(); + console.log(data); + } + }catch (error){ + console.error(error) + } + }); +} + +export default alumniAPI; \ No newline at end of file