Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed User API Documentation #21

Merged
merged 39 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d9ce97b
created userResource
ArinNigam Feb 4, 2024
39fac0c
created studentResource
ArinNigam Feb 4, 2024
951f368
created skillResource
ArinNigam Feb 4, 2024
a2c4f7a
created achievementResource
ArinNigam Feb 4, 2024
98d789e
created facultyResource
ArinNigam Feb 5, 2024
422251a
created courseResource
ArinNigam Feb 5, 2024
24d29cf
fixed unused imports
ArinNigam Feb 5, 2024
3bd9cac
Create student_repository.dart
ArinNigam Feb 5, 2024
0533b91
Create faculty_repository.dart
ArinNigam Feb 5, 2024
7299f26
Create achievement_repository.dart
ArinNigam Feb 5, 2024
269fef3
Create skill_repository.dart
ArinNigam Feb 5, 2024
fdb99ed
Update pubspec.yaml
ArinNigam Feb 5, 2024
14e7f03
added populate
ArinNigam Feb 5, 2024
7dcbb49
Update pubspec.lock
ArinNigam Feb 5, 2024
55a2cfa
Merge branch 'resource-end-points' into user-frontend
ArinNigam Feb 5, 2024
5e17bdb
Update studentResouce.js
ArinNigam Feb 6, 2024
a01266e
Merge branch 'resource-end-points' into user-frontend
ArinNigam Feb 6, 2024
9dea269
added populate to other methods
ArinNigam Feb 11, 2024
bb7a59f
updated student_repository
ArinNigam Feb 11, 2024
6ce6d68
changed argument of getStudent()
ArinNigam Feb 11, 2024
02999d0
updated faculty_repository
ArinNigam Feb 11, 2024
3af927f
Merge branch 'main' into user-frontend
ArinNigam Feb 11, 2024
344f262
updated facultyResource
ArinNigam Feb 12, 2024
5a75313
Merge branch 'resource-end-points' into user-frontend
ArinNigam Feb 12, 2024
6e46de3
updated routes
ArinNigam Feb 12, 2024
b7c953b
removed unused imports
ArinNigam Feb 12, 2024
256c368
added null check
ArinNigam Feb 12, 2024
c3eea2b
fixed response.data being null
ArinNigam Feb 12, 2024
79314b3
added null check
ArinNigam Feb 12, 2024
68982e7
added post faculty
ArinNigam Feb 12, 2024
845b8e5
added next focus on otpbox
ArinNigam Feb 12, 2024
9669eaf
Create otp_provider.dart
ArinNigam Feb 12, 2024
34ff8e4
Create user_provider.dart
ArinNigam Feb 12, 2024
59a4e1c
updated skills and achievements repositories
ArinNigam Feb 12, 2024
8d71d40
fixed routes and imports
ArinNigam Feb 12, 2024
78b60f3
updated user_login with otpProvider
ArinNigam Feb 12, 2024
f861952
updated frontend for a user
ArinNigam Feb 12, 2024
ef0e55c
Create course_repository.dart
ArinNigam Feb 12, 2024
17f123b
added baseurl as an env variable
ArinNigam Feb 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import express from "express";
import cookieParser from "cookie-parser";
import logger from "morgan";
import testResource from "./resources/testResource.js";

import userResource from "./resources/userResource.js";
import authResource from "./resources/authResource.js";
import otpResource from "./resources/otpResource.js";
import studentResource from "./resources/studentResouce.js";
import facultyResource from "./resources/facultyResource.js";
import skillResource from "./resources/skillResource.js";
import achievementResource from "./resources/achievementResource.js";
import courseResource from "./resources/courseResource.js";
import Connection from "./database/db.js";
import cors from "cors";
import auth from "./middlewares/auth.js";
Expand All @@ -24,7 +29,13 @@ app.use(cors());
// Get Database connection
Connection();
app.use(authResource);
app.use(userResource);
app.use(otpResource);
app.use(studentResource);
app.use(facultyResource);
app.use(skillResource);
app.use(courseResource);
app.use(achievementResource);
app.use("/", testResource);
app.use("/rooms", roomListResource);
app.use("/room", roomResource);
Expand Down
71 changes: 71 additions & 0 deletions backend/resources/achievementResource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Achievement from '../models/achievement.js';
import express from 'express';
import * as errorMessages from '../constants/errorMessages.js';
const achievementRouter = express.Router();

