From c8885af59a11bf83dc9f0c4bd06f4111e8ee00cf Mon Sep 17 00:00:00 2001 From: Arin Nigam Date: Tue, 30 Jan 2024 16:48:12 +0530 Subject: [PATCH 01/12] backend models --- backend/models/achievement.js | 10 +++++ backend/models/admin.js | 21 ++++++++++ backend/models/course.js | 21 ++++++++++ backend/models/faculty.js | 21 ++++++++++ backend/models/skill.js | 9 ++++ backend/models/student.js | 44 ++++++++++++++++++++ backend/resources/otpResource.js | 2 + frontend/lib/models/user.dart | 15 ++++++- frontend/lib/provider/user_provider.dart | 31 +++++++++++++- frontend/lib/services/auth/auth_service.dart | 7 +++- 10 files changed, 176 insertions(+), 5 deletions(-) create mode 100644 backend/models/achievement.js create mode 100644 backend/models/admin.js create mode 100644 backend/models/course.js create mode 100644 backend/models/faculty.js create mode 100644 backend/models/skill.js create mode 100644 backend/models/student.js diff --git a/backend/models/achievement.js b/backend/models/achievement.js new file mode 100644 index 0000000..c00e26d --- /dev/null +++ b/backend/models/achievement.js @@ -0,0 +1,10 @@ +import mongoose from 'mongoose'; + +const achievementSchema = new mongoose.Schema({ + name: { type: String, required: true }, + date: { type: Date, required: true }, + description: { type: String, required: true }, +}); + +const Achievement = mongoose.model('Achievement', achievementSchema); +export default Achievement; \ No newline at end of file diff --git a/backend/models/admin.js b/backend/models/admin.js new file mode 100644 index 0000000..373eb68 --- /dev/null +++ b/backend/models/admin.js @@ -0,0 +1,21 @@ +import mongoose from "mongoose"; + +const adminSchema = new mongoose.Schema({ + name: { + type: String, + }, + email: { + type: String, + required: true, + unique: true + }, + token: { + type: String, + required: true + } +}); + +const Admin = mongoose.model('Admin', adminSchema); + +export default Admin; + diff --git a/backend/models/course.js b/backend/models/course.js new file mode 100644 index 0000000..592fb5f --- /dev/null +++ b/backend/models/course.js @@ -0,0 +1,21 @@ +import mongoose from 'mongoose'; + +const courseSchema = new mongoose.Schema({ + name: { + type: String, + required: true + }, + courseCode: { + type: String, + required: true, + unique: true + }, + branches: [{ + type: String, + required: true + }] +}); + +const Course = mongoose.model('Course', courseSchema); + +export default Course; \ No newline at end of file diff --git a/backend/models/faculty.js b/backend/models/faculty.js new file mode 100644 index 0000000..c9b376d --- /dev/null +++ b/backend/models/faculty.js @@ -0,0 +1,21 @@ +const mongoose = require('mongoose'); + +const facultySchema = new mongoose.Schema({ + name: { + type: String, + required: true + }, + email: { + type: String, + required: true, + unique: true + }, + courses: [{ + type: mongoose.Schema.Types.ObjectId, + ref: 'Course' + }] +}); + +const Faculty = mongoose.model('Faculty', facultySchema); + +module.exports = Faculty; diff --git a/backend/models/skill.js b/backend/models/skill.js new file mode 100644 index 0000000..95b90ed --- /dev/null +++ b/backend/models/skill.js @@ -0,0 +1,9 @@ +import mongoose from 'mongoose'; + +const skillSchema = new mongoose.Schema({ + name: { type: String, required: true }, + level: { type: Number, required: true }, +}); + +const Skill = mongoose.model('Skill', skillSchema); +export default Skill; \ No newline at end of file diff --git a/backend/models/student.js b/backend/models/student.js new file mode 100644 index 0000000..bc9518e --- /dev/null +++ b/backend/models/student.js @@ -0,0 +1,44 @@ +import mongoose from 'mongoose'; + +const studentSchema = new mongoose.Schema({ + name: { + type: String, + required: true + }, + email: { + type: String, + required: true + }, + token: { + type: String, + required: true + }, + rollNumber: { + type: String, + }, + about: { + type: String, + }, + profilePicURI: { + type: String, + }, + branch: { + type: String, + }, + graduationYear: { + type: Number, + }, + skills: { + type: [skillSchema], + }, + achievements: { + type: [achievementSchema], + }, + roles: { + type: [String], + } +}); + +const Student = mongoose.model('Student', studentSchema); + +export default Student; diff --git a/backend/resources/otpResource.js b/backend/resources/otpResource.js index 498f697..57c0bae 100644 --- a/backend/resources/otpResource.js +++ b/backend/resources/otpResource.js @@ -108,6 +108,8 @@ otpRouter.post('/verify-otp', async (req, res) => { if (otp === storedOTP) { await collection.deleteOne({ email }); const token = jwt.sign({ email }, process.env.ACCESS_TOKEN_SECRET, { expiresIn: '1h' }); + const userCollection = database.collection('users'); + await userCollection.updateOne({ email }, { $set: { token } }); return res.json({ message: errorConstants.otpVerfied, token }); } res.status(401).json({ error: errorConstants.incorrectOTP }); diff --git a/frontend/lib/models/user.dart b/frontend/lib/models/user.dart index c858ff1..d8cc0dd 100644 --- a/frontend/lib/models/user.dart +++ b/frontend/lib/models/user.dart @@ -1,6 +1,19 @@ +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; + +enum UserType { faculty, student, admin } + class User { String email; String otp; + UserType userType; + final storage = FlutterSecureStorage(); + User({required this.email, required this.otp, required this.userType}); + + Future storeJwt(String jwt) async { + await storage.write(key: 'jwt', value: jwt); + } - User({required this.email, required this.otp}); + Future getJwt() async { + return await storage.read(key: 'jwt'); + } } diff --git a/frontend/lib/provider/user_provider.dart b/frontend/lib/provider/user_provider.dart index 382cef8..beaf8e1 100644 --- a/frontend/lib/provider/user_provider.dart +++ b/frontend/lib/provider/user_provider.dart @@ -1,5 +1,32 @@ import 'package:flutter/widgets.dart'; -class UserProvider extends ChangeNotifier{ +enum UserType { + student, + faculty, + admin, +} -} \ No newline at end of file +class UserProvider extends ChangeNotifier { + String? _userType; + String? _userEmail; + String? _userToken; + + String? get userType => _userType; + String? get userEmail => _userEmail; + String? get userToken => _userToken; + + void setUserType(String? userType) { + _userType = userType; + notifyListeners(); + } + + void setUserEmail(String? userEmail) { + _userEmail = userEmail; + notifyListeners(); + } + + void setUserToken(String? userToken) { + _userToken = userToken; + notifyListeners(); + } +} diff --git a/frontend/lib/services/auth/auth_service.dart b/frontend/lib/services/auth/auth_service.dart index 987ef99..53234c2 100644 --- a/frontend/lib/services/auth/auth_service.dart +++ b/frontend/lib/services/auth/auth_service.dart @@ -1,12 +1,14 @@ import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:http/http.dart' as http; import '../../components/snackbar.dart'; import '../../constants/error_handling.dart'; class AuthService { + final storage = FlutterSecureStorage(); final String baseUrl = 'http://10.0.2.2:3000'; // Replace with your backend API URL @@ -49,8 +51,9 @@ class AuthService { ); if (response.statusCode == 200) { - // OTP verification successful - + final Map data = jsonDecode(response.body); + final String jwt = data['token']; + await storage.write(key: 'jwt', value: jwt); return true; } else { return false; From 8bc0c8f5dff7630393148cd6c89d087fa77ef45d Mon Sep 17 00:00:00 2001 From: Arin Nigam Date: Wed, 31 Jan 2024 17:24:29 +0530 Subject: [PATCH 02/12] frontend models --- backend/app.js | 6 +- backend/constants/errorMessages.js | 5 +- backend/middlewares/auth.js | 37 +- backend/models/admin.js | 5 +- backend/models/faculty.js | 9 +- backend/models/student.js | 21 +- backend/resources/authResource.js | 124 +++-- backend/resources/otpResource.js | 2 - frontend/lib/components/choice_selector.dart | 15 +- frontend/lib/constants/dummy_entries.dart | 488 +++++++----------- frontend/lib/models/achievement.dart | 31 ++ frontend/lib/models/admin.dart | 27 + frontend/lib/models/course.dart | 33 +- frontend/lib/models/faculty.dart | 38 +- frontend/lib/models/skills.dart | 27 + frontend/lib/models/student.dart | 79 ++- frontend/lib/provider/courses_provider.dart | 31 +- frontend/lib/provider/faculty_provider.dart | 22 +- frontend/lib/provider/student_provider.dart | 28 +- frontend/lib/provider/user_provider.dart | 7 - frontend/lib/routes/routes.dart | 2 +- frontend/lib/screens/admin/add_courses.dart | 21 +- frontend/lib/screens/admin/add_students.dart | 41 +- frontend/lib/screens/admin/view_faculty.dart | 25 +- .../{signin_page.dart => login_page.dart} | 2 +- 25 files changed, 649 insertions(+), 477 deletions(-) create mode 100644 frontend/lib/models/achievement.dart create mode 100644 frontend/lib/models/admin.dart create mode 100644 frontend/lib/models/skills.dart rename frontend/lib/screens/auth/{signin_page.dart => login_page.dart} (98%) diff --git a/backend/app.js b/backend/app.js index 18097e5..3c06695 100644 --- a/backend/app.js +++ b/backend/app.js @@ -8,6 +8,7 @@ import otpResource from "./resources/otpResource.js"; import Connection from "./database/db.js"; import bodyParser from "body-parser"; import cors from "cors"; +import auth from "./middlewares/auth.js"; const PORT =`${process.env.PORT || 3000}`; const app = express(); @@ -19,8 +20,11 @@ app.use(cors()); // Get Database connection Connection(); - +app.use(authResource); app.use(otpResource); app.use("/", testResource); +app.get('/protected', auth, (req, res) => { + res.json({ message: 'Access granted' }); +}); export default app; diff --git a/backend/constants/errorMessages.js b/backend/constants/errorMessages.js index 6c26010..9629e84 100644 --- a/backend/constants/errorMessages.js +++ b/backend/constants/errorMessages.js @@ -20,4 +20,7 @@ export const otpSent = 'OTP sent successfully'; // Auth Middleware export const noAuthToken = 'No auth token, access denied'; -export const tokenVerificationFailed = 'Token verification failed, authorization denied.'; \ No newline at end of file +export const invalidAuthToken = 'Invalid token'; +export const tokenVerificationFailed = 'Token verification failed, authorization denied.'; +export const invalidUserType = 'Invalid user type'; +export const tokenUpdateError= 'Error updating token'; \ No newline at end of file diff --git a/backend/middlewares/auth.js b/backend/middlewares/auth.js index c782f3b..b2e0bef 100644 --- a/backend/middlewares/auth.js +++ b/backend/middlewares/auth.js @@ -1,25 +1,26 @@ import jwt from "jsonwebtoken"; import * as errorMessages from "../constants/errorMessages.js"; -const passwordKey = process.env.PASSWORD_KEY; +const secretKey = process.env.ACCESS_TOKEN_SECRET; const auth = async (req, res, next) => { - try { - const token = req.header("x-auth-token"); - if (!token) - return res.status(401).json({ msg: errorMessages.noAuthToken }); - - const verified = jwt.verify(token, passwordKey); - if (!verified) - return res - .status(401) - .json({ msg: errorMessages.tokenVerificationFailed }); - - req.user = verified.id; - req.token = token; - next(); - } catch (err) { - res.status(500).json({ error: err.message }); - } + try { + const bearerHeader = req.headers['authorization']; + if(typeof bearerHeader !== 'undefined') { + const bearer = bearerHeader.split(' '); + const bearerToken = bearer[1]; + // Verify the token + jwt.verify(bearerToken, secretKey, (err, user) => { + if(err) { + res.sendStatus(403); + } else { + req.user = user; + next(); + } + }); + } + } catch (error) { + res.status(500).json({ error: err.message }); + } }; export default auth; diff --git a/backend/models/admin.js b/backend/models/admin.js index 373eb68..142623d 100644 --- a/backend/models/admin.js +++ b/backend/models/admin.js @@ -3,16 +3,13 @@ import mongoose from "mongoose"; const adminSchema = new mongoose.Schema({ name: { type: String, + default: 'Smart Insti User' }, email: { type: String, required: true, unique: true }, - token: { - type: String, - required: true - } }); const Admin = mongoose.model('Admin', adminSchema); diff --git a/backend/models/faculty.js b/backend/models/faculty.js index c9b376d..0913954 100644 --- a/backend/models/faculty.js +++ b/backend/models/faculty.js @@ -1,9 +1,9 @@ -const mongoose = require('mongoose'); +import mongoose from 'mongoose'; const facultySchema = new mongoose.Schema({ name: { type: String, - required: true + default: 'Smart Insti User' }, email: { type: String, @@ -13,9 +13,8 @@ const facultySchema = new mongoose.Schema({ courses: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Course' - }] + }], }); const Faculty = mongoose.model('Faculty', facultySchema); - -module.exports = Faculty; +export default Faculty; \ No newline at end of file diff --git a/backend/models/student.js b/backend/models/student.js index bc9518e..0f79321 100644 --- a/backend/models/student.js +++ b/backend/models/student.js @@ -1,18 +1,13 @@ import mongoose from 'mongoose'; - const studentSchema = new mongoose.Schema({ name: { type: String, - required: true + default: 'Smart Insti User' }, email: { type: String, required: true }, - token: { - type: String, - required: true - }, rollNumber: { type: String, }, @@ -28,12 +23,14 @@ const studentSchema = new mongoose.Schema({ graduationYear: { type: Number, }, - skills: { - type: [skillSchema], - }, - achievements: { - type: [achievementSchema], - }, + skills: [{ + type: mongoose.Schema.Types.ObjectId, + ref: 'Skill' + }], + achievements: [{ + type: mongoose.Schema.Types.ObjectId, + ref: 'Achievement' + }], roles: { type: [String], } diff --git a/backend/resources/authResource.js b/backend/resources/authResource.js index d728e67..09f7def 100644 --- a/backend/resources/authResource.js +++ b/backend/resources/authResource.js @@ -1,62 +1,90 @@ +import mongoose from 'mongoose'; import express from 'express'; import User from "../models/user.js"; import bcryptjs from 'bcryptjs'; import jwt from 'jsonwebtoken'; -import auth from '../middlewares/auth.js'; 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(); -// Sign-Up Route -authRouter.post('/signup',async (req,res)=>{ - try { - const { name, email, password } = req.body; - const existingUser = await User.findOne({ email }); - if (existingUser){ - return res.status(400).json({ msg: errorMessages.userAlreadyExists }); - } - const hashedPassword = await bcryptjs.hash(password,8); - let user = new User({ - email, - password: hashedPassword, - name, - }); - user = await user.save(); - res.json(user); - } catch (e) { - res.status(500).json({error:e.message}); - } -}) - -// Sign-In Route -authRouter.post("/signin", async (req, res) => { - try { - const { email, password } = req.body; - - const user = await User.findOne({ email }); - if (!user) { - return res - .status(400) - .json({ msg: errorMessages.userNotFound }); - } - - const isMatch = await bcryptjs.compare(password, user.password); +// // Sign-Up Route +// authRouter.post('/signup',async (req,res)=>{ +// try { +// const { name, email, password } = req.body; +// const existingUser = await User.findOne({ email }); +// if (existingUser){ +// return res.status(400).json({ msg: errorMessages.userAlreadyExists }); +// } +// const hashedPassword = await bcryptjs.hash(password,8); +// let user = new User({ +// email, +// password: hashedPassword, +// name, +// }); +// user = await user.save(); +// res.json(user); +// } catch (e) { +// res.status(500).json({error:e.message}); +// } +// }) + +// // Sign-In Route +// authRouter.post("/signin", async (req, res) => { +// try { +// const { email, password } = req.body; + +// const user = await User.findOne({ email }); +// if (!user) { +// return res +// .status(400) +// .json({ msg: errorMessages.userNotFound }); +// } + +// const isMatch = await bcryptjs.compare(password, user.password); - if (!isMatch) { - return res.status(400).json({ msg: errorMessages.incorrectPassword }); - } - - const token = jwt.sign({ id: user._id }, "passwordKey"); - res.json({ token, ...user._doc }); - } catch (e) { - res.status(500).json({ error: errorMessages.internalServerError }); +// if (!isMatch) { +// return res.status(400).json({ msg: errorMessages.incorrectPassword }); +// } + +// const token = jwt.sign({ id: user._id }, "passwordKey"); +// res.json({ token, ...user._doc }); +// } catch (e) { +// res.status(500).json({ error: errorMessages.internalServerError }); +// } +// }); + +authRouter.post('/login', async (req, res) => { + const { email, userType } = req.body; + const token = jwt.sign({ email,userType }, process.env.ACCESS_TOKEN_SECRET, { expiresIn: '1h' }); + let userCollection; + let existingUser; + + switch(userType) { + case 'student': + userCollection = Student; + break; + case 'faculty': + userCollection = Faculty; + break; + case 'admin': + userCollection = Admin; + break; + default: + return res.status(400).send({ error: 'Invalid user type' }); } -}); + + existingUser = await userCollection.findOne({ email }); -// Get user Data -authRouter.get("/", auth, async (req, res) => { - const user = await User.findById(req.user); - res.json({ ...user._doc, token: req.token }); + if (!existingUser) { + const newUser = new userCollection({ email }); + await newUser.save(); + res.send({ message: 'User created successfully', user: newUser }); + } else { + res.send({ message: 'User already exists' }); + } }); export default authRouter \ No newline at end of file diff --git a/backend/resources/otpResource.js b/backend/resources/otpResource.js index 57c0bae..498f697 100644 --- a/backend/resources/otpResource.js +++ b/backend/resources/otpResource.js @@ -108,8 +108,6 @@ otpRouter.post('/verify-otp', async (req, res) => { if (otp === storedOTP) { await collection.deleteOne({ email }); const token = jwt.sign({ email }, process.env.ACCESS_TOKEN_SECRET, { expiresIn: '1h' }); - const userCollection = database.collection('users'); - await userCollection.updateOne({ email }, { $set: { token } }); return res.json({ message: errorConstants.otpVerfied, token }); } res.status(401).json({ error: errorConstants.incorrectOTP }); diff --git a/frontend/lib/components/choice_selector.dart b/frontend/lib/components/choice_selector.dart index 1d730cf..737322b 100644 --- a/frontend/lib/components/choice_selector.dart +++ b/frontend/lib/components/choice_selector.dart @@ -2,8 +2,12 @@ import 'package:flutter/material.dart'; import 'package:search_choices/search_choices.dart'; class ChoiceSelector extends StatelessWidget { - - const ChoiceSelector({super.key, required this.onChanged, required this.value,required this.items, required this.hint}); + const ChoiceSelector( + {super.key, + required this.onChanged, + required this.value, + required this.items, + required this.hint}); final Function onChanged; final List> items; @@ -12,7 +16,7 @@ class ChoiceSelector extends StatelessWidget { @override Widget build(BuildContext context) { - return Theme( + return Theme( data: Theme.of(context).copyWith( highlightColor: Colors.transparent, splashColor: Colors.transparent, @@ -39,7 +43,8 @@ class ChoiceSelector extends StatelessWidget { fontSize: 15, fontFamily: "RobotoFlex", ), - contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), + contentPadding: + const EdgeInsets.symmetric(horizontal: 20, vertical: 10), isDense: true, filled: true, fillColor: Colors.tealAccent.withOpacity(0.4), @@ -52,7 +57,7 @@ class ChoiceSelector extends StatelessWidget { ); }, menuConstraints: BoxConstraints.tight(const Size.fromHeight(350)), - validator:null, + validator: null, menuBackgroundColor: Colors.tealAccent.shade100, ), ); diff --git a/frontend/lib/constants/dummy_entries.dart b/frontend/lib/constants/dummy_entries.dart index 3f3079e..1b8239a 100644 --- a/frontend/lib/constants/dummy_entries.dart +++ b/frontend/lib/constants/dummy_entries.dart @@ -7,165 +7,70 @@ import '../models/student.dart'; class DummyStudents { static List students = [ Student( - id: '1', - collegeId: 'C001', - name: 'John Doe', - studentMail: 'john.doe@example.com', - rollNumber: '12345', - branch: 'Computer Science', - role: 'Student'), - Student( - id: '2', - collegeId: 'C002', - name: 'Alice Johnson', - studentMail: 'alice.johnson@example.com', - rollNumber: '67890', - branch: 'Mechanical Engineering', - role: 'Student'), - Student( - id: '3', - collegeId: 'C003', - name: 'Bob Williams', - studentMail: 'bob.williams@example.com', - rollNumber: '54321', - branch: 'Electrical Engineering', - role: 'Student'), - Student( - id: '4', - collegeId: 'C004', - name: 'Eva Davis', - studentMail: 'eva.davis@example.com', - rollNumber: '98765', - branch: 'Civil Engineering', - role: 'Student'), - Student( - id: '5', - collegeId: 'C005', - name: 'Chris Taylor', - studentMail: 'chris.taylor@example.com', - rollNumber: '13579', - branch: 'Chemical Engineering', - role: 'Student'), - Student( - id: '6', - collegeId: 'C006', - name: 'Grace Miller', - studentMail: 'grace.miller@example.com', - rollNumber: '24680', - branch: 'Biotechnology', - role: 'Student'), - Student( - id: '7', - collegeId: 'C007', - name: 'Daniel Brown', - studentMail: 'daniel.brown@example.com', - rollNumber: '97531', - branch: 'Aerospace Engineering', - role: 'Student'), - Student( - id: '8', - collegeId: 'C008', - name: 'Sophia Wilson', - studentMail: 'sophia.wilson@example.com', - rollNumber: '86420', - branch: 'Information Technology', - role: 'Student'), - Student( - id: '9', - collegeId: 'C009', - name: 'Matthew White', - studentMail: 'matthew.white@example.com', - rollNumber: '12340', - branch: 'Mechatronics', - role: 'Student'), - Student( - id: '10', - collegeId: 'C010', - name: 'Olivia Harris', - studentMail: 'olivia.harris@example.com', - rollNumber: '56789', - branch: 'Robotics Engineering', - role: 'Student'), - Student( - id: '11', - collegeId: 'C011', - name: 'William Turner', - studentMail: 'william.turner@example.com', - rollNumber: '34567', - branch: 'Industrial Engineering', - role: 'Student'), - Student( - id: '12', - collegeId: 'C012', - name: 'Emma Clark', - studentMail: 'emma.clark@example.com', - rollNumber: '89012', - branch: 'Computer Engineering', - role: 'Student'), - Student( - id: '13', - collegeId: 'C013', - name: 'Ryan Allen', - studentMail: 'ryan.allen@example.com', - rollNumber: '67890', - branch: 'Software Engineering', - role: 'Student'), - Student( - id: '14', - collegeId: 'C014', - name: 'Ava Young', - studentMail: 'ava.young@example.com', - rollNumber: '23456', - branch: 'Environmental Engineering', - role: 'Student'), - Student( - id: '15', - collegeId: 'C015', - name: 'Jackson Walker', - studentMail: 'jackson.walker@example.com', - rollNumber: '87654', - branch: 'Petroleum Engineering', - role: 'Student'), - Student( - id: '16', - collegeId: 'C016', - name: 'Sophie Lee', - studentMail: 'sophie.lee@example.com', - rollNumber: '54321', - branch: 'Nuclear Engineering', - role: 'Student'), + id: '1', + name: 'John Doe', + email: 'john.doe@example.com', + rollNumber: 'R001', + about: 'I am a computer science student.', + profilePicURI: 'https://example.com/john.jpg', + branch: 'Computer Science', + graduationYear: 2023, + skills: [], + achievements: [], + roles: ['role1', 'role2'], + ), Student( - id: '17', - collegeId: 'C017', - name: 'David Hall', - studentMail: 'david.hall@example.com', - rollNumber: '10987', - branch: 'Biomedical Engineering', - role: 'Student'), + id: '2', + name: 'John Doe', + email: 'john.doe@example.com', + rollNumber: 'R001', + about: 'I am a computer science student.', + profilePicURI: 'https://example.com/john.jpg', + branch: 'Computer Science', + graduationYear: 2023, + skills: [], + achievements: [], + roles: ['role1', 'role2'], + ), Student( - id: '18', - collegeId: 'C018', - name: 'Isabella Miller', - studentMail: 'isabella.miller@example.com', - rollNumber: '87654', - branch: 'Chemical Engineering', - role: 'Student'), + id: '3', + name: 'John Doe', + email: 'john.doe@example.com', + rollNumber: 'R001', + about: 'I am a computer science student.', + profilePicURI: 'https://example.com/john.jpg', + branch: 'Computer Science', + graduationYear: 2023, + skills: [], + achievements: [], + roles: ['role1', 'role2'], + ), Student( - id: '19', - collegeId: 'C019', - name: 'Mason Baker', - studentMail: 'mason.baker@example.com', - rollNumber: '54321', - branch: 'Electronics Engineering', - role: 'Student'), + id: '4', + name: 'John Doe', + email: 'john.doe@example.com', + rollNumber: 'R001', + about: 'I am a computer science student.', + profilePicURI: 'https://example.com/john.jpg', + branch: 'Computer Science', + graduationYear: 2023, + skills: [], + achievements: [], + roles: ['role1', 'role2'], + ), Student( - id: '20', - collegeId: 'C020', - name: 'Ella Turner', - studentMail: 'ella.turner@example.com', - rollNumber: '98765', - branch: 'Computer Science', - role: 'Student'), + id: '5', + name: 'John Doe', + email: 'john.doe@example.com', + rollNumber: 'R001', + about: 'I am a computer science student.', + profilePicURI: 'https://example.com/john.jpg', + branch: 'Computer Science', + graduationYear: 2023, + skills: [], + achievements: [], + roles: ['role1', 'role2'], + ), ]; } @@ -173,244 +78,245 @@ class DummyCourses { static List courses = [ Course( id: '1', - collegeId: 'C001', courseCode: 'CS101', courseName: 'Introduction to Computer Science', - branch: 'Computer Science'), + branches: ['Computer Science']), Course( id: '2', - collegeId: 'C002', courseCode: 'ME102', courseName: 'Mechanical Engineering Basics', - branch: 'Mechanical Engineering'), + branches: ['Mechanical Engineering']), Course( id: '3', - collegeId: 'C003', courseCode: 'EE103', courseName: 'Electrical Engineering Fundamentals', - branch: 'Electrical Engineering'), + branches: ['Electrical Engineering']), Course( id: '4', - collegeId: 'C004', - courseCode: 'CE104', + courseCode: 'EE104', courseName: 'Civil Engineering Principles', - branch: 'Civil Engineering'), + branches: ['Civil Engineering']), Course( id: '5', - collegeId: 'C005', courseCode: 'CHE105', courseName: 'Chemical Engineering Basics', - branch: 'Chemical Engineering'), + branches: ['Chemical Engineering']), Course( id: '6', - collegeId: 'C006', courseCode: 'BT106', courseName: 'Biotechnology Fundamentals', - branch: 'Biotechnology'), + branches: ['Biotechnology']), Course( id: '7', - collegeId: 'C007', courseCode: 'AE107', courseName: 'Aerospace Engineering Introduction', - branch: 'Aerospace Engineering'), + branches: ['Aerospace Engineering']), Course( id: '8', - collegeId: 'C008', courseCode: 'IT108', courseName: 'Information Technology Essentials', - branch: 'Information Technology'), - Course(id: '9', collegeId: 'C009', courseCode: 'MT109', courseName: 'Mechatronics Basics', branch: 'Mechatronics'), + branches: ['Information Technology']), + Course( + id: '9', + courseCode: 'MT109', + courseName: 'Mechatronics Basics', + branches: ['Mechatronics']), Course( id: '10', - collegeId: 'C010', courseCode: 'RE110', courseName: 'Robotics Engineering Fundamentals', - branch: 'Robotics Engineering'), + branches: ['Robotics Engineering']), Course( id: '11', - collegeId: 'C011', courseCode: 'IE111', courseName: 'Industrial Engineering Principles', - branch: 'Industrial Engineering'), + branches: ['Industrial Engineering']), Course( id: '12', - collegeId: 'C012', courseCode: 'CE112', courseName: 'Computer Engineering Basics', - branch: 'Computer Engineering'), + branches: ['Computer Engineering']), Course( id: '13', - collegeId: 'C013', courseCode: 'SE113', courseName: 'Software Engineering Fundamentals', - branch: 'Software Engineering'), + branches: ['Software Engineering']), Course( id: '14', - collegeId: 'C014', courseCode: 'EN114', courseName: 'Environmental Engineering Basics', - branch: 'Environmental Engineering'), + branches: ['Environmental Engineering']), Course( id: '15', - collegeId: 'C015', courseCode: 'PE115', courseName: 'Petroleum Engineering Introduction', - branch: 'Petroleum Engineering'), + branches: ['Petroleum Engineering']), Course( id: '16', - collegeId: 'C016', courseCode: 'NE116', courseName: 'Nuclear Engineering Basics', - branch: 'Nuclear Engineering'), + branches: ['Nuclear Engineering']), Course( id: '17', - collegeId: 'C017', courseCode: 'BE117', courseName: 'Biomedical Engineering Fundamentals', - branch: 'Biomedical Engineering'), + branches: ['Biomedical Engineering']), Course( id: '18', - collegeId: 'C018', courseCode: 'CE118', courseName: 'Chemical Engineering Principles', - branch: 'Chemical Engineering'), + branches: ['Chemical Engineering']), Course( id: '19', - collegeId: 'C019', courseCode: 'EE119', courseName: 'Electronics Engineering Basics', - branch: 'Electronics Engineering'), + branches: ['Electronics Engineering']), Course( id: '20', - collegeId: 'C020', courseCode: 'CS120', courseName: 'Advanced Computer Science Topics', - branch: 'Computer Science'), + branches: ['Computer Science']), ]; } class DummyFaculties { static List faculties = [ - Faculty( - id: '1', - collegeId: 'C001', - name: 'Dr. Smith', - facultyMail: 'smith@example.com', - courses: [DummyCourses.courses[0], DummyCourses.courses[5], DummyCourses.courses[10]]), + Faculty(id: '1', name: 'Dr. Smith', email: 'smith@example.com', courses: [ + DummyCourses.courses[0], + DummyCourses.courses[5], + DummyCourses.courses[10], + ]), Faculty( id: '2', - collegeId: 'C002', name: 'Prof. Johnson', - facultyMail: 'johnson@example.com', - courses: [DummyCourses.courses[1], DummyCourses.courses[6], DummyCourses.courses[11]]), - Faculty( - id: '3', - collegeId: 'C003', - name: 'Dr. Brown', - facultyMail: 'brown@example.com', - courses: [DummyCourses.courses[2], DummyCourses.courses[7], DummyCourses.courses[12]]), - Faculty( - id: '4', - collegeId: 'C004', - name: 'Prof. Davis', - facultyMail: 'davis@example.com', - courses: [DummyCourses.courses[3], DummyCourses.courses[8], DummyCourses.courses[13]]), - Faculty( - id: '5', - collegeId: 'C005', - name: 'Dr. Wilson', - facultyMail: 'wilson@example.com', - courses: [DummyCourses.courses[4], DummyCourses.courses[9], DummyCourses.courses[14]]), + email: 'johnson@example.com', + courses: [ + DummyCourses.courses[1], + DummyCourses.courses[6], + DummyCourses.courses[11] + ]), + Faculty(id: '3', name: 'Dr. Brown', email: 'brown@example.com', courses: [ + DummyCourses.courses[2], + DummyCourses.courses[7], + DummyCourses.courses[12] + ]), + Faculty(id: '4', name: 'Prof. Davis', email: 'davis@example.com', courses: [ + DummyCourses.courses[3], + DummyCourses.courses[8], + DummyCourses.courses[13] + ]), + Faculty(id: '5', name: 'Dr. Wilson', email: 'wilson@example.com', courses: [ + DummyCourses.courses[4], + DummyCourses.courses[9], + DummyCourses.courses[14] + ]), Faculty( id: '6', - collegeId: 'C006', name: 'Prof. Miller', - facultyMail: 'miller@example.com', - courses: [DummyCourses.courses[0], DummyCourses.courses[5], DummyCourses.courses[10]]), - Faculty( - id: '7', - collegeId: 'C007', - name: 'Dr. Turner', - facultyMail: 'turner@example.com', - courses: [DummyCourses.courses[1], DummyCourses.courses[6], DummyCourses.courses[11]]), - Faculty( - id: '8', - collegeId: 'C008', - name: 'Prof. Clark', - facultyMail: 'clark@example.com', - courses: [DummyCourses.courses[2], DummyCourses.courses[7], DummyCourses.courses[12]]), - Faculty( - id: '9', - collegeId: 'C009', - name: 'Dr. Harris', - facultyMail: 'harris@example.com', - courses: [DummyCourses.courses[3], DummyCourses.courses[8], DummyCourses.courses[13]]), + email: 'miller@example.com', + courses: [ + DummyCourses.courses[0], + DummyCourses.courses[5], + DummyCourses.courses[10] + ]), + Faculty(id: '7', name: 'Dr. Turner', email: 'turner@example.com', courses: [ + DummyCourses.courses[1], + DummyCourses.courses[6], + DummyCourses.courses[11] + ]), + Faculty(id: '8', name: 'Prof. Clark', email: 'clark@example.com', courses: [ + DummyCourses.courses[2], + DummyCourses.courses[7], + DummyCourses.courses[12] + ]), + Faculty(id: '9', name: 'Dr. Harris', email: 'harris@example.com', courses: [ + DummyCourses.courses[3], + DummyCourses.courses[8], + DummyCourses.courses[13] + ]), Faculty( id: '10', - collegeId: 'C010', name: 'Prof. Turner', - facultyMail: 'turner@example.com', - courses: [DummyCourses.courses[4], DummyCourses.courses[9], DummyCourses.courses[14]]), - Faculty( - id: '11', - collegeId: 'C011', - name: 'Dr. White', - facultyMail: 'white@example.com', - courses: [DummyCourses.courses[0], DummyCourses.courses[5], DummyCourses.courses[10]]), + email: 'turner@example.com', + courses: [ + DummyCourses.courses[4], + DummyCourses.courses[9], + DummyCourses.courses[14] + ]), + Faculty(id: '11', name: 'Dr. White', email: 'white@example.com', courses: [ + DummyCourses.courses[0], + DummyCourses.courses[5], + DummyCourses.courses[10] + ]), Faculty( id: '12', - collegeId: 'C012', name: 'Prof. Allen', - facultyMail: 'allen@example.com', - courses: [DummyCourses.courses[1], DummyCourses.courses[6], DummyCourses.courses[11]]), - Faculty( - id: '13', - collegeId: 'C013', - name: 'Dr. Young', - facultyMail: 'young@example.com', - courses: [DummyCourses.courses[2], DummyCourses.courses[7], DummyCourses.courses[12]]), + email: 'allen@example.com', + courses: [ + DummyCourses.courses[1], + DummyCourses.courses[6], + DummyCourses.courses[11] + ]), + Faculty(id: '13', name: 'Dr. Young', email: 'young@example.com', courses: [ + DummyCourses.courses[2], + DummyCourses.courses[7], + DummyCourses.courses[12] + ]), Faculty( id: '14', - collegeId: 'C014', name: 'Prof. Walker', - facultyMail: 'walker@example.com', - courses: [DummyCourses.courses[3], DummyCourses.courses[8], DummyCourses.courses[13]]), - Faculty( - id: '15', - collegeId: 'C015', - name: 'Dr. Lee', - facultyMail: 'lee@example.com', - courses: [DummyCourses.courses[4], DummyCourses.courses[9], DummyCourses.courses[14]]), - Faculty( - id: '16', - collegeId: 'C016', - name: 'Prof. Hall', - facultyMail: 'hall@example.com', - courses: [DummyCourses.courses[0], DummyCourses.courses[5], DummyCourses.courses[10]]), + email: 'walker@example.com', + courses: [ + DummyCourses.courses[3], + DummyCourses.courses[8], + DummyCourses.courses[13] + ]), + Faculty(id: '15', name: 'Dr. Lee', email: 'lee@example.com', courses: [ + DummyCourses.courses[4], + DummyCourses.courses[9], + DummyCourses.courses[14] + ]), + Faculty(id: '16', name: 'Prof. Hall', email: 'hall@example.com', courses: [ + DummyCourses.courses[0], + DummyCourses.courses[5], + DummyCourses.courses[10] + ]), Faculty( id: '17', - collegeId: 'C017', name: 'Dr. Miller', - facultyMail: 'miller@example.com', - courses: [DummyCourses.courses[1], DummyCourses.courses[6], DummyCourses.courses[11]]), + email: 'miller@example.com', + courses: [ + DummyCourses.courses[1], + DummyCourses.courses[6], + DummyCourses.courses[11] + ]), Faculty( id: '18', - collegeId: 'C018', name: 'Prof. Baker', - facultyMail: 'baker@example.com', - courses: [DummyCourses.courses[2], DummyCourses.courses[7], DummyCourses.courses[12]]), + email: 'baker@example.com', + courses: [ + DummyCourses.courses[2], + DummyCourses.courses[7], + DummyCourses.courses[12] + ]), Faculty( id: '19', - collegeId: 'C019', name: 'Dr. Turner', - facultyMail: 'turner@example.com', - courses: [DummyCourses.courses[3], DummyCourses.courses[8], DummyCourses.courses[13]]), + email: 'turner@example.com', + courses: [ + DummyCourses.courses[3], + DummyCourses.courses[8], + DummyCourses.courses[13] + ]), Faculty( id: '20', - collegeId: 'C020', name: 'Prof. Smith', - facultyMail: 'smith@example.com', - courses: [DummyCourses.courses[4], DummyCourses.courses[9], DummyCourses.courses[14]]), + email: 'smith@example.com', + courses: [ + DummyCourses.courses[4], + DummyCourses.courses[9], + DummyCourses.courses[14] + ]), ]; } @@ -679,7 +585,11 @@ class DummyRooms { Room(id: '16', name: 'Outdoor Sports Arena', vacant: true), Room(id: '17', name: 'Medical Clinic', vacant: false, occupantId: 'S004'), Room(id: '18', name: 'Music Room', vacant: true), - Room(id: '19', name: 'Student Council Office', vacant: false, occupantId: 'T005'), + Room( + id: '19', + name: 'Student Council Office', + vacant: false, + occupantId: 'T005'), Room(id: '20', name: 'Virtual Reality Lab', vacant: true), ]; } diff --git a/frontend/lib/models/achievement.dart b/frontend/lib/models/achievement.dart new file mode 100644 index 0000000..182b5a1 --- /dev/null +++ b/frontend/lib/models/achievement.dart @@ -0,0 +1,31 @@ +class Achievement { + final String id; + final String name; + final DateTime date; + final String description; + + Achievement({ + required this.id, + required this.name, + required this.date, + required this.description, + }); + + factory Achievement.fromJson(Map json) { + return Achievement( + id: json['_id'], + name: json['name'], + date: DateTime.parse(json['date']), + description: json['description'], + ); + } + + Map toJson() { + return { + '_id': id, + 'name': name, + 'date': date.toIso8601String(), + 'description': description, + }; + } +} diff --git a/frontend/lib/models/admin.dart b/frontend/lib/models/admin.dart new file mode 100644 index 0000000..25ce7d4 --- /dev/null +++ b/frontend/lib/models/admin.dart @@ -0,0 +1,27 @@ +class Admin { + final String id; + final String name; + final String email; + + Admin({ + required this.id, + required this.name, + required this.email, + }); + + factory Admin.fromJson(Map json) { + return Admin( + id: json['_id'], + name: json['name'] ?? 'Smart Insti User', + email: json['email'], + ); + } + + Map toJson() { + return { + '_id': id, + 'name': name, + 'email': email, + }; + } +} diff --git a/frontend/lib/models/course.dart b/frontend/lib/models/course.dart index 9b1d924..4e617a6 100644 --- a/frontend/lib/models/course.dart +++ b/frontend/lib/models/course.dart @@ -1,9 +1,32 @@ class Course { - Course({this.id, this.collegeId, required this.courseCode, required this.courseName, required this.branch}); - final String? id; - final String? collegeId; final String courseCode; final String courseName; - final String branch; -} \ No newline at end of file + final List branches; + + Course({ + this.id, + required this.courseCode, + required this.courseName, + required this.branches, + }); + + factory Course.fromJson(Map json) { + return Course( + id: json['_id'], + courseCode: json['courseCode'], + courseName: json['name'], + branches: + (json['branches'] as List).map((item) => item as String).toList(), + ); + } + + Map toJson() { + return { + '_id': id, + 'courseCode': courseCode, + 'name': courseName, + 'branches': branches, + }; + } +} diff --git a/frontend/lib/models/faculty.dart b/frontend/lib/models/faculty.dart index 9414836..7ac985a 100644 --- a/frontend/lib/models/faculty.dart +++ b/frontend/lib/models/faculty.dart @@ -1,11 +1,35 @@ -import 'course.dart'; +import 'package:smart_insti_app/models/course.dart'; class Faculty { - Faculty({this.id, this.collegeId, required this.name, required this.facultyMail, required this.courses}); - - final String? id; - final String? collegeId; + final String id; final String name; - final String facultyMail; + final String email; final List courses; -} \ No newline at end of file + + Faculty({ + required this.id, + required this.name, + required this.email, + required this.courses, + }); + + factory Faculty.fromJson(Map json) { + return Faculty( + id: json['_id'], + name: json['name'] ?? 'Smart Insti User', + email: json['email'], + courses: (json['courses'] as List) + .map((item) => Course.fromJson(item)) + .toList(), + ); + } + + Map toJson() { + return { + '_id': id, + 'name': name, + 'email': email, + 'courses': courses, + }; + } +} diff --git a/frontend/lib/models/skills.dart b/frontend/lib/models/skills.dart new file mode 100644 index 0000000..7ee7a82 --- /dev/null +++ b/frontend/lib/models/skills.dart @@ -0,0 +1,27 @@ +class Skill { + final String id; + final String name; + final int level; + + Skill({ + required this.id, + required this.name, + required this.level, + }); + + factory Skill.fromJson(Map json) { + return Skill( + id: json['_id'], + name: json['name'], + level: json['level'], + ); + } + + Map toJson() { + return { + '_id': id, + 'name': name, + 'level': level, + }; + } +} diff --git a/frontend/lib/models/student.dart b/frontend/lib/models/student.dart index a388e30..46af59c 100644 --- a/frontend/lib/models/student.dart +++ b/frontend/lib/models/student.dart @@ -1,18 +1,67 @@ -class Student { - Student( - {required this.name, - required this.studentMail, - required this.rollNumber, - required this.branch, - required this.role, - this.id, - this.collegeId}); +import 'package:smart_insti_app/models/achievement.dart'; +import 'package:smart_insti_app/models/skills.dart'; - final String? id; - final String? collegeId; +class Student { + final String id; final String name; - final String studentMail; - final String rollNumber; - final String branch; - final String role; + final String email; + final String? rollNumber; + final String? about; + final String? profilePicURI; + final String? branch; + final int? graduationYear; + final List? skills; + final List? achievements; + final List? roles; + + Student({ + required this.id, + required this.name, + required this.email, + this.rollNumber, + this.about, + this.profilePicURI, + this.branch, + this.graduationYear, + this.skills, + this.achievements, + this.roles, + }); + + factory Student.fromJson(Map json) { + return Student( + id: json['_id'], + name: json['name'] ?? 'Smart Insti User', + email: json['email'], + rollNumber: json['rollNumber'], + about: json['about'], + profilePicURI: json['profilePicURI'], + branch: json['branch'], + graduationYear: json['graduationYear'], + skills: (json['skills'] as List) + .map((item) => Skill.fromJson(item as Map)) + .toList(), + achievements: (json['achievements'] as List) + .map((item) => Achievement.fromJson(item as Map)) + .toList(), + roles: (json['roles'] as List?)?.map((item) => item as String).toList(), + ); + } + + Map toJson() { + return { + '_id': id, + 'name': name, + 'email': email, + 'rollNumber': rollNumber, + 'about': about, + 'profilePicURI': profilePicURI, + 'branch': branch, + 'graduationYear': graduationYear, + 'skills': skills!.map((skill) => skill.toJson()).toList(), + 'achievements': + achievements!.map((achievement) => achievement.toJson()).toList(), + 'roles': roles, + }; + } } diff --git a/frontend/lib/provider/courses_provider.dart b/frontend/lib/provider/courses_provider.dart index cef67c0..539fd3f 100644 --- a/frontend/lib/provider/courses_provider.dart +++ b/frontend/lib/provider/courses_provider.dart @@ -7,7 +7,8 @@ import 'dart:io'; import '../constants/constants.dart'; import '../models/course.dart'; -final coursesProvider = StateNotifierProvider((ref) => CoursesNotifier()); +final coursesProvider = StateNotifierProvider( + (ref) => CoursesNotifier()); class CoursesState { final List courses; @@ -15,7 +16,7 @@ class CoursesState { final TextEditingController courseCodeController; final TextEditingController courseNameController; final TextEditingController searchCourseController; - final String branch; + final List branches; CoursesState({ required this.courses, @@ -23,25 +24,25 @@ class CoursesState { required this.courseCodeController, required this.courseNameController, required this.searchCourseController, - required this.branch, + required this.branches, }); CoursesState copyWith({ - List? branches, List? courses, List? filteredCourses, + List? branches, TextEditingController? courseCodeController, TextEditingController? courseNameController, TextEditingController? searchCourseController, - String? branch, }) { return CoursesState( courses: courses ?? this.courses, filteredCourses: filteredCourses ?? this.filteredCourses, courseCodeController: courseCodeController ?? this.courseCodeController, courseNameController: courseNameController ?? this.courseNameController, - searchCourseController: searchCourseController ?? this.searchCourseController, - branch: branch ?? this.branch, + searchCourseController: + searchCourseController ?? this.searchCourseController, + branches: branches ?? this.branches, ); } } @@ -56,7 +57,7 @@ class CoursesNotifier extends StateNotifier { courseCodeController: TextEditingController(), courseNameController: TextEditingController(), searchCourseController: TextEditingController(), - branch: Branches.branchList[0].value!, + branches: Branches.branchList.map((branch) => branch.value!).toList(), ); } @@ -92,8 +93,10 @@ class CoursesNotifier extends StateNotifier { String query = state.searchCourseController.text; _logger.i("Searching for courses with query $query"); state = state.copyWith( - filteredCourses: - state.courses.where((course) => course.courseName.toLowerCase().contains(query.toLowerCase())).toList()); + filteredCourses: state.courses + .where((course) => + course.courseName.toLowerCase().contains(query.toLowerCase())) + .toList()); } void removeCourse(Course course) { @@ -109,7 +112,7 @@ class CoursesNotifier extends StateNotifier { final newCourse = Course( courseCode: state.courseCodeController.text, courseName: state.courseNameController.text, - branch: state.branch, + branches: state.branches, ); state = state.copyWith( courses: [ @@ -118,11 +121,11 @@ class CoursesNotifier extends StateNotifier { ], courseCodeController: TextEditingController(), courseNameController: TextEditingController(), - branch: Branches.branchList[0].value!, + branches: Branches.branchList.map((branch) => branch.value!).toList(), ); } - void updateBranch(String newBranch) { - state = state.copyWith(branch: newBranch); + void updateBranch(List newBranches) { + state = state.copyWith(branches: newBranches); } } diff --git a/frontend/lib/provider/faculty_provider.dart b/frontend/lib/provider/faculty_provider.dart index e067328..97d1391 100644 --- a/frontend/lib/provider/faculty_provider.dart +++ b/frontend/lib/provider/faculty_provider.dart @@ -7,7 +7,9 @@ import '../constants/dummy_entries.dart'; import '../models/course.dart'; import '../models/faculty.dart'; -final facultyProvider = StateNotifierProvider((ref) => FacultyStateNotifier()); +final facultyProvider = + StateNotifierProvider( + (ref) => FacultyStateNotifier()); class FacultyState { final List faculties; @@ -38,9 +40,12 @@ class FacultyState { faculties: faculties ?? this.faculties, filteredFaculties: filteredFaculties ?? this.filteredFaculties, selectedCourses: selectedCourses ?? this.selectedCourses, - facultyNameController: facultyNameController ?? this.facultyNameController, - facultyEmailController: facultyEmailController ?? this.facultyEmailController, - searchFacultyController: searchFacultyController ?? this.searchFacultyController, + facultyNameController: + facultyNameController ?? this.facultyNameController, + facultyEmailController: + facultyEmailController ?? this.facultyEmailController, + searchFacultyController: + searchFacultyController ?? this.searchFacultyController, ); } } @@ -86,8 +91,9 @@ class FacultyStateNotifier extends StateNotifier { void addFaculty() { Faculty faculty = Faculty( + id: '', name: state.facultyNameController.text, - facultyMail: state.facultyEmailController.text, + email: state.facultyEmailController.text, courses: state.selectedCourses, ); state = state.copyWith( @@ -109,8 +115,10 @@ class FacultyStateNotifier extends StateNotifier { String query = state.searchFacultyController.text; _logger.i("Searching for faculty: $query"); state = state.copyWith( - filteredFaculties: - state.faculties.where((faculty) => faculty.name.toLowerCase().contains(query.toLowerCase())).toList(), + filteredFaculties: state.faculties + .where((faculty) => + faculty.name.toLowerCase().contains(query.toLowerCase())) + .toList(), ); } diff --git a/frontend/lib/provider/student_provider.dart b/frontend/lib/provider/student_provider.dart index 5213345..d2adec8 100644 --- a/frontend/lib/provider/student_provider.dart +++ b/frontend/lib/provider/student_provider.dart @@ -7,7 +7,8 @@ import 'package:smart_insti_app/constants/dummy_entries.dart'; import '../models/student.dart'; import 'dart:io'; -final studentProvider = StateNotifierProvider((ref) => StudentProvider()); +final studentProvider = StateNotifierProvider( + (ref) => StudentProvider()); class StudentState { final List students; @@ -43,10 +44,14 @@ class StudentState { return StudentState( students: students ?? this.students, filteredStudents: filteredStudents ?? this.filteredStudents, - studentNameController: studentNameController ?? this.studentNameController, - studentEmailController: studentEmailController ?? this.studentEmailController, - studentRollNoController: studentRollNoController ?? this.studentRollNoController, - searchStudentController: searchStudentController ?? this.searchStudentController, + studentNameController: + studentNameController ?? this.studentNameController, + studentEmailController: + studentEmailController ?? this.studentEmailController, + studentRollNoController: + studentRollNoController ?? this.studentRollNoController, + searchStudentController: + searchStudentController ?? this.searchStudentController, branch: branch ?? this.branch, role: role ?? this.role, ); @@ -100,8 +105,10 @@ class StudentProvider extends StateNotifier { String query = state.searchStudentController.text; _logger.i("Searching for student: $query"); final newState = state.copyWith( - filteredStudents: - state.students.where((student) => student.name.toLowerCase().contains(query.toLowerCase())).toList(), + filteredStudents: state.students + .where((student) => + student.name.toLowerCase().contains(query.toLowerCase())) + .toList(), ); state = newState; } @@ -120,11 +127,11 @@ class StudentProvider extends StateNotifier { final newState = state.copyWith( students: [ Student( + id: '', name: state.studentNameController.text, - studentMail: state.studentEmailController.text, + email: state.studentEmailController.text, rollNumber: state.studentRollNoController.text, branch: state.branch, - role: state.role, ), ...state.students, ], @@ -139,7 +146,8 @@ class StudentProvider extends StateNotifier { void removeStudent(Student student) { final newStudents = state.students.where((s) => s != student).toList(); - final newFilteredStudents = state.filteredStudents.where((s) => s != student).toList(); + final newFilteredStudents = + state.filteredStudents.where((s) => s != student).toList(); final newState = state.copyWith( students: newStudents, filteredStudents: newFilteredStudents, diff --git a/frontend/lib/provider/user_provider.dart b/frontend/lib/provider/user_provider.dart index beaf8e1..a3f2340 100644 --- a/frontend/lib/provider/user_provider.dart +++ b/frontend/lib/provider/user_provider.dart @@ -9,11 +9,9 @@ enum UserType { class UserProvider extends ChangeNotifier { String? _userType; String? _userEmail; - String? _userToken; String? get userType => _userType; String? get userEmail => _userEmail; - String? get userToken => _userToken; void setUserType(String? userType) { _userType = userType; @@ -24,9 +22,4 @@ class UserProvider extends ChangeNotifier { _userEmail = userEmail; notifyListeners(); } - - void setUserToken(String? userToken) { - _userToken = userToken; - notifyListeners(); - } } diff --git a/frontend/lib/routes/routes.dart b/frontend/lib/routes/routes.dart index 551c854..c87e66d 100644 --- a/frontend/lib/routes/routes.dart +++ b/frontend/lib/routes/routes.dart @@ -10,7 +10,7 @@ import '../screens/admin/add_menu.dart'; import '../screens/admin/view_courses.dart'; import '../screens/admin/view_faculty.dart'; import '../screens/admin/view_menu.dart'; -import '../screens/auth/signin_page.dart'; +import '../screens/auth/login_page.dart'; final GoRouter routes = GoRouter( routes: [ diff --git a/frontend/lib/screens/admin/add_courses.dart b/frontend/lib/screens/admin/add_courses.dart index adbc97d..fed4152 100644 --- a/frontend/lib/screens/admin/add_courses.dart +++ b/frontend/lib/screens/admin/add_courses.dart @@ -46,8 +46,12 @@ class AddCourses extends ConsumerWidget { ), const SizedBox(width: 30), ElevatedButton( - onPressed: () => ref.read(coursesProvider.notifier).pickSpreadsheet(), - style: ButtonStyle(minimumSize: MaterialStateProperty.all(const Size(200, 60))), + onPressed: () => ref + .read(coursesProvider.notifier) + .pickSpreadsheet(), + style: ButtonStyle( + minimumSize: + MaterialStateProperty.all(const Size(200, 60))), child: const Text("Upload Spreadsheet"), ), ], @@ -80,14 +84,17 @@ class AddCourses extends ConsumerWidget { const SizedBox(height: 30), MaterialTextFormField( controller: course.courseCodeController, - validator: (value) => Validators.courseCodeValidator(value), + validator: (value) => + Validators.courseCodeValidator(value), hintText: "Enter course code", hintColor: Colors.teal.shade900.withOpacity(0.5), ), const SizedBox(height: 30), ChoiceSelector( - onChanged: (value) => ref.read(coursesProvider.notifier).updateBranch(value), - value: course.branch, + onChanged: (value) => ref + .read(coursesProvider.notifier) + .updateBranch(value), + value: course.branches[0], items: Branches.branchList, hint: "Select Branch", ), @@ -103,7 +110,9 @@ class AddCourses extends ConsumerWidget { ); } }, - style: ButtonStyle(minimumSize: MaterialStateProperty.all(const Size(200, 60))), + style: ButtonStyle( + minimumSize: MaterialStateProperty.all( + const Size(200, 60))), child: const Text("Add Course"), ), ), diff --git a/frontend/lib/screens/admin/add_students.dart b/frontend/lib/screens/admin/add_students.dart index ba3e324..26c5bd6 100644 --- a/frontend/lib/screens/admin/add_students.dart +++ b/frontend/lib/screens/admin/add_students.dart @@ -45,8 +45,12 @@ class AddStudents extends ConsumerWidget { ), const SizedBox(width: 30), ElevatedButton( - onPressed: () => ref.read(studentProvider.notifier).pickSpreadsheet(), - style: ButtonStyle(minimumSize: MaterialStateProperty.all(const Size(200, 60))), + onPressed: () => ref + .read(studentProvider.notifier) + .pickSpreadsheet(), + style: ButtonStyle( + minimumSize: + MaterialStateProperty.all(const Size(200, 60))), child: const Text("Upload Spreadsheet"), ), ], @@ -71,35 +75,47 @@ class AddStudents extends ConsumerWidget { child: Column( children: [ MaterialTextFormField( - controller: ref.watch(studentProvider.notifier).studentNameController, + controller: ref + .watch(studentProvider.notifier) + .studentNameController, validator: (value) => Validators.nameValidator(value), hintText: "Enter Student Name", hintColor: Colors.teal.shade900.withOpacity(0.5), ), const SizedBox(height: 30), MaterialTextFormField( - controller: ref.read(studentProvider.notifier).studentRollNoController, - validator: (value) => Validators.rollNumberValidator(value), + controller: ref + .read(studentProvider.notifier) + .studentRollNoController, + validator: (value) => + Validators.rollNumberValidator(value), hintText: "Enter Roll Number", hintColor: Colors.teal.shade900.withOpacity(0.5), ), const SizedBox(height: 30), MaterialTextFormField( - controller: ref.read(studentProvider.notifier).studentEmailController, - validator: (value) => Validators.emailValidator(value), + controller: ref + .read(studentProvider.notifier) + .studentEmailController, + validator: (value) => + Validators.emailValidator(value), hintText: "Enter Student Mail", hintColor: Colors.teal.shade900.withOpacity(0.5), ), const SizedBox(height: 30), ChoiceSelector( - onChanged: (value) => ref.read(studentProvider.notifier).updateBranch(value!), + onChanged: (value) => ref + .read(studentProvider.notifier) + .updateBranch(value!), value: ref.watch(studentProvider).branch, items: Branches.branchList, hint: "Select Branch", ), const SizedBox(height: 30), ChoiceSelector( - onChanged: (value) => ref.read(studentProvider.notifier).updateRole(value!), + onChanged: (value) => ref + .read(studentProvider.notifier) + .updateRole(value!), value: ref.watch(studentProvider).role, items: StudentRoles.studentRoleList, hint: "Select student role", @@ -112,11 +128,14 @@ class AddStudents extends ConsumerWidget { if (_formKey.currentState!.validate()) { ref.read(studentProvider.notifier).addStudent(); ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Added Student')), + const SnackBar( + content: Text('Added Student')), ); } }, - style: ButtonStyle(minimumSize: MaterialStateProperty.all(const Size(200, 60))), + style: ButtonStyle( + minimumSize: MaterialStateProperty.all( + const Size(200, 60))), child: const Text("Add Student"), ), ), diff --git a/frontend/lib/screens/admin/view_faculty.dart b/frontend/lib/screens/admin/view_faculty.dart index 82f19a1..a55de33 100644 --- a/frontend/lib/screens/admin/view_faculty.dart +++ b/frontend/lib/screens/admin/view_faculty.dart @@ -26,7 +26,9 @@ class ViewFaculty extends ConsumerWidget { child: SizedBox( width: 390, child: SearchBar( - controller: ref.read(facultyProvider.notifier).searchFacultyController, + controller: ref + .read(facultyProvider.notifier) + .searchFacultyController, hintText: 'Enter faculty name', onChanged: (value) { ref.read(facultyProvider.notifier).searchFaculties(); @@ -59,18 +61,22 @@ class ViewFaculty extends ConsumerWidget { } return ListView.builder( itemBuilder: (_, index) { - List faculties = ref.read(facultyProvider).filteredFaculties; + List faculties = + ref.read(facultyProvider).filteredFaculties; return Container( - margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), + margin: const EdgeInsets.symmetric( + horizontal: 20, vertical: 10), child: ListTile( tileColor: Colors.grey.shade200, selectedTileColor: Colors.red, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(15), ), - contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), + contentPadding: const EdgeInsets.symmetric( + horizontal: 20, vertical: 10), title: Text('Faculty : ${faculties[index].name}'), - subtitle: Text('Faculty Email : ${faculties[index].facultyMail}'), + subtitle: + Text('Faculty Email : ${faculties[index].email}'), trailing: SizedBox( width: 100, child: Row( @@ -78,18 +84,21 @@ class ViewFaculty extends ConsumerWidget { IconButton( iconSize: 20, icon: const Icon(Icons.edit), - onPressed: () => showDialog( + onPressed: () => showDialog( context: context, builder: (_) => const AlertDialog( title: Text('Edit Faculty'), - content: Text("Faculty editing will be added in future"), + content: Text( + "Faculty editing will be added in future"), ), ), ), IconButton( iconSize: 20, icon: const Icon(Icons.delete), - onPressed: () => ref.read(facultyProvider.notifier).removeFaculty(faculties[index]), + onPressed: () => ref + .read(facultyProvider.notifier) + .removeFaculty(faculties[index]), ), ], ), diff --git a/frontend/lib/screens/auth/signin_page.dart b/frontend/lib/screens/auth/login_page.dart similarity index 98% rename from frontend/lib/screens/auth/signin_page.dart rename to frontend/lib/screens/auth/login_page.dart index e7ed415..1a8338d 100644 --- a/frontend/lib/screens/auth/signin_page.dart +++ b/frontend/lib/screens/auth/login_page.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; +import 'package:slide_switcher/slide_switcher.dart'; import '../../components/snackbar.dart'; import '../../services/auth/auth_service.dart'; @@ -106,7 +107,6 @@ class _SignInState extends State { otpController2.text + otpController3.text + otpController4.text; - print('OTP: $otp'); // Print the OTP // Call verifyOTP final isVerified = await authService.verifyOTP(emailController.text, otp); From e14e272f4eba2233c84bde3a44c4c20b178e5f74 Mon Sep 17 00:00:00 2001 From: Arin Nigam Date: Wed, 31 Jan 2024 21:59:53 +0530 Subject: [PATCH 03/12] Deleted User Created different models instead of a single user --- frontend/lib/models/user.dart | 19 ------------------ frontend/lib/provider/user_provider.dart | 25 ------------------------ 2 files changed, 44 deletions(-) delete mode 100644 frontend/lib/models/user.dart delete mode 100644 frontend/lib/provider/user_provider.dart diff --git a/frontend/lib/models/user.dart b/frontend/lib/models/user.dart deleted file mode 100644 index d8cc0dd..0000000 --- a/frontend/lib/models/user.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:flutter_secure_storage/flutter_secure_storage.dart'; - -enum UserType { faculty, student, admin } - -class User { - String email; - String otp; - UserType userType; - final storage = FlutterSecureStorage(); - User({required this.email, required this.otp, required this.userType}); - - Future storeJwt(String jwt) async { - await storage.write(key: 'jwt', value: jwt); - } - - Future getJwt() async { - return await storage.read(key: 'jwt'); - } -} diff --git a/frontend/lib/provider/user_provider.dart b/frontend/lib/provider/user_provider.dart deleted file mode 100644 index a3f2340..0000000 --- a/frontend/lib/provider/user_provider.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:flutter/widgets.dart'; - -enum UserType { - student, - faculty, - admin, -} - -class UserProvider extends ChangeNotifier { - String? _userType; - String? _userEmail; - - String? get userType => _userType; - String? get userEmail => _userEmail; - - void setUserType(String? userType) { - _userType = userType; - notifyListeners(); - } - - void setUserEmail(String? userEmail) { - _userEmail = userEmail; - notifyListeners(); - } -} From c4ded313a63e28354222c862f7229f41da3a44fb Mon Sep 17 00:00:00 2001 From: Arin Nigam Date: Wed, 31 Jan 2024 22:37:24 +0530 Subject: [PATCH 04/12] fixed null id --- frontend/lib/models/course.dart | 4 ++-- frontend/lib/provider/courses_provider.dart | 1 + frontend/lib/provider/faculty_provider.dart | 2 +- frontend/lib/provider/student_provider.dart | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/lib/models/course.dart b/frontend/lib/models/course.dart index 4e617a6..168e332 100644 --- a/frontend/lib/models/course.dart +++ b/frontend/lib/models/course.dart @@ -1,11 +1,11 @@ class Course { - final String? id; + final String id; final String courseCode; final String courseName; final List branches; Course({ - this.id, + required this.id, required this.courseCode, required this.courseName, required this.branches, diff --git a/frontend/lib/provider/courses_provider.dart b/frontend/lib/provider/courses_provider.dart index 539fd3f..fad4b8a 100644 --- a/frontend/lib/provider/courses_provider.dart +++ b/frontend/lib/provider/courses_provider.dart @@ -110,6 +110,7 @@ class CoursesNotifier extends StateNotifier { void addCourse() { _logger.i("Adding course ${state.courseCodeController.text}"); final newCourse = Course( + id: (state.courses.length + 1).toString(), courseCode: state.courseCodeController.text, courseName: state.courseNameController.text, branches: state.branches, diff --git a/frontend/lib/provider/faculty_provider.dart b/frontend/lib/provider/faculty_provider.dart index 97d1391..74c1097 100644 --- a/frontend/lib/provider/faculty_provider.dart +++ b/frontend/lib/provider/faculty_provider.dart @@ -91,7 +91,7 @@ class FacultyStateNotifier extends StateNotifier { void addFaculty() { Faculty faculty = Faculty( - id: '', + id: (state.faculties.length + 1).toString(), name: state.facultyNameController.text, email: state.facultyEmailController.text, courses: state.selectedCourses, diff --git a/frontend/lib/provider/student_provider.dart b/frontend/lib/provider/student_provider.dart index d2adec8..3a336a4 100644 --- a/frontend/lib/provider/student_provider.dart +++ b/frontend/lib/provider/student_provider.dart @@ -127,7 +127,7 @@ class StudentProvider extends StateNotifier { final newState = state.copyWith( students: [ Student( - id: '', + id: (state.students.length + 1).toString(), name: state.studentNameController.text, email: state.studentEmailController.text, rollNumber: state.studentRollNoController.text, From 8a415b592725e43456b24c1808ced68122d288c9 Mon Sep 17 00:00:00 2001 From: Arin Nigam Date: Fri, 2 Feb 2024 22:36:37 +0530 Subject: [PATCH 05/12] changed admin auth admin can now log in using email id and password --- backend/constants/errorMessages.js | 1 + backend/models/admin.js | 29 ++-- backend/models/user.js | 27 ---- backend/resources/authResource.js | 86 +++++----- frontend/lib/components/otp_box.dart | 29 ++++ frontend/lib/constants/constants.dart | 98 +++++++---- frontend/lib/routes/routes.dart | 10 +- frontend/lib/screens/auth/admin_login.dart | 109 +++++++++++++ frontend/lib/screens/auth/login_page.dart | 160 ------------------ frontend/lib/screens/auth/user_login.dart | 162 +++++++++++++++++++ frontend/lib/services/auth/auth_service.dart | 86 +++++++++- 11 files changed, 516 insertions(+), 281 deletions(-) delete mode 100644 backend/models/user.js create mode 100644 frontend/lib/components/otp_box.dart create mode 100644 frontend/lib/screens/auth/admin_login.dart delete mode 100644 frontend/lib/screens/auth/login_page.dart create mode 100644 frontend/lib/screens/auth/user_login.dart diff --git a/backend/constants/errorMessages.js b/backend/constants/errorMessages.js index 9629e84..82c0512 100644 --- a/backend/constants/errorMessages.js +++ b/backend/constants/errorMessages.js @@ -3,6 +3,7 @@ export const userAlreadyExists = "User with this email already exists!"; export const userNotFound = "User with this email does not exist!"; export const incorrectPassword = "Incorrect password."; export const internalServerError = "Internal Server Error. Please try again later."; +export const userCreated = "User created successfully"; //Database Connection export const databaseConnected = "Database connected successfully"; diff --git a/backend/models/admin.js b/backend/models/admin.js index 142623d..c021c4c 100644 --- a/backend/models/admin.js +++ b/backend/models/admin.js @@ -1,18 +1,23 @@ -import mongoose from "mongoose"; +import mongoose from 'mongoose'; const adminSchema = new mongoose.Schema({ - name: { - type: String, - default: 'Smart Insti User' + email:{ + required: true, + type:String, + validate: { + validator: (value) => { + const re = + /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i; + return value.match(re); + }, + message: "Please enter a valid email address", + }, }, - email: { - type: String, + password:{ required: true, - unique: true + type:String, }, -}); - -const Admin = mongoose.model('Admin', adminSchema); - -export default Admin; +}) +const Admin = mongoose.model("Admin", adminSchema); +export default Admin; \ No newline at end of file diff --git a/backend/models/user.js b/backend/models/user.js deleted file mode 100644 index d30174a..0000000 --- a/backend/models/user.js +++ /dev/null @@ -1,27 +0,0 @@ -import mongoose from 'mongoose'; - -const userSchema = new mongoose.Schema({ - name:{ - required: true, - type:String, - }, - email:{ - required: true, - type:String, - validate: { - validator: (value) => { - const re = - /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i; - return value.match(re); - }, - message: "Please enter a valid email address", - }, - }, - password:{ - required: true, - type:String, - }, -}) - -const User = mongoose.model("User", userSchema); -export default User; \ No newline at end of file diff --git a/backend/resources/authResource.js b/backend/resources/authResource.js index 09f7def..aaed7ec 100644 --- a/backend/resources/authResource.js +++ b/backend/resources/authResource.js @@ -1,6 +1,5 @@ import mongoose from 'mongoose'; import express from 'express'; -import User from "../models/user.js"; import bcryptjs from 'bcryptjs'; import jwt from 'jsonwebtoken'; import * as errorMessages from '../constants/errorMessages.js'; @@ -10,51 +9,50 @@ import Admin from '../models/admin.js'; const authRouter = express.Router(); -// // Sign-Up Route -// authRouter.post('/signup',async (req,res)=>{ -// try { -// const { name, email, password } = req.body; -// const existingUser = await User.findOne({ email }); -// if (existingUser){ -// return res.status(400).json({ msg: errorMessages.userAlreadyExists }); -// } -// const hashedPassword = await bcryptjs.hash(password,8); -// let user = new User({ -// email, -// password: hashedPassword, -// name, -// }); -// user = await user.save(); -// res.json(user); -// } catch (e) { -// res.status(500).json({error:e.message}); -// } -// }) +// Sign-Up Route +authRouter.post('/signup',async (req,res)=>{ + try { + const {email, password } = req.body; + const existingUser = await Admin.findOne({ email }); + if (existingUser){ + return res.status(400).json({ msg: errorMessages.userAlreadyExists }); + } + const hashedPassword = await bcryptjs.hash(password,8); + let admin = new Admin({ + email, + password: hashedPassword, + }); + admin = await admin.save(); + res.json(admin); + } catch (e) { + res.status(500).json({error:e.message}); + } +}) -// // Sign-In Route -// authRouter.post("/signin", async (req, res) => { -// try { -// const { email, password } = req.body; +// Sign-In Route +authRouter.post("/signin", async (req, res) => { + try { + const { email, password } = req.body; -// const user = await User.findOne({ email }); -// if (!user) { -// return res -// .status(400) -// .json({ msg: errorMessages.userNotFound }); -// } + const user = await Admin.findOne({ email }); + if (!user) { + return res + .status(400) + .json({ msg: errorMessages.userNotFound }); + } -// const isMatch = await bcryptjs.compare(password, user.password); + const isMatch = await bcryptjs.compare(password, user.password); -// if (!isMatch) { -// return res.status(400).json({ msg: errorMessages.incorrectPassword }); -// } + if (!isMatch) { + return res.status(400).json({ msg: errorMessages.incorrectPassword }); + } -// const token = jwt.sign({ id: user._id }, "passwordKey"); -// res.json({ token, ...user._doc }); -// } catch (e) { -// res.status(500).json({ error: errorMessages.internalServerError }); -// } -// }); + const token = jwt.sign({ id: user._id }, "passwordKey"); + res.json({ token, ...user._doc }); + } catch (e) { + res.status(500).json({ error: errorMessages.internalServerError }); + } +}); authRouter.post('/login', async (req, res) => { const { email, userType } = req.body; @@ -73,7 +71,7 @@ authRouter.post('/login', async (req, res) => { userCollection = Admin; break; default: - return res.status(400).send({ error: 'Invalid user type' }); + return res.status(400).send({ error: errorMessages.invalidUserType }); } existingUser = await userCollection.findOne({ email }); @@ -81,9 +79,9 @@ authRouter.post('/login', async (req, res) => { if (!existingUser) { const newUser = new userCollection({ email }); await newUser.save(); - res.send({ message: 'User created successfully', user: newUser }); + res.send({ message: errorMessages.userCreated, user: newUser }); } else { - res.send({ message: 'User already exists' }); + res.send({ message: errorMessages.userAlreadyExists, user: existingUser}); } }); diff --git a/frontend/lib/components/otp_box.dart b/frontend/lib/components/otp_box.dart new file mode 100644 index 0000000..e21cf80 --- /dev/null +++ b/frontend/lib/components/otp_box.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; + +class OTPBox extends StatelessWidget { + final TextEditingController controller; + final FocusNode focusNode; + OTPBox({required this.controller, required this.focusNode}); + @override + Widget build(BuildContext context) { + return Container( + width: 50.0, + height: 50.0, + decoration: BoxDecoration( + border: Border.all(color: Colors.grey), + borderRadius: BorderRadius.circular(8.0), + ), + child: TextField( + controller: controller, + focusNode: focusNode, + keyboardType: TextInputType.number, + maxLength: 1, + textAlign: TextAlign.center, + decoration: InputDecoration( + counterText: '', + border: InputBorder.none, + ), + ), + ); + } +} diff --git a/frontend/lib/constants/constants.dart b/frontend/lib/constants/constants.dart index 8e5bda7..88c923e 100644 --- a/frontend/lib/constants/constants.dart +++ b/frontend/lib/constants/constants.dart @@ -6,32 +6,58 @@ class AppConstants { static const Color seedColor = Colors.lightBlueAccent; } +class AuthConstants { + static List? roles = []; +} + class Branches { static List> branchList = const [ - DropdownMenuItem(value: "Computer Science and Engineering", child: Text("Computer Science and Engineering")), - DropdownMenuItem(value: "Computer Science", child: Text("Computer Science")), - DropdownMenuItem(value: "Electrical Engineering", child: Text("Electrical Engineering")), - DropdownMenuItem(value: "Mechanical Engineering", child: Text("Mechanical Engineering")), - DropdownMenuItem(value: "Civil Engineering", child: Text("Civil Engineering")), - DropdownMenuItem(value: "Chemical Engineering", child: Text("Chemical Engineering")), - DropdownMenuItem(value: "Aerospace Engineering", child: Text("Aerospace Engineering")), - DropdownMenuItem(value: "Metallurgical Engineering", child: Text("Metallurgical Engineering")), - DropdownMenuItem(value: "Ocean Engineering", child: Text("Ocean Engineering")), - DropdownMenuItem(value: "Biotechnology", child: Text("Biotechnology")), + DropdownMenuItem( + value: "Computer Science and Engineering", + child: Text("Computer Science and Engineering")), + DropdownMenuItem( + value: "Computer Science", child: Text("Computer Science")), + DropdownMenuItem( + value: "Electrical Engineering", child: Text("Electrical Engineering")), + DropdownMenuItem( + value: "Mechanical Engineering", child: Text("Mechanical Engineering")), + DropdownMenuItem( + value: "Civil Engineering", child: Text("Civil Engineering")), + DropdownMenuItem( + value: "Chemical Engineering", child: Text("Chemical Engineering")), + DropdownMenuItem( + value: "AerosRpace Engineering", child: Text("Aerospace Engineering")), + DropdownMenuItem( + value: "Metallurgical Engineering", + child: Text("Metallurgical Engineering")), + DropdownMenuItem( + value: "Ocean Engineering", child: Text("Ocean Engineering")), + DropdownMenuItem( + value: "Biotechnology", child: Text("Biotechnology")), DropdownMenuItem(value: "Physics", child: Text("Physics")), DropdownMenuItem(value: "Chemistry", child: Text("Chemistry")), DropdownMenuItem(value: "Mathematics", child: Text("Mathematics")), - DropdownMenuItem(value: "Humanities and Social Sciences", child: Text("Humanities and Social Sciences")), - DropdownMenuItem(value: "Management Studies", child: Text("Management Studies")), - DropdownMenuItem(value: "Nanotechnology", child: Text("Nanotechnology")), - DropdownMenuItem(value: "Energy Engineering", child: Text("Energy Engineering")), - DropdownMenuItem(value: "Environmental Engineering", child: Text("Environmental Engineering")), + DropdownMenuItem( + value: "Humanities and Social Sciences", + child: Text("Humanities and Social Sciences")), + DropdownMenuItem( + value: "Management Studies", child: Text("Management Studies")), + DropdownMenuItem( + value: "Nanotechnology", child: Text("Nanotechnology")), + DropdownMenuItem( + value: "Energy Engineering", child: Text("Energy Engineering")), + DropdownMenuItem( + value: "Environmental Engineering", + child: Text("Environmental Engineering")), DropdownMenuItem( value: "Industrial Engineering and Operations Research", child: Text("Industrial Engineering and Operations Research")), - DropdownMenuItem(value: "Systems and Control Engineering", child: Text("Systems and Control Engineering")), DropdownMenuItem( - value: "Materials Science and Engineering", child: Text("Materials Science and Engineering")), + value: "Systems and Control Engineering", + child: Text("Systems and Control Engineering")), + DropdownMenuItem( + value: "Materials Science and Engineering", + child: Text("Materials Science and Engineering")), ]; } @@ -40,10 +66,14 @@ class LayoutConstants {} class StudentRoles { static List> studentRoleList = const [ DropdownMenuItem(value: "Student", child: Text("Student")), - DropdownMenuItem(value: "Class Representative", child: Text("Class Representative")), - DropdownMenuItem(value: "Cultural Secretary", child: Text("Cultural Secretary")), - DropdownMenuItem(value: "Teaching Assistant", child: Text("Teaching Assistant")), - DropdownMenuItem(value: "Vice President", child: Text("Vice President")), + DropdownMenuItem( + value: "Class Representative", child: Text("Class Representative")), + DropdownMenuItem( + value: "Cultural Secretary", child: Text("Cultural Secretary")), + DropdownMenuItem( + value: "Teaching Assistant", child: Text("Teaching Assistant")), + DropdownMenuItem( + value: "Vice President", child: Text("Vice President")), DropdownMenuItem(value: "Monitor", child: Text("Monitor")), DropdownMenuItem(value: "President", child: Text("President")), DropdownMenuItem(value: "Instructor", child: Text("Instructor")), @@ -107,22 +137,22 @@ class MessMenuConstants { ]; static final List mealTypes = [ - Text('Breakfast',style: TextStyle(color: Colors.teal.shade900, fontSize: 14)), - Text('Lunch',style: TextStyle(color: Colors.teal.shade900, fontSize: 14)), - Text('Snacks',style: TextStyle(color: Colors.teal.shade900, fontSize: 14)), - Text('Dinner',style: TextStyle(color: Colors.teal.shade900, fontSize: 14)), + Text('Breakfast', + style: TextStyle(color: Colors.teal.shade900, fontSize: 14)), + Text('Lunch', style: TextStyle(color: Colors.teal.shade900, fontSize: 14)), + Text('Snacks', style: TextStyle(color: Colors.teal.shade900, fontSize: 14)), + Text('Dinner', style: TextStyle(color: Colors.teal.shade900, fontSize: 14)), ]; - static const Map weekdaysShortToLong = { - "Sun":"Sunday", - "Mon":"Monday", - "Tue":"Tuesday", - "Wed":"Wednesday", - "Thu":"Thursday", - "Fri":"Friday", - "Sat":"Saturday", + static const Map weekdaysShortToLong = { + "Sun": "Sunday", + "Mon": "Monday", + "Tue": "Tuesday", + "Wed": "Wednesday", + "Thu": "Thursday", + "Fri": "Friday", + "Sat": "Saturday", }; - } class Validators { diff --git a/frontend/lib/routes/routes.dart b/frontend/lib/routes/routes.dart index c87e66d..0a5c294 100644 --- a/frontend/lib/routes/routes.dart +++ b/frontend/lib/routes/routes.dart @@ -10,14 +10,20 @@ import '../screens/admin/add_menu.dart'; import '../screens/admin/view_courses.dart'; import '../screens/admin/view_faculty.dart'; import '../screens/admin/view_menu.dart'; -import '../screens/auth/login_page.dart'; +import '../screens/auth/admin_login.dart'; +import '../screens/auth/user_login.dart'; final GoRouter routes = GoRouter( routes: [ GoRoute( path: '/', - pageBuilder: (context, state) => MaterialPage(child: SignIn()), + pageBuilder: (context, state) => MaterialPage(child: UserLogin()), routes: [ + GoRoute( + path: 'admin_login', + pageBuilder: (context, state) => + const MaterialPage(child: AdminLogin()), + ), GoRoute( path: 'admin_home', pageBuilder: (context, state) => diff --git a/frontend/lib/screens/auth/admin_login.dart b/frontend/lib/screens/auth/admin_login.dart new file mode 100644 index 0000000..84cca40 --- /dev/null +++ b/frontend/lib/screens/auth/admin_login.dart @@ -0,0 +1,109 @@ +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; +import 'package:http/http.dart' as http; + +import '../../services/auth/auth_service.dart'; + +class AdminLogin extends StatefulWidget { + const AdminLogin({super.key}); + + @override + State createState() => _AdminLoginState(); +} + +class _AdminLoginState extends State { + @override + Widget build(BuildContext context) { + final _signInFormKey = GlobalKey(); + final AuthService authService = AuthService(); + final TextEditingController _emailController = TextEditingController(); + final TextEditingController _passwordController = TextEditingController(); + String message = ''; + + @override + void dispose() { + _emailController.dispose(); + _passwordController.dispose(); + } + + void signInAdmin() { + authService.signInAdmin( + context: context, + email: _emailController.text, + password: _passwordController.text, + ); + } + + return Scaffold( + appBar: AppBar( + title: Text('Admin Login'), + leading: GestureDetector( + onTap: () { + context.go('/'); + }, + child: const Icon(Icons.arrow_back), + ), + ), + body: SafeArea( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Center( + child: SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const Text( + 'Welcome Admin', + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.w500, + ), + ), + ListTile( + title: const Text( + 'Sign-In', + style: TextStyle( + fontSize: 20.0, + fontWeight: FontWeight.bold, + ), + ), + ), + Container( + padding: const EdgeInsets.all(8), + color: Colors.white, + child: Form( + key: _signInFormKey, + child: Column( + children: [ + TextFormField( + controller: _emailController, + decoration: InputDecoration(hintText: 'Email'), + ), + const SizedBox(height: 10), + TextFormField( + obscureText: true, + controller: _passwordController, + decoration: InputDecoration(hintText: 'Password'), + ), + const SizedBox(height: 10), + ElevatedButton( + child: Text('Sign In'), + onPressed: () { + if (_signInFormKey.currentState!.validate()) { + signInAdmin(); + } + }, + ), + ], + ), + ), + ), + ], + ), + ), + ), + )), + ); + } +} diff --git a/frontend/lib/screens/auth/login_page.dart b/frontend/lib/screens/auth/login_page.dart deleted file mode 100644 index 1a8338d..0000000 --- a/frontend/lib/screens/auth/login_page.dart +++ /dev/null @@ -1,160 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:go_router/go_router.dart'; -import 'package:slide_switcher/slide_switcher.dart'; -import '../../components/snackbar.dart'; -import '../../services/auth/auth_service.dart'; - -class SignIn extends StatefulWidget { - @override - _SignInState createState() => _SignInState(); -} - -class _SignInState extends State { - bool showOTPFields = false; - final emailRegex = RegExp(r'^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]+'); - final emailController = TextEditingController(); - final otpController1 = TextEditingController(); - final otpController2 = TextEditingController(); - final otpController3 = TextEditingController(); - final otpController4 = TextEditingController(); - - final focusNode1 = FocusNode(); - final focusNode2 = FocusNode(); - final focusNode3 = FocusNode(); - final focusNode4 = FocusNode(); - - final authService = AuthService(); // Create an instance of AuthService - - @override - void initState() { - super.initState(); - - // When the text in the first OTPBox changes, request focus for the second OTPBox - otpController1.addListener(() { - if (otpController1.text.length >= 1) { - FocusScope.of(context).requestFocus(focusNode2); - } - }); - - // Do the same for the other OTPBoxes - otpController2.addListener(() { - if (otpController2.text.length >= 1) { - FocusScope.of(context).requestFocus(focusNode3); - } - }); - - otpController3.addListener(() { - if (otpController3.text.length >= 1) { - FocusScope.of(context).requestFocus(focusNode4); - } - }); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text('Login'), - ), - body: Padding( - padding: EdgeInsets.all(16.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - TextField( - controller: emailController, - decoration: InputDecoration( - labelText: 'Email', - ), - ), - SizedBox(height: 16.0), - ElevatedButton( - onPressed: () { - // Call sendOtp when the button is clicked - if (emailRegex.hasMatch(emailController.text)) { - // If the email is valid, set the state - setState(() { - showOTPFields = true; - }); - authService.sendOTP( - context: context, - email: emailController.text, - ); - } else { - // If the email is not valid, show a SnackBar with an error message - showSnackBar( - context, - 'Please enter a valid email', - ); - } - }, - child: Text('Send OTP'), - ), - if (showOTPFields) ...[ - SizedBox(height: 16.0), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - OTPBox(controller: otpController1, focusNode: focusNode1), - OTPBox(controller: otpController2, focusNode: focusNode2), - OTPBox(controller: otpController3, focusNode: focusNode3), - OTPBox(controller: otpController4, focusNode: focusNode4), - ], - ), - ElevatedButton( - onPressed: () async { - final otp = otpController1.text + - otpController2.text + - otpController3.text + - otpController4.text; - // Call verifyOTP - final isVerified = - await authService.verifyOTP(emailController.text, otp); - - if (isVerified) { - // Navigate to the admin home page - context.go('/admin_home'); - } else { - showSnackBar( - context, - 'Incorrect OTP', - ); - } - }, - child: Text('Verify OTP'), - ), - ], - ], - ), - ), - ); - } -} - -class OTPBox extends StatelessWidget { - final TextEditingController controller; - final FocusNode focusNode; - OTPBox({required this.controller, required this.focusNode}); - @override - Widget build(BuildContext context) { - return Container( - width: 50.0, - height: 50.0, - decoration: BoxDecoration( - border: Border.all(color: Colors.grey), - borderRadius: BorderRadius.circular(8.0), - ), - child: TextField( - controller: controller, - focusNode: focusNode, - keyboardType: TextInputType.number, - maxLength: 1, - textAlign: TextAlign.center, - decoration: InputDecoration( - counterText: '', - border: InputBorder.none, - ), - ), - ); - } -} diff --git a/frontend/lib/screens/auth/user_login.dart b/frontend/lib/screens/auth/user_login.dart new file mode 100644 index 0000000..f9b1d4f --- /dev/null +++ b/frontend/lib/screens/auth/user_login.dart @@ -0,0 +1,162 @@ +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; +import 'package:slide_switcher/slide_switcher.dart'; +import '../../components/otp_box.dart'; +import '../../components/snackbar.dart'; +import '../../services/auth/auth_service.dart'; + +class UserLogin extends StatefulWidget { + @override + _UserLoginState createState() => _UserLoginState(); +} + +class _UserLoginState extends State { + bool showOTPFields = false; + final emailRegex = RegExp(r'^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]+'); + final emailController = TextEditingController(); + final passwordController = TextEditingController(); + final otpController1 = TextEditingController(); + final otpController2 = TextEditingController(); + final otpController3 = TextEditingController(); + final otpController4 = TextEditingController(); + + final focusNode1 = FocusNode(); + final focusNode2 = FocusNode(); + final focusNode3 = FocusNode(); + final focusNode4 = FocusNode(); + + final authService = AuthService(); // Create an instance of AuthService + + @override + void initState() { + super.initState(); + + // When the text in the first OTPBox changes, request focus for the second OTPBox + otpController1.addListener(() { + if (otpController1.text.length >= 1) { + FocusScope.of(context).requestFocus(focusNode2); + } + }); + + otpController2.addListener(() { + if (otpController2.text.length >= 1) { + FocusScope.of(context).requestFocus(focusNode3); + } + }); + + otpController3.addListener(() { + if (otpController3.text.length >= 1) { + FocusScope.of(context).requestFocus(focusNode4); + } + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + actions: [ + GestureDetector( + onTap: () { + context.go('/admin_login'); + }, + child: Padding( + padding: const EdgeInsets.only(right: 16.0), + child: Text( + 'Admin', + style: TextStyle(color: Colors.teal), + ), + ), + ), + ], + title: Text('Login'), + ), + body: SafeArea( + child: Padding( + padding: EdgeInsets.all(16.0), + child: Center( + child: SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const Text( + 'Welcome User', + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.w500, + ), + ), + SizedBox(height: 16.0), + TextField( + controller: emailController, + decoration: InputDecoration( + labelText: 'Email', + ), + ), + SizedBox(height: 16.0), + ElevatedButton( + onPressed: () { + if (emailRegex.hasMatch(emailController.text)) { + setState(() { + showOTPFields = true; + }); + authService.sendOTP( + context: context, + email: emailController.text, + ); + } else { + showSnackBar( + context, + 'Please enter a valid email', + ); + } + }, + child: Text('Send OTP'), + ), + SizedBox(height: 16.0), + if (showOTPFields) ...[ + SizedBox(height: 16.0), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + OTPBox( + controller: otpController1, focusNode: focusNode1), + OTPBox( + controller: otpController2, focusNode: focusNode2), + OTPBox( + controller: otpController3, focusNode: focusNode3), + OTPBox( + controller: otpController4, focusNode: focusNode4), + ], + ), + ElevatedButton( + onPressed: () async { + final otp = otpController1.text + + otpController2.text + + otpController3.text + + otpController4.text; + final isVerified = await authService.verifyOTP( + emailController.text, otp); + + if (isVerified) { + context.go('/admin_home'); + } else { + showSnackBar( + context, + 'Incorrect OTP', + ); + } + }, + child: Text('Verify OTP'), + ), + ] + ], + ), + ), + ), + ), + ), + ); + } +} diff --git a/frontend/lib/services/auth/auth_service.dart b/frontend/lib/services/auth/auth_service.dart index 53234c2..dd89b5f 100644 --- a/frontend/lib/services/auth/auth_service.dart +++ b/frontend/lib/services/auth/auth_service.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:go_router/go_router.dart'; import 'package:http/http.dart' as http; import '../../components/snackbar.dart'; @@ -11,6 +12,67 @@ class AuthService { final storage = FlutterSecureStorage(); final String baseUrl = 'http://10.0.2.2:3000'; // Replace with your backend API URL + Future signUpAdmin({ + required BuildContext context, + required String email, + required String password, + }) async { + try { + http.Response res = await http.post( + Uri.parse('$baseUrl/signup'), + body: jsonEncode({ + 'email': email, + 'password': password, + }), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }, + ); + + httpErrorHandle( + response: res, + context: context, + onSuccess: () { + showSnackBar( + context, + 'Account created! Login with the same credentials!', + ); + }, + ); + } catch (e) { + showSnackBar(context, e.toString()); + print(e); + } + } + + Future signInAdmin({ + required BuildContext context, + required String email, + required String password, + }) async { + try { + http.Response res = await http.post( + Uri.parse('$baseUrl/signin'), + body: jsonEncode({ + 'email': email, + 'password': password, + }), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }, + ); + + httpErrorHandle( + response: res, + context: context, + onSuccess: () async { + context.go('/admin_home'); + }, + ); + } catch (e) { + showSnackBar(context, e.toString()); + } + } Future sendOTP({ required BuildContext context, @@ -53,15 +115,35 @@ class AuthService { if (response.statusCode == 200) { final Map data = jsonDecode(response.body); final String jwt = data['token']; - await storage.write(key: 'jwt', value: jwt); + loginUser(email, jwt); return true; } else { return false; } } catch (e) { - // Handle network or server error print(e); return false; } } + + Future loginUser(String email, String jwt) async { + var url = Uri.parse('$baseUrl/login'); + var response = await http.post( + url, + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + 'Authorization': 'Bearer $jwt', + }, + body: jsonEncode({ + 'email': email, + }), + ); + + if (response.statusCode == 200) { + print('Login successful'); + } else { + print('Login failed'); + } + } } From d2db4080154222a05d1f1f61c2b8a7931f3fcef4 Mon Sep 17 00:00:00 2001 From: Arin Nigam Date: Fri, 2 Feb 2024 23:18:48 +0530 Subject: [PATCH 06/12] updated models changes made as suggested by @Aditya062003 --- backend/models/course.js | 8 + backend/models/faculty.js | 9 + frontend/lib/constants/dummy_entries.dart | 306 ++++++++++++++------ frontend/lib/models/admin.dart | 2 +- frontend/lib/models/course.dart | 8 + frontend/lib/models/faculty.dart | 8 + frontend/lib/provider/courses_provider.dart | 12 + frontend/lib/provider/faculty_provider.dart | 20 ++ 8 files changed, 282 insertions(+), 91 deletions(-) diff --git a/backend/models/course.js b/backend/models/course.js index 592fb5f..f82143b 100644 --- a/backend/models/course.js +++ b/backend/models/course.js @@ -10,6 +10,14 @@ const courseSchema = new mongoose.Schema({ required: true, unique: true }, + primary_room: { + type: String, + required: true, + }, + credits: { + type: Number, + required: true, + }, branches: [{ type: String, required: true diff --git a/backend/models/faculty.js b/backend/models/faculty.js index 0913954..a9534e2 100644 --- a/backend/models/faculty.js +++ b/backend/models/faculty.js @@ -10,10 +10,19 @@ const facultySchema = new mongoose.Schema({ required: true, unique: true }, + cabin_number: { + type: String, + required: true, + }, + department: { + type: String, + required: true, + }, courses: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Course' }], + }); const Faculty = mongoose.model('Faculty', facultySchema); diff --git a/frontend/lib/constants/dummy_entries.dart b/frontend/lib/constants/dummy_entries.dart index 1b8239a..5760e81 100644 --- a/frontend/lib/constants/dummy_entries.dart +++ b/frontend/lib/constants/dummy_entries.dart @@ -80,136 +80,204 @@ class DummyCourses { id: '1', courseCode: 'CS101', courseName: 'Introduction to Computer Science', - branches: ['Computer Science']), + branches: ['Computer Science'], + credits: 3, + primaryRoom: 'LT-1'), Course( id: '2', courseCode: 'ME102', courseName: 'Mechanical Engineering Basics', - branches: ['Mechanical Engineering']), + branches: ['Mechanical Engineering'], + credits: 3, + primaryRoom: 'LT-2'), Course( id: '3', courseCode: 'EE103', courseName: 'Electrical Engineering Fundamentals', - branches: ['Electrical Engineering']), + branches: ['Electrical Engineering'], + credits: 3, + primaryRoom: 'LT-3'), Course( id: '4', courseCode: 'EE104', courseName: 'Civil Engineering Principles', - branches: ['Civil Engineering']), + branches: ['Civil Engineering'], + credits: 3, + primaryRoom: 'LT-4'), Course( id: '5', courseCode: 'CHE105', courseName: 'Chemical Engineering Basics', - branches: ['Chemical Engineering']), + branches: ['Chemical Engineering'], + credits: 3, + primaryRoom: 'LH-1'), Course( id: '6', courseCode: 'BT106', courseName: 'Biotechnology Fundamentals', - branches: ['Biotechnology']), + branches: ['Biotechnology'], + credits: 3, + primaryRoom: 'LH-2'), Course( id: '7', courseCode: 'AE107', courseName: 'Aerospace Engineering Introduction', - branches: ['Aerospace Engineering']), + branches: ['Aerospace Engineering'], + credits: 3, + primaryRoom: 'LH-3'), Course( id: '8', courseCode: 'IT108', courseName: 'Information Technology Essentials', - branches: ['Information Technology']), + branches: ['Information Technology'], + credits: 3, + primaryRoom: 'LH-4'), Course( id: '9', courseCode: 'MT109', courseName: 'Mechatronics Basics', - branches: ['Mechatronics']), + branches: ['Mechatronics'], + credits: 3, + primaryRoom: 'LH-5'), Course( id: '10', courseCode: 'RE110', courseName: 'Robotics Engineering Fundamentals', - branches: ['Robotics Engineering']), + branches: ['Robotics Engineering'], + credits: 3, + primaryRoom: 'LH-6'), Course( id: '11', courseCode: 'IE111', courseName: 'Industrial Engineering Principles', - branches: ['Industrial Engineering']), + branches: ['Industrial Engineering'], + credits: 3, + primaryRoom: 'LH-7'), Course( id: '12', courseCode: 'CE112', courseName: 'Computer Engineering Basics', - branches: ['Computer Engineering']), + branches: ['Computer Engineering'], + credits: 3, + primaryRoom: 'LH-8'), Course( id: '13', courseCode: 'SE113', courseName: 'Software Engineering Fundamentals', - branches: ['Software Engineering']), + branches: ['Software Engineering'], + credits: 3, + primaryRoom: 'ROOM-101'), Course( id: '14', courseCode: 'EN114', courseName: 'Environmental Engineering Basics', - branches: ['Environmental Engineering']), + branches: ['Environmental Engineering'], + credits: 3, + primaryRoom: 'ROOM-102'), Course( id: '15', courseCode: 'PE115', courseName: 'Petroleum Engineering Introduction', - branches: ['Petroleum Engineering']), + branches: ['Petroleum Engineering'], + credits: 3, + primaryRoom: 'ROOM-103'), Course( id: '16', courseCode: 'NE116', courseName: 'Nuclear Engineering Basics', - branches: ['Nuclear Engineering']), + branches: ['Nuclear Engineering'], + credits: 3, + primaryRoom: 'ROOM-104'), Course( id: '17', courseCode: 'BE117', courseName: 'Biomedical Engineering Fundamentals', - branches: ['Biomedical Engineering']), + branches: ['Biomedical Engineering'], + credits: 3, + primaryRoom: 'ROOM-201'), Course( id: '18', courseCode: 'CE118', courseName: 'Chemical Engineering Principles', - branches: ['Chemical Engineering']), + branches: ['Chemical Engineering'], + credits: 3, + primaryRoom: 'ROOM-202'), Course( id: '19', courseCode: 'EE119', courseName: 'Electronics Engineering Basics', - branches: ['Electronics Engineering']), + branches: ['Electronics Engineering'], + credits: 3, + primaryRoom: 'ROOM-203'), Course( id: '20', courseCode: 'CS120', courseName: 'Advanced Computer Science Topics', - branches: ['Computer Science']), + branches: ['Computer Science'], + credits: 3, + primaryRoom: 'ROOM-204'), ]; } class DummyFaculties { static List faculties = [ - Faculty(id: '1', name: 'Dr. Smith', email: 'smith@example.com', courses: [ - DummyCourses.courses[0], - DummyCourses.courses[5], - DummyCourses.courses[10], - ]), Faculty( - id: '2', - name: 'Prof. Johnson', - email: 'johnson@example.com', + id: '1', + name: 'Dr. Smith', + email: 'smith@example.com', courses: [ - DummyCourses.courses[1], - DummyCourses.courses[6], - DummyCourses.courses[11] - ]), - Faculty(id: '3', name: 'Dr. Brown', email: 'brown@example.com', courses: [ - DummyCourses.courses[2], - DummyCourses.courses[7], - DummyCourses.courses[12] - ]), - Faculty(id: '4', name: 'Prof. Davis', email: 'davis@example.com', courses: [ - DummyCourses.courses[3], - DummyCourses.courses[8], - DummyCourses.courses[13] - ]), - Faculty(id: '5', name: 'Dr. Wilson', email: 'wilson@example.com', courses: [ - DummyCourses.courses[4], - DummyCourses.courses[9], - DummyCourses.courses[14] - ]), + DummyCourses.courses[0], + DummyCourses.courses[5], + DummyCourses.courses[10], + ], + cabinNumber: 'C-101', + department: 'Computer Science'), + Faculty( + id: '2', + name: 'Prof. Johnson', + email: 'johnson@example.com', + courses: [ + DummyCourses.courses[1], + DummyCourses.courses[6], + DummyCourses.courses[11] + ], + cabinNumber: 'C-102', + department: 'Mechanical Engineering', + ), + Faculty( + id: '3', + name: 'Dr. Brown', + email: 'brown@example.com', + courses: [ + DummyCourses.courses[2], + DummyCourses.courses[7], + DummyCourses.courses[12] + ], + cabinNumber: 'C-103', + department: 'Electrical Engineering', + ), + Faculty( + id: '4', + name: 'Prof. Davis', + email: 'davis@example.com', + courses: [ + DummyCourses.courses[3], + DummyCourses.courses[8], + DummyCourses.courses[13] + ], + cabinNumber: 'C-104', + department: 'Civil Engineering'), + Faculty( + id: '5', + name: 'Dr. Wilson', + email: 'wilson@example.com', + courses: [ + DummyCourses.courses[4], + DummyCourses.courses[9], + DummyCourses.courses[14] + ], + cabinNumber: 'C-105', + department: 'Chemical Engineering'), Faculty( id: '6', name: 'Prof. Miller', @@ -218,22 +286,42 @@ class DummyFaculties { DummyCourses.courses[0], DummyCourses.courses[5], DummyCourses.courses[10] - ]), - Faculty(id: '7', name: 'Dr. Turner', email: 'turner@example.com', courses: [ - DummyCourses.courses[1], - DummyCourses.courses[6], - DummyCourses.courses[11] - ]), - Faculty(id: '8', name: 'Prof. Clark', email: 'clark@example.com', courses: [ - DummyCourses.courses[2], - DummyCourses.courses[7], - DummyCourses.courses[12] - ]), - Faculty(id: '9', name: 'Dr. Harris', email: 'harris@example.com', courses: [ - DummyCourses.courses[3], - DummyCourses.courses[8], - DummyCourses.courses[13] - ]), + ], + cabinNumber: 'C-106', + department: 'Biotechnology'), + Faculty( + id: '7', + name: 'Dr. Turner', + email: 'turner@example.com', + courses: [ + DummyCourses.courses[1], + DummyCourses.courses[6], + DummyCourses.courses[11] + ], + cabinNumber: 'C-107', + department: 'Aerospace Engineering'), + Faculty( + id: '8', + name: 'Prof. Clark', + email: 'clark@example.com', + courses: [ + DummyCourses.courses[2], + DummyCourses.courses[7], + DummyCourses.courses[12] + ], + cabinNumber: 'C-108', + department: 'Information Technology'), + Faculty( + id: '9', + name: 'Dr. Harris', + email: 'harris@example.com', + courses: [ + DummyCourses.courses[3], + DummyCourses.courses[8], + DummyCourses.courses[13] + ], + cabinNumber: 'C-109', + department: 'Mechatronics'), Faculty( id: '10', name: 'Prof. Turner', @@ -242,12 +330,20 @@ class DummyFaculties { DummyCourses.courses[4], DummyCourses.courses[9], DummyCourses.courses[14] - ]), - Faculty(id: '11', name: 'Dr. White', email: 'white@example.com', courses: [ - DummyCourses.courses[0], - DummyCourses.courses[5], - DummyCourses.courses[10] - ]), + ], + cabinNumber: 'C-110', + department: 'Robotics Engineering'), + Faculty( + id: '11', + name: 'Dr. White', + email: 'white@example.com', + courses: [ + DummyCourses.courses[0], + DummyCourses.courses[5], + DummyCourses.courses[10] + ], + cabinNumber: 'D-101', + department: 'Industrial Engineering'), Faculty( id: '12', name: 'Prof. Allen', @@ -256,12 +352,20 @@ class DummyFaculties { DummyCourses.courses[1], DummyCourses.courses[6], DummyCourses.courses[11] - ]), - Faculty(id: '13', name: 'Dr. Young', email: 'young@example.com', courses: [ - DummyCourses.courses[2], - DummyCourses.courses[7], - DummyCourses.courses[12] - ]), + ], + cabinNumber: 'D-102', + department: 'Computer Engineering'), + Faculty( + id: '13', + name: 'Dr. Young', + email: 'young@example.com', + courses: [ + DummyCourses.courses[2], + DummyCourses.courses[7], + DummyCourses.courses[12] + ], + cabinNumber: 'D-103', + department: 'Software Engineering'), Faculty( id: '14', name: 'Prof. Walker', @@ -270,17 +374,31 @@ class DummyFaculties { DummyCourses.courses[3], DummyCourses.courses[8], DummyCourses.courses[13] - ]), - Faculty(id: '15', name: 'Dr. Lee', email: 'lee@example.com', courses: [ - DummyCourses.courses[4], - DummyCourses.courses[9], - DummyCourses.courses[14] - ]), - Faculty(id: '16', name: 'Prof. Hall', email: 'hall@example.com', courses: [ - DummyCourses.courses[0], - DummyCourses.courses[5], - DummyCourses.courses[10] - ]), + ], + cabinNumber: 'D-104', + department: 'Environmental Engineering'), + Faculty( + id: '15', + name: 'Dr. Lee', + email: 'lee@example.com', + courses: [ + DummyCourses.courses[4], + DummyCourses.courses[9], + DummyCourses.courses[14] + ], + cabinNumber: 'D-105', + department: 'Petroleum Engineering'), + Faculty( + id: '16', + name: 'Prof. Hall', + email: 'hall@example.com', + courses: [ + DummyCourses.courses[0], + DummyCourses.courses[5], + DummyCourses.courses[10] + ], + cabinNumber: 'D-106', + department: 'Nuclear Engineering'), Faculty( id: '17', name: 'Dr. Miller', @@ -289,7 +407,9 @@ class DummyFaculties { DummyCourses.courses[1], DummyCourses.courses[6], DummyCourses.courses[11] - ]), + ], + cabinNumber: 'D-107', + department: 'Biomedical Engineering'), Faculty( id: '18', name: 'Prof. Baker', @@ -298,7 +418,9 @@ class DummyFaculties { DummyCourses.courses[2], DummyCourses.courses[7], DummyCourses.courses[12] - ]), + ], + cabinNumber: 'D-108', + department: 'Chemical Engineering'), Faculty( id: '19', name: 'Dr. Turner', @@ -307,7 +429,9 @@ class DummyFaculties { DummyCourses.courses[3], DummyCourses.courses[8], DummyCourses.courses[13] - ]), + ], + cabinNumber: 'D-109', + department: 'Electronics Engineering'), Faculty( id: '20', name: 'Prof. Smith', @@ -316,7 +440,9 @@ class DummyFaculties { DummyCourses.courses[4], DummyCourses.courses[9], DummyCourses.courses[14] - ]), + ], + cabinNumber: 'D-110', + department: 'Computer Science'), ]; } diff --git a/frontend/lib/models/admin.dart b/frontend/lib/models/admin.dart index 25ce7d4..033d52e 100644 --- a/frontend/lib/models/admin.dart +++ b/frontend/lib/models/admin.dart @@ -12,7 +12,7 @@ class Admin { factory Admin.fromJson(Map json) { return Admin( id: json['_id'], - name: json['name'] ?? 'Smart Insti User', + name: json['name'] ?? 'Admin', email: json['email'], ); } diff --git a/frontend/lib/models/course.dart b/frontend/lib/models/course.dart index 168e332..28918b8 100644 --- a/frontend/lib/models/course.dart +++ b/frontend/lib/models/course.dart @@ -2,13 +2,17 @@ class Course { final String id; final String courseCode; final String courseName; + final int credits; final List branches; + final String primaryRoom; Course({ required this.id, required this.courseCode, required this.courseName, + required this.credits, required this.branches, + required this.primaryRoom, }); factory Course.fromJson(Map json) { @@ -16,8 +20,10 @@ class Course { id: json['_id'], courseCode: json['courseCode'], courseName: json['name'], + credits: json['credits'], branches: (json['branches'] as List).map((item) => item as String).toList(), + primaryRoom: json['primary_room'], ); } @@ -26,7 +32,9 @@ class Course { '_id': id, 'courseCode': courseCode, 'name': courseName, + 'credits': credits, 'branches': branches, + 'primary_room': primaryRoom, }; } } diff --git a/frontend/lib/models/faculty.dart b/frontend/lib/models/faculty.dart index 7ac985a..f2b2804 100644 --- a/frontend/lib/models/faculty.dart +++ b/frontend/lib/models/faculty.dart @@ -4,12 +4,16 @@ class Faculty { final String id; final String name; final String email; + final String cabinNumber; + final String department; final List courses; Faculty({ required this.id, required this.name, required this.email, + required this.cabinNumber, + required this.department, required this.courses, }); @@ -18,6 +22,8 @@ class Faculty { id: json['_id'], name: json['name'] ?? 'Smart Insti User', email: json['email'], + cabinNumber: json['cabin_number'], + department: json['department'], courses: (json['courses'] as List) .map((item) => Course.fromJson(item)) .toList(), @@ -29,6 +35,8 @@ class Faculty { '_id': id, 'name': name, 'email': email, + 'cabin_number': cabinNumber, + 'department': department, 'courses': courses, }; } diff --git a/frontend/lib/provider/courses_provider.dart b/frontend/lib/provider/courses_provider.dart index fad4b8a..3c81f08 100644 --- a/frontend/lib/provider/courses_provider.dart +++ b/frontend/lib/provider/courses_provider.dart @@ -15,6 +15,7 @@ class CoursesState { final List filteredCourses; final TextEditingController courseCodeController; final TextEditingController courseNameController; + final TextEditingController courseCreditController; final TextEditingController searchCourseController; final List branches; @@ -23,6 +24,7 @@ class CoursesState { required this.filteredCourses, required this.courseCodeController, required this.courseNameController, + required this.courseCreditController, required this.searchCourseController, required this.branches, }); @@ -33,6 +35,7 @@ class CoursesState { List? branches, TextEditingController? courseCodeController, TextEditingController? courseNameController, + TextEditingController? courseCreditController, TextEditingController? searchCourseController, }) { return CoursesState( @@ -40,6 +43,8 @@ class CoursesState { filteredCourses: filteredCourses ?? this.filteredCourses, courseCodeController: courseCodeController ?? this.courseCodeController, courseNameController: courseNameController ?? this.courseNameController, + courseCreditController: + courseCreditController ?? this.courseCreditController, searchCourseController: searchCourseController ?? this.searchCourseController, branches: branches ?? this.branches, @@ -56,6 +61,7 @@ class CoursesNotifier extends StateNotifier { filteredCourses: [], courseCodeController: TextEditingController(), courseNameController: TextEditingController(), + courseCreditController: TextEditingController(), searchCourseController: TextEditingController(), branches: Branches.branchList.map((branch) => branch.value!).toList(), ); @@ -65,6 +71,8 @@ class CoursesNotifier extends StateNotifier { get courseCodeController => state.courseCodeController; + get courseCreditController => state.courseCreditController; + get searchCourseController => state.searchCourseController; final Logger _logger = Logger(); @@ -114,6 +122,10 @@ class CoursesNotifier extends StateNotifier { courseCode: state.courseCodeController.text, courseName: state.courseNameController.text, branches: state.branches, + credits: state.courseCreditController.text.isEmpty + ? 0 + : int.parse(state.courseCreditController.text), + primaryRoom: '', ); state = state.copyWith( courses: [ diff --git a/frontend/lib/provider/faculty_provider.dart b/frontend/lib/provider/faculty_provider.dart index 74c1097..6043fef 100644 --- a/frontend/lib/provider/faculty_provider.dart +++ b/frontend/lib/provider/faculty_provider.dart @@ -17,6 +17,8 @@ class FacultyState { final List selectedCourses; final TextEditingController facultyNameController; final TextEditingController facultyEmailController; + final TextEditingController facultyDepartmentController; + final TextEditingController facultyCabinNumberController; final TextEditingController searchFacultyController; FacultyState({ @@ -26,6 +28,8 @@ class FacultyState { required this.facultyNameController, required this.facultyEmailController, required this.searchFacultyController, + required this.facultyDepartmentController, + required this.facultyCabinNumberController, }); FacultyState copyWith({ @@ -35,6 +39,8 @@ class FacultyState { TextEditingController? facultyNameController, TextEditingController? facultyEmailController, TextEditingController? searchFacultyController, + TextEditingController? facultyDepartmentController, + TextEditingController? facultyCabinNumberController, }) { return FacultyState( faculties: faculties ?? this.faculties, @@ -44,6 +50,10 @@ class FacultyState { facultyNameController ?? this.facultyNameController, facultyEmailController: facultyEmailController ?? this.facultyEmailController, + facultyCabinNumberController: + facultyCabinNumberController ?? this.facultyCabinNumberController, + facultyDepartmentController: + facultyDepartmentController ?? this.facultyDepartmentController, searchFacultyController: searchFacultyController ?? this.searchFacultyController, ); @@ -58,6 +68,8 @@ class FacultyStateNotifier extends StateNotifier { selectedCourses: [], facultyNameController: TextEditingController(), facultyEmailController: TextEditingController(), + facultyCabinNumberController: TextEditingController(), + facultyDepartmentController: TextEditingController(), searchFacultyController: TextEditingController(), )); @@ -69,6 +81,10 @@ class FacultyStateNotifier extends StateNotifier { get searchFacultyController => state.searchFacultyController; + get facultyCabinNumberController => state.facultyCabinNumberController; + + get facultyDepartmentController => state.facultyDepartmentController; + void pickSpreadsheet() async { FilePickerResult? result = await FilePicker.platform.pickFiles(); if (result != null) { @@ -95,12 +111,16 @@ class FacultyStateNotifier extends StateNotifier { name: state.facultyNameController.text, email: state.facultyEmailController.text, courses: state.selectedCourses, + cabinNumber: state.facultyCabinNumberController.text, + department: state.facultyDepartmentController.text, ); state = state.copyWith( faculties: [faculty, ...state.faculties], selectedCourses: [], facultyNameController: TextEditingController(), facultyEmailController: TextEditingController(), + facultyCabinNumberController: TextEditingController(), + facultyDepartmentController: TextEditingController(), ); _logger.i("Added faculty: ${faculty.name}"); } From e479f751463fa33ee565f086770b63dbb0eb983d Mon Sep 17 00:00:00 2001 From: Arin Nigam Date: Sat, 3 Feb 2024 00:32:03 +0530 Subject: [PATCH 07/12] Added dummy entries --- backend/models/faculty.js | 2 - backend/models/lost_and_found.js | 30 ++ backend/models/mess_menu.js | 24 ++ frontend/lib/constants/dummy_entries.dart | 424 +++++++++++++++++++--- frontend/lib/models/lost_and_found.dart | 39 ++ frontend/lib/models/room.dart | 18 + 6 files changed, 489 insertions(+), 48 deletions(-) create mode 100644 backend/models/lost_and_found.js create mode 100644 backend/models/mess_menu.js create mode 100644 frontend/lib/models/lost_and_found.dart diff --git a/backend/models/faculty.js b/backend/models/faculty.js index a9534e2..1f5e55e 100644 --- a/backend/models/faculty.js +++ b/backend/models/faculty.js @@ -12,11 +12,9 @@ const facultySchema = new mongoose.Schema({ }, cabin_number: { type: String, - required: true, }, department: { type: String, - required: true, }, courses: [{ type: mongoose.Schema.Types.ObjectId, diff --git a/backend/models/lost_and_found.js b/backend/models/lost_and_found.js new file mode 100644 index 0000000..2ff415d --- /dev/null +++ b/backend/models/lost_and_found.js @@ -0,0 +1,30 @@ +import mongoose from 'mongoose'; + +const lostAndFoundItemSchema = new mongoose.Schema({ + name: { + type: String, + required: true + }, + lastSeenLocation: { + type: String, + }, + imagePath: { + type: String, + }, + description: { + type: String, + required: true + }, + contactNumber: { + type: String, + required: true + }, + isLost: { + type: Boolean, + required: true + } +}); + +const LostAndFoundItem = mongoose.model('LostAndFoundItem', lostAndFoundItemSchema); + +export default LostAndFoundItem; \ No newline at end of file diff --git a/backend/models/mess_menu.js b/backend/models/mess_menu.js new file mode 100644 index 0000000..ed536e5 --- /dev/null +++ b/backend/models/mess_menu.js @@ -0,0 +1,24 @@ +const mongoose = require('mongoose'); + +const messMenuSchema = new mongoose.Schema({ + id: { + type: String, + required: true + }, + kitchenName: { + type: String, + required: true + }, + messMenu: { + type: Map, + of: { + type: Map, + of: [String] + }, + required: true + } +}); + +const MessMenu = mongoose.model('MessMenu', messMenuSchema); + +module.exports = MessMenu; diff --git a/frontend/lib/constants/dummy_entries.dart b/frontend/lib/constants/dummy_entries.dart index 5760e81..69852db 100644 --- a/frontend/lib/constants/dummy_entries.dart +++ b/frontend/lib/constants/dummy_entries.dart @@ -1,7 +1,9 @@ +import '../models/achievement.dart'; import '../models/course.dart'; import '../models/faculty.dart'; import '../models/mess_menu.dart'; import '../models/room.dart'; +import '../models/skills.dart'; import '../models/student.dart'; class DummyStudents { @@ -10,66 +12,241 @@ class DummyStudents { id: '1', name: 'John Doe', email: 'john.doe@example.com', - rollNumber: 'R001', + rollNumber: '89890', about: 'I am a computer science student.', - profilePicURI: 'https://example.com/john.jpg', + profilePicURI: '', branch: 'Computer Science', graduationYear: 2023, - skills: [], - achievements: [], - roles: ['role1', 'role2'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), ), Student( id: '2', - name: 'John Doe', - email: 'john.doe@example.com', - rollNumber: 'R001', - about: 'I am a computer science student.', - profilePicURI: 'https://example.com/john.jpg', - branch: 'Computer Science', - graduationYear: 2023, - skills: [], - achievements: [], - roles: ['role1', 'role2'], + name: 'Alice Johnson', + email: 'alice.johnson@example.com', + rollNumber: '67890', + about: 'I am a mechanical engineering student.', + profilePicURI: '', + branch: 'Mechanical Engineering', + roles: ['Student,Class Representative'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), ), Student( id: '3', - name: 'John Doe', - email: 'john.doe@example.com', - rollNumber: 'R001', - about: 'I am a computer science student.', - profilePicURI: 'https://example.com/john.jpg', - branch: 'Computer Science', - graduationYear: 2023, - skills: [], - achievements: [], - roles: ['role1', 'role2'], + name: 'Bob Williams', + email: 'bob.williams@example.com', + about: 'I am an electrical engineering student.', + profilePicURI: '', + rollNumber: '54321', + branch: 'Electrical Engineering', + roles: ['Student'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), ), Student( id: '4', - name: 'John Doe', - email: 'john.doe@example.com', - rollNumber: 'R001', - about: 'I am a computer science student.', - profilePicURI: 'https://example.com/john.jpg', - branch: 'Computer Science', - graduationYear: 2023, - skills: [], - achievements: [], - roles: ['role1', 'role2'], + name: 'Eva Davis', + email: 'eva.davis@example.com', + about: 'I am a civil engineering student.', + profilePicURI: '', + rollNumber: '98765', + branch: 'Civil Engineering', + roles: ['Student,Class Representative'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), ), Student( id: '5', - name: 'John Doe', - email: 'john.doe@example.com', - rollNumber: 'R001', + name: 'Chris Taylor', + email: 'chris.taylor@example.com', + about: 'I am a chemical engineering student.', + profilePicURI: '', + rollNumber: '13579', + branch: 'Chemical Engineering', + roles: ['Student'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '6', + name: 'Grace Miller', + email: 'grace.miller@example.com', + about: 'I am a biotechnology student.', + profilePicURI: '', + rollNumber: '24680', + branch: 'Biotechnology', + roles: ['Student,Class Representative'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '7', + name: 'Daniel Brown', + email: 'daniel.brown@example.com', + about: 'I am an aerospace engineering student.', + profilePicURI: '', + rollNumber: '97531', + branch: 'Aerospace Engineering', + roles: ['Student,Teaching Assistant'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '8', + name: 'Sophia Wilson', + email: 'sophia.wilson@example.com', + about: 'I am an information technology student.', + profilePicURI: '', + rollNumber: '86420', + branch: 'Information Technology', + roles: ['Student,Teaching Assistant'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '9', + name: 'Matthew White', + email: 'matthew.white@example.com', + about: 'I am a mechatronics student.', + profilePicURI: '', + rollNumber: '12340', + branch: 'Mechatronics', + roles: ['Student'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '10', + name: 'Olivia Harris', + email: 'olivia.harris@example.com', + about: 'I am a robotics engineering student.', + profilePicURI: '', + rollNumber: '56789', + branch: 'Robotics Engineering', + roles: ['Student'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '11', + name: 'William Turner', + email: 'william.turner@example.com', + about: 'I am an industrial engineering student.', + profilePicURI: '', + rollNumber: '34567', + branch: 'Industrial Engineering', + roles: ['Student,Teaching Assistant'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '12', + name: 'Emma Clark', + email: 'emma.clark@example.com', + about: 'I am a computer engineering student.', + profilePicURI: '', + rollNumber: '89012', + branch: 'Computer Engineering', + roles: ['Student'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '13', + name: 'Ryan Allen', + email: 'ryan.allen@example.com', + about: 'I am a software engineering student.', + profilePicURI: '', + rollNumber: '67890', + branch: 'Software Engineering', + roles: ['Student'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '14', + name: 'Ava Young', + email: 'ava.young@example.com', + about: 'I am an environmental engineering student.', + profilePicURI: '', + rollNumber: '23456', + branch: 'Environmental Engineering', + roles: ['Student'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '15', + name: 'Jackson Walker', + email: 'jackson.walker@example.com', + about: 'I am a petrolesum[ engineer]ing student.', + profilePicURI: '', + rollNumber: '87654', + branch: 'Petrolesum Engineer]ing', + roles: ['Student,Class Representative'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '16', + name: 'Sophie Lee', + email: 'sophie.lee@example.com', + about: 'I am a nuclear engineering student.', + profilePicURI: '', + rollNumber: '54321', + branch: 'Nuclear Engineering', + roles: ['Student,Cultural Secretary'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '17', + name: 'David Hall', + email: 'david.hall@example.com', + about: 'I am a biomedical engineering student.', + profilePicURI: '', + rollNumber: '10987', + branch: 'Biomedical Engineering', + roles: ['Student,Class Representative'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '18', + name: 'Isabella Miller', + email: 'isabella.miller@example.com', + about: 'I am a chemical engineering student.', + profilePicURI: '', + rollNumber: '87654', + branch: 'Chemical Engineering', + roles: ['Student'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '19', + name: 'Mason Baker', + email: 'mason.baker@example.com', + about: 'I am an electronics engineering student.', + profilePicURI: '', + rollNumber: '54321', + branch: 'Electronics Engineering', + roles: ['Student,Class Representative'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), + ), + Student( + id: '20', + name: 'Ella Turner', + email: 'ella.turner@example.com', about: 'I am a computer science student.', - profilePicURI: 'https://example.com/john.jpg', + profilePicURI: '', + rollNumber: '98765', branch: 'Computer Science', - graduationYear: 2023, - skills: [], - achievements: [], - roles: ['role1', 'role2'], + roles: ['Student,Teaching Assistant'], + skills: DummySkills.skills.sublist(0, 5), + achievements: DummyAchievements.achievements.sublist(0, 5), ), ]; } @@ -177,8 +354,8 @@ class DummyCourses { Course( id: '15', courseCode: 'PE115', - courseName: 'Petroleum Engineering Introduction', - branches: ['Petroleum Engineering'], + courseName: 'Petrolesum[ Engineer]ing Introduction', + branches: ['Petrolesum[ Engineer]ing'], credits: 3, primaryRoom: 'ROOM-103'), Course( @@ -387,7 +564,7 @@ class DummyFaculties { DummyCourses.courses[14] ], cabinNumber: 'D-105', - department: 'Petroleum Engineering'), + department: 'Petrolesum[ Engineer]ing'), Faculty( id: '16', name: 'Prof. Hall', @@ -719,3 +896,158 @@ class DummyRooms { Room(id: '20', name: 'Virtual Reality Lab', vacant: true), ]; } + +class DummySkills { + static List skills = [ + Skill(id: '1', name: 'Programming', level: 5), + Skill(id: '2', name: 'Web Development', level: 3), + Skill(id: '3', name: 'Data Analysis', level: 2), + Skill(id: '4', name: 'Graphic Design', level: 4), + Skill(id: '5', name: 'Project Management', level: 3), + Skill(id: '6', name: 'Mobile App Development', level: 2), + Skill(id: '7', name: 'UI/UX Design', level: 4), + Skill(id: '8', name: 'Machine Learning', level: 1), + Skill(id: '9', name: 'Database Management', level: 3), + Skill(id: '10', name: 'Networking', level: 2), + Skill(id: '11', name: 'Cybersecurity', level: 1), + Skill(id: '12', name: 'System Administration', level: 4), + Skill(id: '13', name: 'Cloud Computing', level: 2), + Skill(id: '14', name: 'Testing/QA', level: 3), + Skill(id: '15', name: 'Agile Methodology', level: 4), + Skill(id: '16', name: 'Technical Writing', level: 3), + Skill(id: '17', name: 'Problem Solving', level: 5), + Skill(id: '18', name: 'Communication Skills', level: 4), + Skill(id: '19', name: 'Time Management', level: 3), + Skill(id: '20', name: 'Leadership', level: 4), + ]; +} + +class DummyAchievements { + static List achievements = [ + Achievement( + id: '1', + name: 'Employee of the Month', + date: DateTime(2022, 5, 15), + description: 'Recognized for outstanding performance and dedication.', + ), + Achievement( + id: '2', + name: 'Project Completion', + date: DateTime(2022, 8, 20), + description: 'Successfully led a team to complete a critical project.', + ), + Achievement( + id: '3', + name: 'Certification Achievement', + date: DateTime(2022, 3, 10), + description: 'Obtained a certification in a relevant field of expertise.', + ), + Achievement( + id: '4', + name: 'Innovation Award', + date: DateTime(2023, 1, 5), + description: 'Recognized for introducing innovative solutions.', + ), + Achievement( + id: '5', + name: 'Customer Appreciation', + date: DateTime(2023, 7, 12), + description: 'Received positive feedback and appreciation from a client.', + ), + Achievement( + id: '6', + name: 'Leadership Excellence', + date: DateTime(2023, 11, 30), + description: 'Acknowledged for exemplary leadership skills.', + ), + Achievement( + id: '7', + name: 'Community Service Award', + date: DateTime(2022, 6, 8), + description: 'Recognized for contributions to community service.', + ), + Achievement( + id: '8', + name: 'Sales Achievement', + date: DateTime(2022, 9, 25), + description: 'Achieved significant sales targets and milestones.', + ), + Achievement( + id: '9', + name: 'Team Collaboration Award', + date: DateTime(2023, 4, 18), + description: 'Commended for fostering effective team collaboration.', + ), + Achievement( + id: '10', + name: 'Publication Recognition', + date: DateTime(2022, 12, 7), + description: 'Published work recognized for its impact in the industry.', + ), + Achievement( + id: '11', + name: 'Safety Excellence Award', + date: DateTime(2023, 8, 2), + description: 'Maintained a safe working environment with zero incidents.', + ), + Achievement( + id: '12', + name: 'Training and Development', + date: DateTime(2022, 4, 22), + description: + 'Contributed significantly to employee training and development.', + ), + Achievement( + id: '13', + name: 'Quality Assurance Recognition', + date: DateTime(2023, 2, 14), + description: + 'Acknowledged for ensuring high-quality standards in projects.', + ), + Achievement( + id: '14', + name: 'Inclusive Workplace Award', + date: DateTime(2022, 10, 9), + description: 'Promoted inclusivity and diversity in the workplace.', + ), + Achievement( + id: '15', + name: 'Milestone Anniversary', + date: DateTime(2023, 6, 5), + description: 'Celebrating a significant milestone with the organization.', + ), + Achievement( + id: '16', + name: 'International Recognition', + date: DateTime(2022, 11, 19), + description: 'Recognized internationally for contributions to the field.', + ), + Achievement( + id: '17', + name: 'Environmental Sustainability Award', + date: DateTime(2023, 3, 28), + description: 'Contributed to environmentally sustainable practices.', + ), + Achievement( + id: '18', + name: 'Customer Service Excellence', + date: DateTime(2022, 7, 1), + description: 'Provided outstanding customer service and satisfaction.', + ), + Achievement( + id: '19', + name: 'Health and Wellness Initiative', + date: DateTime(2023, 9, 10), + description: + 'Led initiatives to promote health and wellness in the workplace.', + ), + Achievement( + id: '20', + name: 'Public Speaking Achievement', + date: DateTime(2022, 1, 30), + description: + 'Received acclaim for public speaking skills at a conference.', + ), + ]; + // You can use the dummyEntries list as needed in your application +} diff --git a/frontend/lib/models/lost_and_found.dart b/frontend/lib/models/lost_and_found.dart new file mode 100644 index 0000000..d7058b1 --- /dev/null +++ b/frontend/lib/models/lost_and_found.dart @@ -0,0 +1,39 @@ +class LostAndFoundItem { + String name; + String lastSeenLocation; + String imagePath; + String description; + String contactNumber; + bool isLost; + + LostAndFoundItem({ + required this.name, + required this.lastSeenLocation, + required this.imagePath, + required this.description, + required this.contactNumber, + required this.isLost, + }); + + factory LostAndFoundItem.fromJson(Map json) { + return LostAndFoundItem( + name: json['name'], + lastSeenLocation: json['lastSeenLocation'], + imagePath: json['imagePath'], + description: json['description'], + contactNumber: json['contactNumber'], + isLost: json['isLost'], + ); + } + + Map toJson() { + return { + 'name': name, + 'lastSeenLocation': lastSeenLocation, + 'imagePath': imagePath, + 'description': description, + 'contactNumber': contactNumber, + 'isLost': isLost, + }; + } +} diff --git a/frontend/lib/models/room.dart b/frontend/lib/models/room.dart index 1f714bb..105ee48 100644 --- a/frontend/lib/models/room.dart +++ b/frontend/lib/models/room.dart @@ -5,4 +5,22 @@ class Room { final String name; final bool? vacant; final String? occupantId; + + factory Room.fromJson(Map json) { + return Room( + id: json['id'], + name: json['name'], + vacant: json['vacant'], + occupantId: json['occupantId'], + ); + } + + Map toJson() { + return { + 'id': id, + 'name': name, + 'vacant': vacant, + 'occupantId': occupantId, + }; + } } From d28aeb8bd0e258a37efb6a4648bc3bea0cd1d642 Mon Sep 17 00:00:00 2001 From: Arin Nigam Date: Sat, 3 Feb 2024 00:52:47 +0530 Subject: [PATCH 08/12] added professor_id --- backend/models/course.js | 6 ++- frontend/lib/constants/dummy_entries.dart | 60 +++++++++++++++-------- frontend/lib/models/course.dart | 4 ++ 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/backend/models/course.js b/backend/models/course.js index f82143b..2093559 100644 --- a/backend/models/course.js +++ b/backend/models/course.js @@ -12,12 +12,16 @@ const courseSchema = new mongoose.Schema({ }, primary_room: { type: String, - required: true, }, credits: { type: Number, required: true, }, + professor_id: { + type: mongoose.Schema.Types.ObjectId, + ref: 'Faculty', + required: true, + }, branches: [{ type: String, required: true diff --git a/frontend/lib/constants/dummy_entries.dart b/frontend/lib/constants/dummy_entries.dart index 69852db..6fa8c12 100644 --- a/frontend/lib/constants/dummy_entries.dart +++ b/frontend/lib/constants/dummy_entries.dart @@ -259,140 +259,160 @@ class DummyCourses { courseName: 'Introduction to Computer Science', branches: ['Computer Science'], credits: 3, - primaryRoom: 'LT-1'), + primaryRoom: 'LT-1', + professor_id: DummyFaculties.faculties[0].id), Course( id: '2', courseCode: 'ME102', courseName: 'Mechanical Engineering Basics', branches: ['Mechanical Engineering'], credits: 3, - primaryRoom: 'LT-2'), + primaryRoom: 'LT-2', + professor_id: DummyFaculties.faculties[1].id), Course( id: '3', courseCode: 'EE103', courseName: 'Electrical Engineering Fundamentals', branches: ['Electrical Engineering'], credits: 3, - primaryRoom: 'LT-3'), + primaryRoom: 'LT-3', + professor_id: DummyFaculties.faculties[2].id), Course( id: '4', courseCode: 'EE104', courseName: 'Civil Engineering Principles', branches: ['Civil Engineering'], credits: 3, - primaryRoom: 'LT-4'), + primaryRoom: 'LT-4', + professor_id: DummyFaculties.faculties[3].id), Course( id: '5', courseCode: 'CHE105', courseName: 'Chemical Engineering Basics', branches: ['Chemical Engineering'], credits: 3, - primaryRoom: 'LH-1'), + primaryRoom: 'LH-1', + professor_id: DummyFaculties.faculties[4].id), Course( id: '6', courseCode: 'BT106', courseName: 'Biotechnology Fundamentals', branches: ['Biotechnology'], credits: 3, - primaryRoom: 'LH-2'), + primaryRoom: 'LH-2', + professor_id: DummyFaculties.faculties[5].id), Course( id: '7', courseCode: 'AE107', courseName: 'Aerospace Engineering Introduction', branches: ['Aerospace Engineering'], credits: 3, - primaryRoom: 'LH-3'), + primaryRoom: 'LH-3', + professor_id: DummyFaculties.faculties[6].id), Course( id: '8', courseCode: 'IT108', courseName: 'Information Technology Essentials', branches: ['Information Technology'], credits: 3, - primaryRoom: 'LH-4'), + primaryRoom: 'LH-4', + professor_id: DummyFaculties.faculties[7].id), Course( id: '9', courseCode: 'MT109', courseName: 'Mechatronics Basics', branches: ['Mechatronics'], credits: 3, - primaryRoom: 'LH-5'), + primaryRoom: 'LH-5', + professor_id: DummyFaculties.faculties[8].id), Course( id: '10', courseCode: 'RE110', courseName: 'Robotics Engineering Fundamentals', branches: ['Robotics Engineering'], credits: 3, - primaryRoom: 'LH-6'), + primaryRoom: 'LH-6', + professor_id: DummyFaculties.faculties[9].id), Course( id: '11', courseCode: 'IE111', courseName: 'Industrial Engineering Principles', branches: ['Industrial Engineering'], credits: 3, - primaryRoom: 'LH-7'), + primaryRoom: 'LH-7', + professor_id: DummyFaculties.faculties[10].id), Course( id: '12', courseCode: 'CE112', courseName: 'Computer Engineering Basics', branches: ['Computer Engineering'], credits: 3, - primaryRoom: 'LH-8'), + primaryRoom: 'LH-8', + professor_id: DummyFaculties.faculties[11].id), Course( id: '13', courseCode: 'SE113', courseName: 'Software Engineering Fundamentals', branches: ['Software Engineering'], credits: 3, - primaryRoom: 'ROOM-101'), + primaryRoom: 'ROOM-101', + professor_id: DummyFaculties.faculties[12].id), Course( id: '14', courseCode: 'EN114', courseName: 'Environmental Engineering Basics', branches: ['Environmental Engineering'], credits: 3, - primaryRoom: 'ROOM-102'), + primaryRoom: 'ROOM-102', + professor_id: DummyFaculties.faculties[13].id), Course( id: '15', courseCode: 'PE115', courseName: 'Petrolesum[ Engineer]ing Introduction', branches: ['Petrolesum[ Engineer]ing'], credits: 3, - primaryRoom: 'ROOM-103'), + primaryRoom: 'ROOM-103', + professor_id: DummyFaculties.faculties[14].id), Course( id: '16', courseCode: 'NE116', courseName: 'Nuclear Engineering Basics', branches: ['Nuclear Engineering'], credits: 3, - primaryRoom: 'ROOM-104'), + primaryRoom: 'ROOM-104', + professor_id: DummyFaculties.faculties[15].id), Course( id: '17', courseCode: 'BE117', courseName: 'Biomedical Engineering Fundamentals', branches: ['Biomedical Engineering'], credits: 3, - primaryRoom: 'ROOM-201'), + primaryRoom: 'ROOM-201', + professor_id: DummyFaculties.faculties[16].id), Course( id: '18', courseCode: 'CE118', courseName: 'Chemical Engineering Principles', branches: ['Chemical Engineering'], credits: 3, - primaryRoom: 'ROOM-202'), + primaryRoom: 'ROOM-202', + professor_id: DummyFaculties.faculties[17].id), Course( id: '19', courseCode: 'EE119', courseName: 'Electronics Engineering Basics', branches: ['Electronics Engineering'], credits: 3, - primaryRoom: 'ROOM-203'), + primaryRoom: 'ROOM-203', + professor_id: DummyFaculties.faculties[18].id), Course( id: '20', courseCode: 'CS120', courseName: 'Advanced Computer Science Topics', branches: ['Computer Science'], credits: 3, - primaryRoom: 'ROOM-204'), + primaryRoom: 'ROOM-204', + professor_id: DummyFaculties.faculties[19].id), ]; } diff --git a/frontend/lib/models/course.dart b/frontend/lib/models/course.dart index 28918b8..d3e8e1e 100644 --- a/frontend/lib/models/course.dart +++ b/frontend/lib/models/course.dart @@ -5,6 +5,7 @@ class Course { final int credits; final List branches; final String primaryRoom; + final String professor_id; Course({ required this.id, @@ -13,6 +14,7 @@ class Course { required this.credits, required this.branches, required this.primaryRoom, + required this.professor_id, }); factory Course.fromJson(Map json) { @@ -24,6 +26,7 @@ class Course { branches: (json['branches'] as List).map((item) => item as String).toList(), primaryRoom: json['primary_room'], + professor_id: json['professor_id'], ); } @@ -35,6 +38,7 @@ class Course { 'credits': credits, 'branches': branches, 'primary_room': primaryRoom, + 'professor_id': professor_id, }; } } From 89e91fad64c89ba7619200d022fb65a632096c10 Mon Sep 17 00:00:00 2001 From: Arin Nigam Date: Sat, 3 Feb 2024 23:32:29 +0530 Subject: [PATCH 09/12] fixed naming convention --- backend/models/course.js | 4 +-- backend/models/faculty.js | 2 +- frontend/lib/constants/dummy_entries.dart | 40 ++++++++++----------- frontend/lib/models/course.dart | 12 +++---- frontend/lib/models/faculty.dart | 4 +-- frontend/lib/models/lost_and_found.dart | 4 +++ frontend/lib/provider/courses_provider.dart | 1 + 7 files changed, 36 insertions(+), 31 deletions(-) diff --git a/backend/models/course.js b/backend/models/course.js index 2093559..d29d67f 100644 --- a/backend/models/course.js +++ b/backend/models/course.js @@ -10,14 +10,14 @@ const courseSchema = new mongoose.Schema({ required: true, unique: true }, - primary_room: { + primaryRoom: { type: String, }, credits: { type: Number, required: true, }, - professor_id: { + professorId: { type: mongoose.Schema.Types.ObjectId, ref: 'Faculty', required: true, diff --git a/backend/models/faculty.js b/backend/models/faculty.js index 1f5e55e..c61c912 100644 --- a/backend/models/faculty.js +++ b/backend/models/faculty.js @@ -10,7 +10,7 @@ const facultySchema = new mongoose.Schema({ required: true, unique: true }, - cabin_number: { + cabinNumber: { type: String, }, department: { diff --git a/frontend/lib/constants/dummy_entries.dart b/frontend/lib/constants/dummy_entries.dart index 6fa8c12..32f06d8 100644 --- a/frontend/lib/constants/dummy_entries.dart +++ b/frontend/lib/constants/dummy_entries.dart @@ -260,7 +260,7 @@ class DummyCourses { branches: ['Computer Science'], credits: 3, primaryRoom: 'LT-1', - professor_id: DummyFaculties.faculties[0].id), + professorId: DummyFaculties.faculties[0].id), Course( id: '2', courseCode: 'ME102', @@ -268,7 +268,7 @@ class DummyCourses { branches: ['Mechanical Engineering'], credits: 3, primaryRoom: 'LT-2', - professor_id: DummyFaculties.faculties[1].id), + professorId: DummyFaculties.faculties[1].id), Course( id: '3', courseCode: 'EE103', @@ -276,7 +276,7 @@ class DummyCourses { branches: ['Electrical Engineering'], credits: 3, primaryRoom: 'LT-3', - professor_id: DummyFaculties.faculties[2].id), + professorId: DummyFaculties.faculties[2].id), Course( id: '4', courseCode: 'EE104', @@ -284,7 +284,7 @@ class DummyCourses { branches: ['Civil Engineering'], credits: 3, primaryRoom: 'LT-4', - professor_id: DummyFaculties.faculties[3].id), + professorId: DummyFaculties.faculties[3].id), Course( id: '5', courseCode: 'CHE105', @@ -292,7 +292,7 @@ class DummyCourses { branches: ['Chemical Engineering'], credits: 3, primaryRoom: 'LH-1', - professor_id: DummyFaculties.faculties[4].id), + professorId: DummyFaculties.faculties[4].id), Course( id: '6', courseCode: 'BT106', @@ -300,7 +300,7 @@ class DummyCourses { branches: ['Biotechnology'], credits: 3, primaryRoom: 'LH-2', - professor_id: DummyFaculties.faculties[5].id), + professorId: DummyFaculties.faculties[5].id), Course( id: '7', courseCode: 'AE107', @@ -308,7 +308,7 @@ class DummyCourses { branches: ['Aerospace Engineering'], credits: 3, primaryRoom: 'LH-3', - professor_id: DummyFaculties.faculties[6].id), + professorId: DummyFaculties.faculties[6].id), Course( id: '8', courseCode: 'IT108', @@ -316,7 +316,7 @@ class DummyCourses { branches: ['Information Technology'], credits: 3, primaryRoom: 'LH-4', - professor_id: DummyFaculties.faculties[7].id), + professorId: DummyFaculties.faculties[7].id), Course( id: '9', courseCode: 'MT109', @@ -324,7 +324,7 @@ class DummyCourses { branches: ['Mechatronics'], credits: 3, primaryRoom: 'LH-5', - professor_id: DummyFaculties.faculties[8].id), + professorId: DummyFaculties.faculties[8].id), Course( id: '10', courseCode: 'RE110', @@ -332,7 +332,7 @@ class DummyCourses { branches: ['Robotics Engineering'], credits: 3, primaryRoom: 'LH-6', - professor_id: DummyFaculties.faculties[9].id), + professorId: DummyFaculties.faculties[9].id), Course( id: '11', courseCode: 'IE111', @@ -340,7 +340,7 @@ class DummyCourses { branches: ['Industrial Engineering'], credits: 3, primaryRoom: 'LH-7', - professor_id: DummyFaculties.faculties[10].id), + professorId: DummyFaculties.faculties[10].id), Course( id: '12', courseCode: 'CE112', @@ -348,7 +348,7 @@ class DummyCourses { branches: ['Computer Engineering'], credits: 3, primaryRoom: 'LH-8', - professor_id: DummyFaculties.faculties[11].id), + professorId: DummyFaculties.faculties[11].id), Course( id: '13', courseCode: 'SE113', @@ -356,7 +356,7 @@ class DummyCourses { branches: ['Software Engineering'], credits: 3, primaryRoom: 'ROOM-101', - professor_id: DummyFaculties.faculties[12].id), + professorId: DummyFaculties.faculties[12].id), Course( id: '14', courseCode: 'EN114', @@ -364,7 +364,7 @@ class DummyCourses { branches: ['Environmental Engineering'], credits: 3, primaryRoom: 'ROOM-102', - professor_id: DummyFaculties.faculties[13].id), + professorId: DummyFaculties.faculties[13].id), Course( id: '15', courseCode: 'PE115', @@ -372,7 +372,7 @@ class DummyCourses { branches: ['Petrolesum[ Engineer]ing'], credits: 3, primaryRoom: 'ROOM-103', - professor_id: DummyFaculties.faculties[14].id), + professorId: DummyFaculties.faculties[14].id), Course( id: '16', courseCode: 'NE116', @@ -380,7 +380,7 @@ class DummyCourses { branches: ['Nuclear Engineering'], credits: 3, primaryRoom: 'ROOM-104', - professor_id: DummyFaculties.faculties[15].id), + professorId: DummyFaculties.faculties[15].id), Course( id: '17', courseCode: 'BE117', @@ -388,7 +388,7 @@ class DummyCourses { branches: ['Biomedical Engineering'], credits: 3, primaryRoom: 'ROOM-201', - professor_id: DummyFaculties.faculties[16].id), + professorId: DummyFaculties.faculties[16].id), Course( id: '18', courseCode: 'CE118', @@ -396,7 +396,7 @@ class DummyCourses { branches: ['Chemical Engineering'], credits: 3, primaryRoom: 'ROOM-202', - professor_id: DummyFaculties.faculties[17].id), + professorId: DummyFaculties.faculties[17].id), Course( id: '19', courseCode: 'EE119', @@ -404,7 +404,7 @@ class DummyCourses { branches: ['Electronics Engineering'], credits: 3, primaryRoom: 'ROOM-203', - professor_id: DummyFaculties.faculties[18].id), + professorId: DummyFaculties.faculties[18].id), Course( id: '20', courseCode: 'CS120', @@ -412,7 +412,7 @@ class DummyCourses { branches: ['Computer Science'], credits: 3, primaryRoom: 'ROOM-204', - professor_id: DummyFaculties.faculties[19].id), + professorId: DummyFaculties.faculties[19].id), ]; } diff --git a/frontend/lib/models/course.dart b/frontend/lib/models/course.dart index d3e8e1e..bb393b6 100644 --- a/frontend/lib/models/course.dart +++ b/frontend/lib/models/course.dart @@ -5,7 +5,7 @@ class Course { final int credits; final List branches; final String primaryRoom; - final String professor_id; + final String professorId; Course({ required this.id, @@ -14,7 +14,7 @@ class Course { required this.credits, required this.branches, required this.primaryRoom, - required this.professor_id, + required this.professorId, }); factory Course.fromJson(Map json) { @@ -25,8 +25,8 @@ class Course { credits: json['credits'], branches: (json['branches'] as List).map((item) => item as String).toList(), - primaryRoom: json['primary_room'], - professor_id: json['professor_id'], + primaryRoom: json['primaryRoom'], + professorId: json['professorId'], ); } @@ -37,8 +37,8 @@ class Course { 'name': courseName, 'credits': credits, 'branches': branches, - 'primary_room': primaryRoom, - 'professor_id': professor_id, + 'primaryRoom': primaryRoom, + 'professorId': professorId, }; } } diff --git a/frontend/lib/models/faculty.dart b/frontend/lib/models/faculty.dart index f2b2804..4acb376 100644 --- a/frontend/lib/models/faculty.dart +++ b/frontend/lib/models/faculty.dart @@ -22,7 +22,7 @@ class Faculty { id: json['_id'], name: json['name'] ?? 'Smart Insti User', email: json['email'], - cabinNumber: json['cabin_number'], + cabinNumber: json['cabinNumber'], department: json['department'], courses: (json['courses'] as List) .map((item) => Course.fromJson(item)) @@ -35,7 +35,7 @@ class Faculty { '_id': id, 'name': name, 'email': email, - 'cabin_number': cabinNumber, + 'cabinNumber': cabinNumber, 'department': department, 'courses': courses, }; diff --git a/frontend/lib/models/lost_and_found.dart b/frontend/lib/models/lost_and_found.dart index d7058b1..64a01ad 100644 --- a/frontend/lib/models/lost_and_found.dart +++ b/frontend/lib/models/lost_and_found.dart @@ -1,4 +1,5 @@ class LostAndFoundItem { + String userId; String name; String lastSeenLocation; String imagePath; @@ -7,6 +8,7 @@ class LostAndFoundItem { bool isLost; LostAndFoundItem({ + required this.userId, required this.name, required this.lastSeenLocation, required this.imagePath, @@ -17,6 +19,7 @@ class LostAndFoundItem { factory LostAndFoundItem.fromJson(Map json) { return LostAndFoundItem( + userId: json['user_id'], name: json['name'], lastSeenLocation: json['lastSeenLocation'], imagePath: json['imagePath'], @@ -28,6 +31,7 @@ class LostAndFoundItem { Map toJson() { return { + 'user_id': userId, 'name': name, 'lastSeenLocation': lastSeenLocation, 'imagePath': imagePath, diff --git a/frontend/lib/provider/courses_provider.dart b/frontend/lib/provider/courses_provider.dart index 3c81f08..737026c 100644 --- a/frontend/lib/provider/courses_provider.dart +++ b/frontend/lib/provider/courses_provider.dart @@ -126,6 +126,7 @@ class CoursesNotifier extends StateNotifier { ? 0 : int.parse(state.courseCreditController.text), primaryRoom: '', + professorId: '', ); state = state.copyWith( courses: [ From 8afc9cc79a4b759babad17fd3ce1f5626854e6c9 Mon Sep 17 00:00:00 2001 From: Arin Nigam Date: Sat, 3 Feb 2024 23:34:28 +0530 Subject: [PATCH 10/12] fixed naming convention --- backend/models/course.js | 4 +-- backend/models/faculty.js | 2 +- backend/models/lost_and_found.js | 4 +++ frontend/lib/constants/dummy_entries.dart | 40 ++++++++++----------- frontend/lib/models/course.dart | 12 +++---- frontend/lib/models/faculty.dart | 4 +-- frontend/lib/models/lost_and_found.dart | 4 --- frontend/lib/provider/courses_provider.dart | 1 - 8 files changed, 35 insertions(+), 36 deletions(-) diff --git a/backend/models/course.js b/backend/models/course.js index d29d67f..2093559 100644 --- a/backend/models/course.js +++ b/backend/models/course.js @@ -10,14 +10,14 @@ const courseSchema = new mongoose.Schema({ required: true, unique: true }, - primaryRoom: { + primary_room: { type: String, }, credits: { type: Number, required: true, }, - professorId: { + professor_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Faculty', required: true, diff --git a/backend/models/faculty.js b/backend/models/faculty.js index c61c912..1f5e55e 100644 --- a/backend/models/faculty.js +++ b/backend/models/faculty.js @@ -10,7 +10,7 @@ const facultySchema = new mongoose.Schema({ required: true, unique: true }, - cabinNumber: { + cabin_number: { type: String, }, department: { diff --git a/backend/models/lost_and_found.js b/backend/models/lost_and_found.js index 2ff415d..6d9c29d 100644 --- a/backend/models/lost_and_found.js +++ b/backend/models/lost_and_found.js @@ -1,6 +1,10 @@ import mongoose from 'mongoose'; const lostAndFoundItemSchema = new mongoose.Schema({ + userId: { + type: String, + required: true + }, name: { type: String, required: true diff --git a/frontend/lib/constants/dummy_entries.dart b/frontend/lib/constants/dummy_entries.dart index 32f06d8..6fa8c12 100644 --- a/frontend/lib/constants/dummy_entries.dart +++ b/frontend/lib/constants/dummy_entries.dart @@ -260,7 +260,7 @@ class DummyCourses { branches: ['Computer Science'], credits: 3, primaryRoom: 'LT-1', - professorId: DummyFaculties.faculties[0].id), + professor_id: DummyFaculties.faculties[0].id), Course( id: '2', courseCode: 'ME102', @@ -268,7 +268,7 @@ class DummyCourses { branches: ['Mechanical Engineering'], credits: 3, primaryRoom: 'LT-2', - professorId: DummyFaculties.faculties[1].id), + professor_id: DummyFaculties.faculties[1].id), Course( id: '3', courseCode: 'EE103', @@ -276,7 +276,7 @@ class DummyCourses { branches: ['Electrical Engineering'], credits: 3, primaryRoom: 'LT-3', - professorId: DummyFaculties.faculties[2].id), + professor_id: DummyFaculties.faculties[2].id), Course( id: '4', courseCode: 'EE104', @@ -284,7 +284,7 @@ class DummyCourses { branches: ['Civil Engineering'], credits: 3, primaryRoom: 'LT-4', - professorId: DummyFaculties.faculties[3].id), + professor_id: DummyFaculties.faculties[3].id), Course( id: '5', courseCode: 'CHE105', @@ -292,7 +292,7 @@ class DummyCourses { branches: ['Chemical Engineering'], credits: 3, primaryRoom: 'LH-1', - professorId: DummyFaculties.faculties[4].id), + professor_id: DummyFaculties.faculties[4].id), Course( id: '6', courseCode: 'BT106', @@ -300,7 +300,7 @@ class DummyCourses { branches: ['Biotechnology'], credits: 3, primaryRoom: 'LH-2', - professorId: DummyFaculties.faculties[5].id), + professor_id: DummyFaculties.faculties[5].id), Course( id: '7', courseCode: 'AE107', @@ -308,7 +308,7 @@ class DummyCourses { branches: ['Aerospace Engineering'], credits: 3, primaryRoom: 'LH-3', - professorId: DummyFaculties.faculties[6].id), + professor_id: DummyFaculties.faculties[6].id), Course( id: '8', courseCode: 'IT108', @@ -316,7 +316,7 @@ class DummyCourses { branches: ['Information Technology'], credits: 3, primaryRoom: 'LH-4', - professorId: DummyFaculties.faculties[7].id), + professor_id: DummyFaculties.faculties[7].id), Course( id: '9', courseCode: 'MT109', @@ -324,7 +324,7 @@ class DummyCourses { branches: ['Mechatronics'], credits: 3, primaryRoom: 'LH-5', - professorId: DummyFaculties.faculties[8].id), + professor_id: DummyFaculties.faculties[8].id), Course( id: '10', courseCode: 'RE110', @@ -332,7 +332,7 @@ class DummyCourses { branches: ['Robotics Engineering'], credits: 3, primaryRoom: 'LH-6', - professorId: DummyFaculties.faculties[9].id), + professor_id: DummyFaculties.faculties[9].id), Course( id: '11', courseCode: 'IE111', @@ -340,7 +340,7 @@ class DummyCourses { branches: ['Industrial Engineering'], credits: 3, primaryRoom: 'LH-7', - professorId: DummyFaculties.faculties[10].id), + professor_id: DummyFaculties.faculties[10].id), Course( id: '12', courseCode: 'CE112', @@ -348,7 +348,7 @@ class DummyCourses { branches: ['Computer Engineering'], credits: 3, primaryRoom: 'LH-8', - professorId: DummyFaculties.faculties[11].id), + professor_id: DummyFaculties.faculties[11].id), Course( id: '13', courseCode: 'SE113', @@ -356,7 +356,7 @@ class DummyCourses { branches: ['Software Engineering'], credits: 3, primaryRoom: 'ROOM-101', - professorId: DummyFaculties.faculties[12].id), + professor_id: DummyFaculties.faculties[12].id), Course( id: '14', courseCode: 'EN114', @@ -364,7 +364,7 @@ class DummyCourses { branches: ['Environmental Engineering'], credits: 3, primaryRoom: 'ROOM-102', - professorId: DummyFaculties.faculties[13].id), + professor_id: DummyFaculties.faculties[13].id), Course( id: '15', courseCode: 'PE115', @@ -372,7 +372,7 @@ class DummyCourses { branches: ['Petrolesum[ Engineer]ing'], credits: 3, primaryRoom: 'ROOM-103', - professorId: DummyFaculties.faculties[14].id), + professor_id: DummyFaculties.faculties[14].id), Course( id: '16', courseCode: 'NE116', @@ -380,7 +380,7 @@ class DummyCourses { branches: ['Nuclear Engineering'], credits: 3, primaryRoom: 'ROOM-104', - professorId: DummyFaculties.faculties[15].id), + professor_id: DummyFaculties.faculties[15].id), Course( id: '17', courseCode: 'BE117', @@ -388,7 +388,7 @@ class DummyCourses { branches: ['Biomedical Engineering'], credits: 3, primaryRoom: 'ROOM-201', - professorId: DummyFaculties.faculties[16].id), + professor_id: DummyFaculties.faculties[16].id), Course( id: '18', courseCode: 'CE118', @@ -396,7 +396,7 @@ class DummyCourses { branches: ['Chemical Engineering'], credits: 3, primaryRoom: 'ROOM-202', - professorId: DummyFaculties.faculties[17].id), + professor_id: DummyFaculties.faculties[17].id), Course( id: '19', courseCode: 'EE119', @@ -404,7 +404,7 @@ class DummyCourses { branches: ['Electronics Engineering'], credits: 3, primaryRoom: 'ROOM-203', - professorId: DummyFaculties.faculties[18].id), + professor_id: DummyFaculties.faculties[18].id), Course( id: '20', courseCode: 'CS120', @@ -412,7 +412,7 @@ class DummyCourses { branches: ['Computer Science'], credits: 3, primaryRoom: 'ROOM-204', - professorId: DummyFaculties.faculties[19].id), + professor_id: DummyFaculties.faculties[19].id), ]; } diff --git a/frontend/lib/models/course.dart b/frontend/lib/models/course.dart index bb393b6..d3e8e1e 100644 --- a/frontend/lib/models/course.dart +++ b/frontend/lib/models/course.dart @@ -5,7 +5,7 @@ class Course { final int credits; final List branches; final String primaryRoom; - final String professorId; + final String professor_id; Course({ required this.id, @@ -14,7 +14,7 @@ class Course { required this.credits, required this.branches, required this.primaryRoom, - required this.professorId, + required this.professor_id, }); factory Course.fromJson(Map json) { @@ -25,8 +25,8 @@ class Course { credits: json['credits'], branches: (json['branches'] as List).map((item) => item as String).toList(), - primaryRoom: json['primaryRoom'], - professorId: json['professorId'], + primaryRoom: json['primary_room'], + professor_id: json['professor_id'], ); } @@ -37,8 +37,8 @@ class Course { 'name': courseName, 'credits': credits, 'branches': branches, - 'primaryRoom': primaryRoom, - 'professorId': professorId, + 'primary_room': primaryRoom, + 'professor_id': professor_id, }; } } diff --git a/frontend/lib/models/faculty.dart b/frontend/lib/models/faculty.dart index 4acb376..f2b2804 100644 --- a/frontend/lib/models/faculty.dart +++ b/frontend/lib/models/faculty.dart @@ -22,7 +22,7 @@ class Faculty { id: json['_id'], name: json['name'] ?? 'Smart Insti User', email: json['email'], - cabinNumber: json['cabinNumber'], + cabinNumber: json['cabin_number'], department: json['department'], courses: (json['courses'] as List) .map((item) => Course.fromJson(item)) @@ -35,7 +35,7 @@ class Faculty { '_id': id, 'name': name, 'email': email, - 'cabinNumber': cabinNumber, + 'cabin_number': cabinNumber, 'department': department, 'courses': courses, }; diff --git a/frontend/lib/models/lost_and_found.dart b/frontend/lib/models/lost_and_found.dart index 64a01ad..d7058b1 100644 --- a/frontend/lib/models/lost_and_found.dart +++ b/frontend/lib/models/lost_and_found.dart @@ -1,5 +1,4 @@ class LostAndFoundItem { - String userId; String name; String lastSeenLocation; String imagePath; @@ -8,7 +7,6 @@ class LostAndFoundItem { bool isLost; LostAndFoundItem({ - required this.userId, required this.name, required this.lastSeenLocation, required this.imagePath, @@ -19,7 +17,6 @@ class LostAndFoundItem { factory LostAndFoundItem.fromJson(Map json) { return LostAndFoundItem( - userId: json['user_id'], name: json['name'], lastSeenLocation: json['lastSeenLocation'], imagePath: json['imagePath'], @@ -31,7 +28,6 @@ class LostAndFoundItem { Map toJson() { return { - 'user_id': userId, 'name': name, 'lastSeenLocation': lastSeenLocation, 'imagePath': imagePath, diff --git a/frontend/lib/provider/courses_provider.dart b/frontend/lib/provider/courses_provider.dart index 737026c..3c81f08 100644 --- a/frontend/lib/provider/courses_provider.dart +++ b/frontend/lib/provider/courses_provider.dart @@ -126,7 +126,6 @@ class CoursesNotifier extends StateNotifier { ? 0 : int.parse(state.courseCreditController.text), primaryRoom: '', - professorId: '', ); state = state.copyWith( courses: [ From 1e9fc476ea23b4fec6a09efda53fd47faf1c2201 Mon Sep 17 00:00:00 2001 From: Arin Nigam Date: Sat, 3 Feb 2024 23:37:52 +0530 Subject: [PATCH 11/12] Revert "fixed naming convention" This reverts commit 8afc9cc79a4b759babad17fd3ce1f5626854e6c9. --- backend/models/course.js | 4 +-- backend/models/faculty.js | 2 +- backend/models/lost_and_found.js | 4 --- frontend/lib/constants/dummy_entries.dart | 40 ++++++++++----------- frontend/lib/models/course.dart | 12 +++---- frontend/lib/models/faculty.dart | 4 +-- frontend/lib/models/lost_and_found.dart | 4 +++ frontend/lib/provider/courses_provider.dart | 1 + 8 files changed, 36 insertions(+), 35 deletions(-) diff --git a/backend/models/course.js b/backend/models/course.js index 2093559..d29d67f 100644 --- a/backend/models/course.js +++ b/backend/models/course.js @@ -10,14 +10,14 @@ const courseSchema = new mongoose.Schema({ required: true, unique: true }, - primary_room: { + primaryRoom: { type: String, }, credits: { type: Number, required: true, }, - professor_id: { + professorId: { type: mongoose.Schema.Types.ObjectId, ref: 'Faculty', required: true, diff --git a/backend/models/faculty.js b/backend/models/faculty.js index 1f5e55e..c61c912 100644 --- a/backend/models/faculty.js +++ b/backend/models/faculty.js @@ -10,7 +10,7 @@ const facultySchema = new mongoose.Schema({ required: true, unique: true }, - cabin_number: { + cabinNumber: { type: String, }, department: { diff --git a/backend/models/lost_and_found.js b/backend/models/lost_and_found.js index 6d9c29d..2ff415d 100644 --- a/backend/models/lost_and_found.js +++ b/backend/models/lost_and_found.js @@ -1,10 +1,6 @@ import mongoose from 'mongoose'; const lostAndFoundItemSchema = new mongoose.Schema({ - userId: { - type: String, - required: true - }, name: { type: String, required: true diff --git a/frontend/lib/constants/dummy_entries.dart b/frontend/lib/constants/dummy_entries.dart index 6fa8c12..32f06d8 100644 --- a/frontend/lib/constants/dummy_entries.dart +++ b/frontend/lib/constants/dummy_entries.dart @@ -260,7 +260,7 @@ class DummyCourses { branches: ['Computer Science'], credits: 3, primaryRoom: 'LT-1', - professor_id: DummyFaculties.faculties[0].id), + professorId: DummyFaculties.faculties[0].id), Course( id: '2', courseCode: 'ME102', @@ -268,7 +268,7 @@ class DummyCourses { branches: ['Mechanical Engineering'], credits: 3, primaryRoom: 'LT-2', - professor_id: DummyFaculties.faculties[1].id), + professorId: DummyFaculties.faculties[1].id), Course( id: '3', courseCode: 'EE103', @@ -276,7 +276,7 @@ class DummyCourses { branches: ['Electrical Engineering'], credits: 3, primaryRoom: 'LT-3', - professor_id: DummyFaculties.faculties[2].id), + professorId: DummyFaculties.faculties[2].id), Course( id: '4', courseCode: 'EE104', @@ -284,7 +284,7 @@ class DummyCourses { branches: ['Civil Engineering'], credits: 3, primaryRoom: 'LT-4', - professor_id: DummyFaculties.faculties[3].id), + professorId: DummyFaculties.faculties[3].id), Course( id: '5', courseCode: 'CHE105', @@ -292,7 +292,7 @@ class DummyCourses { branches: ['Chemical Engineering'], credits: 3, primaryRoom: 'LH-1', - professor_id: DummyFaculties.faculties[4].id), + professorId: DummyFaculties.faculties[4].id), Course( id: '6', courseCode: 'BT106', @@ -300,7 +300,7 @@ class DummyCourses { branches: ['Biotechnology'], credits: 3, primaryRoom: 'LH-2', - professor_id: DummyFaculties.faculties[5].id), + professorId: DummyFaculties.faculties[5].id), Course( id: '7', courseCode: 'AE107', @@ -308,7 +308,7 @@ class DummyCourses { branches: ['Aerospace Engineering'], credits: 3, primaryRoom: 'LH-3', - professor_id: DummyFaculties.faculties[6].id), + professorId: DummyFaculties.faculties[6].id), Course( id: '8', courseCode: 'IT108', @@ -316,7 +316,7 @@ class DummyCourses { branches: ['Information Technology'], credits: 3, primaryRoom: 'LH-4', - professor_id: DummyFaculties.faculties[7].id), + professorId: DummyFaculties.faculties[7].id), Course( id: '9', courseCode: 'MT109', @@ -324,7 +324,7 @@ class DummyCourses { branches: ['Mechatronics'], credits: 3, primaryRoom: 'LH-5', - professor_id: DummyFaculties.faculties[8].id), + professorId: DummyFaculties.faculties[8].id), Course( id: '10', courseCode: 'RE110', @@ -332,7 +332,7 @@ class DummyCourses { branches: ['Robotics Engineering'], credits: 3, primaryRoom: 'LH-6', - professor_id: DummyFaculties.faculties[9].id), + professorId: DummyFaculties.faculties[9].id), Course( id: '11', courseCode: 'IE111', @@ -340,7 +340,7 @@ class DummyCourses { branches: ['Industrial Engineering'], credits: 3, primaryRoom: 'LH-7', - professor_id: DummyFaculties.faculties[10].id), + professorId: DummyFaculties.faculties[10].id), Course( id: '12', courseCode: 'CE112', @@ -348,7 +348,7 @@ class DummyCourses { branches: ['Computer Engineering'], credits: 3, primaryRoom: 'LH-8', - professor_id: DummyFaculties.faculties[11].id), + professorId: DummyFaculties.faculties[11].id), Course( id: '13', courseCode: 'SE113', @@ -356,7 +356,7 @@ class DummyCourses { branches: ['Software Engineering'], credits: 3, primaryRoom: 'ROOM-101', - professor_id: DummyFaculties.faculties[12].id), + professorId: DummyFaculties.faculties[12].id), Course( id: '14', courseCode: 'EN114', @@ -364,7 +364,7 @@ class DummyCourses { branches: ['Environmental Engineering'], credits: 3, primaryRoom: 'ROOM-102', - professor_id: DummyFaculties.faculties[13].id), + professorId: DummyFaculties.faculties[13].id), Course( id: '15', courseCode: 'PE115', @@ -372,7 +372,7 @@ class DummyCourses { branches: ['Petrolesum[ Engineer]ing'], credits: 3, primaryRoom: 'ROOM-103', - professor_id: DummyFaculties.faculties[14].id), + professorId: DummyFaculties.faculties[14].id), Course( id: '16', courseCode: 'NE116', @@ -380,7 +380,7 @@ class DummyCourses { branches: ['Nuclear Engineering'], credits: 3, primaryRoom: 'ROOM-104', - professor_id: DummyFaculties.faculties[15].id), + professorId: DummyFaculties.faculties[15].id), Course( id: '17', courseCode: 'BE117', @@ -388,7 +388,7 @@ class DummyCourses { branches: ['Biomedical Engineering'], credits: 3, primaryRoom: 'ROOM-201', - professor_id: DummyFaculties.faculties[16].id), + professorId: DummyFaculties.faculties[16].id), Course( id: '18', courseCode: 'CE118', @@ -396,7 +396,7 @@ class DummyCourses { branches: ['Chemical Engineering'], credits: 3, primaryRoom: 'ROOM-202', - professor_id: DummyFaculties.faculties[17].id), + professorId: DummyFaculties.faculties[17].id), Course( id: '19', courseCode: 'EE119', @@ -404,7 +404,7 @@ class DummyCourses { branches: ['Electronics Engineering'], credits: 3, primaryRoom: 'ROOM-203', - professor_id: DummyFaculties.faculties[18].id), + professorId: DummyFaculties.faculties[18].id), Course( id: '20', courseCode: 'CS120', @@ -412,7 +412,7 @@ class DummyCourses { branches: ['Computer Science'], credits: 3, primaryRoom: 'ROOM-204', - professor_id: DummyFaculties.faculties[19].id), + professorId: DummyFaculties.faculties[19].id), ]; } diff --git a/frontend/lib/models/course.dart b/frontend/lib/models/course.dart index d3e8e1e..bb393b6 100644 --- a/frontend/lib/models/course.dart +++ b/frontend/lib/models/course.dart @@ -5,7 +5,7 @@ class Course { final int credits; final List branches; final String primaryRoom; - final String professor_id; + final String professorId; Course({ required this.id, @@ -14,7 +14,7 @@ class Course { required this.credits, required this.branches, required this.primaryRoom, - required this.professor_id, + required this.professorId, }); factory Course.fromJson(Map json) { @@ -25,8 +25,8 @@ class Course { credits: json['credits'], branches: (json['branches'] as List).map((item) => item as String).toList(), - primaryRoom: json['primary_room'], - professor_id: json['professor_id'], + primaryRoom: json['primaryRoom'], + professorId: json['professorId'], ); } @@ -37,8 +37,8 @@ class Course { 'name': courseName, 'credits': credits, 'branches': branches, - 'primary_room': primaryRoom, - 'professor_id': professor_id, + 'primaryRoom': primaryRoom, + 'professorId': professorId, }; } } diff --git a/frontend/lib/models/faculty.dart b/frontend/lib/models/faculty.dart index f2b2804..4acb376 100644 --- a/frontend/lib/models/faculty.dart +++ b/frontend/lib/models/faculty.dart @@ -22,7 +22,7 @@ class Faculty { id: json['_id'], name: json['name'] ?? 'Smart Insti User', email: json['email'], - cabinNumber: json['cabin_number'], + cabinNumber: json['cabinNumber'], department: json['department'], courses: (json['courses'] as List) .map((item) => Course.fromJson(item)) @@ -35,7 +35,7 @@ class Faculty { '_id': id, 'name': name, 'email': email, - 'cabin_number': cabinNumber, + 'cabinNumber': cabinNumber, 'department': department, 'courses': courses, }; diff --git a/frontend/lib/models/lost_and_found.dart b/frontend/lib/models/lost_and_found.dart index d7058b1..64a01ad 100644 --- a/frontend/lib/models/lost_and_found.dart +++ b/frontend/lib/models/lost_and_found.dart @@ -1,4 +1,5 @@ class LostAndFoundItem { + String userId; String name; String lastSeenLocation; String imagePath; @@ -7,6 +8,7 @@ class LostAndFoundItem { bool isLost; LostAndFoundItem({ + required this.userId, required this.name, required this.lastSeenLocation, required this.imagePath, @@ -17,6 +19,7 @@ class LostAndFoundItem { factory LostAndFoundItem.fromJson(Map json) { return LostAndFoundItem( + userId: json['user_id'], name: json['name'], lastSeenLocation: json['lastSeenLocation'], imagePath: json['imagePath'], @@ -28,6 +31,7 @@ class LostAndFoundItem { Map toJson() { return { + 'user_id': userId, 'name': name, 'lastSeenLocation': lastSeenLocation, 'imagePath': imagePath, diff --git a/frontend/lib/provider/courses_provider.dart b/frontend/lib/provider/courses_provider.dart index 3c81f08..737026c 100644 --- a/frontend/lib/provider/courses_provider.dart +++ b/frontend/lib/provider/courses_provider.dart @@ -126,6 +126,7 @@ class CoursesNotifier extends StateNotifier { ? 0 : int.parse(state.courseCreditController.text), primaryRoom: '', + professorId: '', ); state = state.copyWith( courses: [ From a55d579b6a9cbc8a4e1da078d3ecdeeda6b090ca Mon Sep 17 00:00:00 2001 From: Arin Nigam Date: Sat, 3 Feb 2024 23:42:55 +0530 Subject: [PATCH 12/12] added room schema --- backend/models/room.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 backend/models/room.js diff --git a/backend/models/room.js b/backend/models/room.js new file mode 100644 index 0000000..2af0ea3 --- /dev/null +++ b/backend/models/room.js @@ -0,0 +1,26 @@ + +const mongoose = require('mongoose'); + +const roomSchema = new mongoose.Schema({ + id: { + type: String, + required: true, + }, + name: { + type: String, + required: true, + }, + vacant: { + type: Boolean, + default: true, + }, + occupantId: { + type: String, + default: null, + }, +}); + +const Room = mongoose.model('Room', roomSchema); + +module.exports = Room; +