In this lab you will be developing a server that stores data for a school, and a simple frontend. The school has the following data models:
- Classes
- Students
-
Take a look at the JavaScript Classes in the files
Class.js
,School.js
andStudent.js
. They will be our models for creating objects. -
In your server instantiate a
School
as a global variable. Something like:let mySchool = new School();
-
As you saw in
School.js
aSchool
object has a method calledaddClass()
. You will use this method to add a class to the school. Example:mySchool.addClass('physics', 'Henry Roman'); // Creates a Class Object with the name physics
-
It is your responsibility to implement and write the code for all the
School
methods outlined inSchool.js
. The comments above the methods document what the methods should do and return. You will use these methods in your server routes.
-
Class
es objects will be stored in theclasses
(this.classes
) property of theSchool
instance. -
The
classes
property of aSchool
is itself an object where the property key is the name of the class and the property value will be aClass
object. -
Each
Class
object has aname
property, ateacher
property with a string that represents the name of the instructor and astudents
property that holds an array ofStudent
s currently enrolled in that class.Class.js
is as follows:class Class { constructor(name, teacher) { this.name = name this.teacher = teacher this.students = [] } } module.exports = Class;
- Each student within a class is an object that stores four data points or properties:
- name
- age
- city
- grade
- The
Student
class found inStudent.js
has:class Student { constructor(name, age, city, grade) { this.name = name this.city = city this.age = age this.grade = grade } } module.exports = Student;
- A student can be enrolled in multiple classes. A student's grade is class dependant.
Method | Endpoint | Request Body |
---|---|---|
POST |
/class |
Class properties: name , teacher |
- Create an Express route/endpoint to handle the request as seen above.
- The method
addClass()
in theSchool
has already been implemented for you. Make sure you understand how it works. Use theaddClass()
method in your route handler. - If the class already exists, respond with an error message.
A successful response should look like:
{
"class": { "name": "Physics", "teacher": "Henry Roman", "students": []},
"message": "Created a new class",
"timestamp": "YYYY, MM/DD HH:MM:SS"
}
An error response should look like:
{
"error": "Please fill out all the information or Class already exists",
"timestamp": "YYYY, MM/DD HH:MM:SS"
}
Method | Endpoint | Request Body |
---|---|---|
POST |
/class/<class-name>/enroll |
Student properties: name , age , city , grade |
- Create an Express route/endpoint to handle the request as seen above.
- Add the new student to
<class-name>
class. - If the student is already enrolled in the given class, update/rewrite the student's information with the new data passed.
- Implement the method
enrollStudent()
in theSchool
object for accomplishing this. This method should add the student to thestudents
array within theClass
object.
A successful response should look like:
{
"student": { "name": "John", "age": 30, "city": "NYC", "grade": 75 },
"className": "physics",
"message": "Enrolled Student",
"timestamp": "YYYY, MM/DD HH:MM:SS"
}
An error response should look like:
{
"error": "Please fill out all the information for the student",
"timestamp": "YYYY, MM/DD HH:MM:SS"
}
Method | Endpoint | Query Parameters |
---|---|---|
GET |
/class/<class-name>/students |
failing=true|false , city=nyc |
- Create an Express route/endpoint to handle the request as seen above.
- This endpoint should return all the students enrolled on
<class-name>
. - If query parameters are passed:
- If
failing=true
, return all students that are failing the class, that is all students whose grade is less than 70. - If a
city
is passed return students whose city match the city passed. - If both
failing
andcity
are passed return students that are failing and that live in the specified city.
- If
- If not matches for students failing or in a given city are found, the
students
property of the response should have an empty array. - If the given class
<class-name>
doesn't exist and error should be returned. - Implement the methods
getStudentsByClass()
andgetStudentsByClassWithFilter()
in theSchool
class for accomplishing this.
{
"students": [
{ "name": "John", "age": 30, "city": "NYC", "grade": 75 },
{ "name": "Emily", "age": 28, "city": "LA", "grade": 80 }
],
"message": "Retrieved Students",
"timestamp": "YYYY, MM/DD HH:MM:SS"
}
An error response should look like:
{
"error": "Class physicslol doesn't exist.",
"timestamp": "YYYY, MM/DD HH:MM:SS"
}
Build three separate forms, for using each of the different routes:
Have text inputs for:
- class name
- teacher
Have a button to submit the form to your server. Display the response below the form.
Have text inputs for:
- class
- name
- age
- city
- grade
Have a button to submit the form to your server. Display the response below the form.
Have inputs for:
- class
- city (optional)
Have a checkbox input for:
- Show Failing Students Only
Have a button to submit the form to your server. Route and retrieve the appropriate information given your inputs. Display the response below the form.