achievementRouter.get('/achievements', async (req, res) => {
try {
const achievement = await Achievement.find({});
res.json(achievement)
} catch (err) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

achievementRouter.get('/achievements/:id', async (req, res) => {
const achievementId = req.params.id;

try {
const achievementDetails = await Achievement.findById(achievementId);

if (!achievementDetails) {
return res.status(404).json({ message: errorMessages.achievementNotFound });
}

res.json(achievementDetails);
} catch (err) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

achievementRouter.post('/achievements', async (req, res) => {
const achievementData = req.body;

try {
const newAchievement = new Achievement(achievementData);
await newAchievement.save();

res.status(201).json(newAchievement);
} catch (err) {
res.status(500).json({ message: errorMessages.internalServerError});
}
});

achievementRouter.put('/achievements/:id', async (req, res) => {
const achievementId = req.params.id;
const achievementData = req.body;

try {
const updatedAchievement = await Achievement.findByIdAndUpdate(achievementId,achievementData,{new:true});
res.json(updatedAchievement);
} catch (error) {
res.status(500).json({ message: errorMessages.internalServerError });
}

});

achievementRouter.delete('/achievements/:id', async (req, res) => {
const achievementId = req.params.id;

try {
const deletedAchievement = await Achievement.findByIdAndDelete(achievementId);
res.json(deletedAchievement);
} catch (error) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

export default achievementRouter;



16 changes: 8 additions & 8 deletions backend/resources/authResource.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import mongoose from "mongoose";
import express from "express";
import bcryptjs from "bcryptjs";
import jwt from "jsonwebtoken";
import * as errorMessages from "../constants/errorMessages.js";
import Student from "../models/student.js";
import Faculty from "../models/faculty.js";
import Admin from "../models/admin.js";
import mongoose from 'mongoose';
import express from 'express';
import bcryptjs from 'bcryptjs';
import jwt from 'jsonwebtoken';
import * as errorMessages from '../constants/errorMessages.js';
import Student from '../models/Student.js';
import Faculty from '../models/faculty.js';
import Admin from '../models/admin.js';

const authRouter = express.Router();

Expand Down
71 changes: 71 additions & 0 deletions backend/resources/courseResource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Course from '../models/course.js';
import express from 'express';
import * as errorMessages from '../constants/errorMessages.js';
const courseRouter = express.Router();

courseRouter.get('/courses', async (req, res) => {
try {
const courses = await Course.find({});
res.json(courses)
} catch (err) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

courseRouter.get('/courses/:id', async (req, res) => {
const courseId = req.params.id;

try {
const courseDetails = await Course.findById(courseId);

if (!courseDetails) {
return res.status(404).json({ message: errorMessages.courseNotFound });
}

res.json(courseDetails);
} catch (err) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

courseRouter.post('/courses', async (req, res) => {
const courseData = req.body;

try {
const newCourse = new Course(courseData);
await newCourse.save();

res.status(201).json(newCourse);
} catch (err) {
res.status(500).json({ message: errorMessages.internalServerError});
}
});

courseRouter.put('/courses/:id', async (req, res) => {
const courseId = req.params.id;
const courseData = req.body;

try {
const updatedCourse = await Course.findByIdAndUpdate(courseId,courseData,{new:true});
res.json(updatedCourse);
} catch (error) {
res.status(500).json({ message: errorMessages.internalServerError });
}

});

courseRouter.delete('/courses/:id', async (req, res) => {
const courseId = req.params.id;

try {
const deletedCourse = await Course.findByIdAndDelete(courseId);
res.json(deletedCourse);
} catch (error) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

export default courseRouter;



87 changes: 87 additions & 0 deletions backend/resources/facultyResource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import Faculty from '../models/faculty.js';
import express from 'express';
import * as errorMessages from '../constants/errorMessages.js';
const facultyRouter = express.Router();

facultyRouter.get('/faculties', async (req, res) => {
try {
const faculties = await Faculty.find().populate('courses');
res.json(faculties);
} catch (err) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

facultyRouter.post('/faculties', async (req, res) => {
const {email} = req.body;
let existingUser = await Faculty.findOne({ email });
try {
if (!existingUser) {
const newUser = new Faculty({ email });
await newUser.save();
res.send({ message: errorMessages.userCreated, user: newUser });
} else {
res.send({ message: errorMessages.userAlreadyExists, user: existingUser});
}
} catch (error) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

facultyRouter.get('/faculties/:id', async (req, res) => {
const facultyId = req.params.id;

try {
const facultyDetails = await Faculty.findById(facultyId).populate('courses');

if (!facultyDetails) {
return res.status(404).json({ message: errorMessages.facultyNotFound });
}

res.json(facultyDetails);
} catch (err) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

facultyRouter.post('/faculties', async (req, res) => {
const {email} = req.body;
let existingUser = await Faculty.findOne({ email });
try {
if (!existingUser) {
const newUser = new Faculty({ email });
await newUser.save();
res.send({ message: errorMessages.userCreated, user: newUser });
} else {
res.send({ message: errorMessages.userAlreadyExists, user: existingUser});
}
} catch (error) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

facultyRouter.put('/faculties/:id', async (req, res) => {
const facultyId = req.params.id;
const facultyData = req.body;

try {
const updatedFaculty = await Faculty.findByIdAndUpdate(facultyId,facultyData,{new:true}).populate('courses');
res.json(updatedFaculty);
} catch (error) {
res.status(500).json({ message: errorMessages.internalServerError });
}

});

facultyRouter.delete('/faculties/:id', async (req, res) => {
const facultyId = req.params.id;

try {
const deletedFaculty = await Faculty.findByIdAndDelete(facultyId).populate('courses');
res.json(deletedFaculty);
} catch (error) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

export default facultyRouter;
4 changes: 2 additions & 2 deletions backend/resources/lostAndFound/lostAndFoundListResource.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Router } from "express";
import LostAndFoundItem from "../../models/lost_and_found.js";
import fs from "fs/promises";
import uploader from "../../database/multerConfig.js";
import uploader from "../../middlewares/multerConfig.js";

const router = Router();

Expand All @@ -13,7 +13,7 @@ router.get("/", async (req, res) => {

// Create an empty array to store items with images
const itemsWithImages = [];

``
// Iterate through each item
for (const item of items) {
// Check if imagePath is null
Expand Down
71 changes: 71 additions & 0 deletions backend/resources/skillResource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Skill from '../models/Skill.js';
import express from 'express';
import * as errorMessages from '../constants/errorMessages.js';
const skillRouter = express.Router();

skillRouter.get('/skills', async (req, res) => {
try {
const skills = await Skill.find({});
res.json(skills)
} catch (err) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

skillRouter.get('/skills/:id', async (req, res) => {
const skillId = req.params.id;

try {
const skillDetails = await Skill.findById(skillId);

if (!skillDetails) {
return res.status(404).json({ message: errorMessages.skillNotFound });
}

res.json(skillDetails);
} catch (err) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

skillRouter.post('/skills', async (req, res) => {
const skillData = req.body;

try {
const newSkill = new Skill(skillData);
await newSkill.save();

res.status(201).json(newSkill);
} catch (err) {
res.status(500).json({ message: errorMessages.internalServerError});
}
});

skillRouter.put('/skills/:id', async (req, res) => {
const skillId = req.params.id;
const skillData = req.body;

try {
const updatedSkill = await Skill.findByIdAndUpdate(skillId,skillData,{new:true});
res.json(updatedSkill);
} catch (error) {
res.status(500).json({ message: errorMessages.internalServerError });
}

});

skillRouter.delete('/skills/:id', async (req, res) => {
const skillId = req.params.id;

try {
const deletedSkill = await Skill.findByIdAndDelete(skillId);
res.json(deletedSkill);
} catch (error) {
res.status(500).json({ message: errorMessages.internalServerError });
}
});

export default skillRouter;



Loading
Loading