An API for the teachers to perform administrative functions for their students where teachers and students are identified by their email addresses.
The codebase is written entirely in JavaScript.
The API is based on Node.js together with Express, MySQL and Unit Testing using Jest.
- Register students under teacher.
- Suspend a student.
- Retrieve students' email registered under teacher(s).
- Retrieve list of students can receive notifications from a teacher.
The API assumes:
- You have MySQL Server and MySQL Workbench installed.
- You have Node.js installed.
Clone this repository, go into the folder and install the node modules:
npm install
Open the file and setup the password of your root user for your machine MySQL database.
/db/env.js
const env = {
development: {
database: 'school',
username: 'root',
password: 'secretpassword',
host: 'localhost',
port: '3306',
dialect: 'mysql',
timezone: 'Asia/Singapore',
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
}
}
Kindly do the Data Import in your MySQL Workbench with the sql file in the directory below :
/db/db-mysql.sql
It will create the database together with the tables with dummy data for unit testing
npm start
npm test
Swagger API Documentation UI is implemented in the project for easy understanding of the API. It can also work as a tool to test on the API.
URL: http://localhost:3000/api-docs
Host: localhost
Post: 3000
Request Method | URL Endpoint |
---|---|
POST | /api/register |
GET | /api/commonstudents?teacher=teachermel%40example.com |
POST | /api/suspend |
POST | /api/retrievefornotifications |
The students will be registered under the teacher.
Request body:
{
"teacher": "[email protected]",
"students": [
"[email protected]",
"[email protected]",
"[email protected]"
]
}
Response:
Status Code 204
It returns a list of students registered under the teacher in the query passed.
Request by Passing teacher Query:
/api/commonstudents?teacher=teachermel%40example.com
For students registered under 2 teachers:
/api/commonstudents?teacher=teachermolo%40gmail.com&teacher=teachermel%40gmail.com
Response Body:
{
"students": [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
]
}
The student will be suspended and will not be able to receive notifications.
Request Body:
{
"student": "[email protected]"
}
Response:
Status Code 204
It returns a list of students that can receive notifications, which registered under the teacher or mentioned in the notifications with the character '@'.
Request Body:
{
"teacher": "[email protected]",
"notification": "Hello Students! @[email protected] @[email protected]"
}
Response Body:
{
'students': [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
]
}
- Andrew Lai : [email protected]