Skip to content

Commit fe203e1

Browse files
Frontend added
1 parent fa1180f commit fe203e1

14 files changed

Lines changed: 591 additions & 2 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const Teacher = require('../../Modules/Teacher/module.teacher');
2+
3+
const createTeacher = async (req, res) => {
4+
if(req.body) {
5+
const teacher = new Teacher(req.body);
6+
await teacher.save()
7+
.then(data=>{
8+
res.status(200).send({data: data});
9+
})
10+
.catch(error =>{
11+
res.status(500).send({error: error.message});
12+
});
13+
}
14+
}
15+
16+
const getAllTeachers = async (req, res) => {
17+
await Teacher.find({})
18+
.then(data=>{
19+
res.status(200).send({data: data});
20+
})
21+
.catch(error =>{
22+
res.status(500).send({error: error.message});
23+
});
24+
}
25+
26+
const viewTeacherById = async (req, res) => {
27+
if (req.params && req.params.id) {
28+
await Teacher.findById(req.params.id)
29+
.populate('teachers', '_id firstName lastName nic contactNumber email qualificationType')
30+
.then(response => {
31+
res.status(200).send({ data: response });
32+
})
33+
.catch(error => {
34+
res.status(500).send({ error: error.message });
35+
});
36+
}
37+
}
38+
39+
40+
const updateById = async (req, res) => {
41+
const id = req.params.id;
42+
const {status} = req.body;
43+
const updateTeacher = {
44+
status
45+
}
46+
const update = await Teacher.findByIdAndUpdate(id, updateTeacher)
47+
.then(() => {
48+
res.status(200).send({status: "Teacher Registration Updated"})
49+
}).catch((err) => {
50+
console.log(err);
51+
res.status(500).send({status: " Error", error:err.message});
52+
})
53+
}
54+
55+
const deleteById = async (req, res) => {
56+
const id = req.params.id
57+
await Teacher.findByIdAndRemove(id).exec()
58+
res.send('Teacher Registration Declined');
59+
}
60+
61+
module.exports = {
62+
createTeacher,
63+
getAllTeachers,
64+
viewTeacherById,
65+
updateById,
66+
deleteById
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const Profile = require('../../Modules/Teacher/module.tprofile');
2+
3+
const createProfile = async (req, res) => {
4+
if(req.body) {
5+
const profile = new Profile(req.body);
6+
await profile.save()
7+
.then(data=>{
8+
res.status(200).send({data: data});
9+
})
10+
.catch(error =>{
11+
res.status(500).send({error: error.message});
12+
});
13+
}
14+
}
15+
16+
const getAllProfiles = async (req, res) => {
17+
await Profile.find({})
18+
.then(data=>{
19+
res.status(200).send({data: data});
20+
})
21+
.catch(error =>{
22+
res.status(500).send({error: error.message});
23+
});
24+
}
25+
26+
const viewProfileById = async (req, res) => {
27+
if (req.params && req.params.id) {
28+
await Profile.findById(req.params.id)
29+
.populate('profile', '_id registrationNumber fName lName nic passportNumber address contactNumber email password editedDate')
30+
.then(response => {
31+
res.status(200).send({ data: response });
32+
})
33+
.catch(error => {
34+
res.status(500).send({ error: error.message });
35+
});
36+
}
37+
}
38+
39+
40+
const updateProfileById = async (req, res) => {
41+
const id = req.params.id;
42+
const {status} = req.body;
43+
const updateProfile = {
44+
status
45+
}
46+
const update = await Profile.findByIdAndUpdate(id, updateProfile)
47+
.then(() => {
48+
res.status(200).send({status: "Teacher Profile Updated"})
49+
}).catch((err) => {
50+
console.log(err);
51+
res.status(500).send({status: " Error", error:err.message});
52+
})
53+
}
54+
55+
const deleteProfileById = async (req, res) => {
56+
const id = req.params.id
57+
await Profile.findByIdAndRemove(id).exec()
58+
res.send('Teacher Profile Deleted');
59+
}
60+
61+
module.exports = {
62+
createProfile,
63+
getAllProfiles,
64+
viewProfileById,
65+
updateProfileById,
66+
deleteProfileById
67+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
const mongoose = require('mongoose');
2+
3+
const TeacherSchema = new mongoose.Schema({
4+
firstName: {
5+
type: String,
6+
required: true,
7+
min: 2,
8+
max: 450
9+
},
10+
lastName: {
11+
type: String,
12+
required: true,
13+
min: 2,
14+
max: 450
15+
},
16+
gender: {
17+
type: String,
18+
required: true,
19+
min: 2,
20+
max: 450
21+
},
22+
nic: {
23+
type: String,
24+
trim: true
25+
},
26+
passportNumber: {
27+
type: String,
28+
trim: true
29+
},
30+
address : {
31+
type: String,
32+
required: true,
33+
min: 2,
34+
max: 450
35+
},
36+
contactNumber: {
37+
type: String,
38+
required: true,
39+
min: 2,
40+
max: 450
41+
},
42+
email: {
43+
type: String,
44+
required: true,
45+
min: 2,
46+
max: 450
47+
},
48+
qualificationType : {
49+
type: String,
50+
required: true,
51+
min: 2,
52+
max: 1050
53+
},
54+
academicInstitute : {
55+
type: String,
56+
required: true,
57+
min: 2,
58+
max: 1050
59+
},
60+
academicYear : {
61+
type: Number,
62+
required: true,
63+
},
64+
subjects : {
65+
type: String,
66+
required: true,
67+
min: 2,
68+
max: 1050
69+
},
70+
teachingInstitute : {
71+
type: String,
72+
required: true,
73+
min: 2,
74+
max: 1050
75+
},
76+
77+
teachingYear : {
78+
type: Number,
79+
required: true,
80+
},
81+
majorSubjects : {
82+
type: String,
83+
required: true,
84+
min: 2,
85+
max: 1050
86+
},
87+
88+
89+
associationName : {
90+
type: String,
91+
required: true,
92+
min: 2,
93+
max: 1050
94+
},
95+
regNumber : {
96+
type: String,
97+
required: true,
98+
min: 2,
99+
max: 1050
100+
},
101+
experienceYear : {
102+
type: Number,
103+
required: true,
104+
},
105+
schoolName : {
106+
type: String,
107+
required: true,
108+
min: 2,
109+
max: 1050
110+
},
111+
taughtSubjects : {
112+
type: String,
113+
required: true,
114+
min: 2,
115+
max: 1050
116+
},
117+
status: {
118+
type: String,
119+
default: "not approved"
120+
},
121+
});
122+
123+
const Teacher = mongoose.model('teachers', TeacherSchema);
124+
module.exports = Teacher;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const mongoose = require('mongoose');
2+
3+
const ProfileSchema = new mongoose.Schema({
4+
5+
registrationNumber: {
6+
type: String,
7+
required: true,
8+
},
9+
fName: {
10+
type: String,
11+
required: true,
12+
min: 2,
13+
max: 450
14+
},
15+
lName: {
16+
type: String,
17+
required: true,
18+
min: 2,
19+
max: 450
20+
},
21+
NIC: {
22+
type: String,
23+
trim: true
24+
},
25+
passportNumber: {
26+
type: String,
27+
trim: true
28+
},
29+
address : {
30+
type: String,
31+
required: true,
32+
min: 2,
33+
max: 450
34+
},
35+
contactNumber: {
36+
type: String,
37+
required: true,
38+
min: 2,
39+
max: 450
40+
},
41+
email: {
42+
type: String,
43+
required: true,
44+
min: 2,
45+
max: 450
46+
},
47+
password : {
48+
type: String,
49+
required: true,
50+
min: 2,
51+
max: 1050
52+
},
53+
editedDate: {
54+
type: Date,
55+
},
56+
57+
58+
});
59+
60+
const Profile = mongoose.model('teacherprofile', ProfileSchema);
61+
module.exports = Profile;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const express = require('express');
2+
const router = express.Router();
3+
const controller = require('../../Controllers/Teacher/controller.teacher');
4+
5+
module.exports = function () {
6+
router.post('/createTeacher', controller.createTeacher);
7+
router.get('/', controller.getAllTeachers);
8+
router.get('/viewbyid/:id', controller.viewTeacherById);
9+
router.put('/update/:id', controller.updateById);
10+
router.delete('/delete/:id', controller.deleteById);
11+
return router;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const express = require('express');
2+
const router = express.Router();
3+
const controller = require('../../Controllers/Teacher/controller.tprofile');
4+
5+
module.exports = function () {
6+
router.post('/createProfile', controller.createProfile);
7+
router.get('/', controller.getAllProfiles);
8+
router.get('/viewbyid/:id', controller.viewProfileById);
9+
router.put('/update/:id', controller.updateProfileById);
10+
router.delete('/delete/:id', controller.deleteProfileById);
11+
return router;
12+
}

Backend/server.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ const mongoose = require('mongoose');
33
const dotenv = require('dotenv');
44
const cors = require('cors');
55
const bodyParser = require('body-parser');
6+
const TeacherAPI = require('./Routes/Teacher/route.teacher');
7+
const ProfileAPI = require('./Routes/Teacher/route.tprofile');
68

79
dotenv.config();
810
const app = express();
911
app.use(cors());
1012
app.use(bodyParser.json());
1113

12-
const PORT = process.env.PORT || 8080;
14+
const PORT = process.env.PORT || 8082;
1315
/**
1416
* Get MONGODB_URI from .env
1517
*/
@@ -38,6 +40,8 @@ app.route('/').get((req, res) => {
3840
});
3941

4042
//API endpoints
43+
app.use('/teacher', TeacherAPI());
44+
app.use('/profile', ProfileAPI());
4145

4246

4347

frontend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"axios": "^0.21.1",
1010
"react": "^17.0.2",
1111
"react-dom": "^17.0.2",
12-
"react-router-dom": "^5.2.0",
1312
"react-scripts": "4.0.3",
1413
"web-vitals": "^1.0.1"
1514
},
@@ -36,5 +35,8 @@
3635
"last 1 firefox version",
3736
"last 1 safari version"
3837
]
38+
},
39+
"devDependencies": {
40+
"react-router-dom": "^5.2.0"
3941
}
4042
}

0 commit comments

Comments
 (0)