Skip to content

edocecchini01/homework-management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exam #2: "Compiti"

Student: s339169 Cecchini Edoardo

React Client Application Routes

  • Route /: page containing the menu with the options available according to the type of authenticated user. In case the user is not authenticated the user is redirected to the login page
  • Route /new-homework: page containing the form for creating a new homework, the content shown is a text-area for the question and the list of all students to choose from to form the group. (This route can only be used by users with teacher role)
  • Route /students: page containing the list of the entire class, with information about homeworks and the average score. A sorting option is also available to organize the list by different criteria. (This route can only be used by users with teacher role)
  • Route /homeworks: page containing a list of homeworks as cards, each showing key information. The content updates dynamically based on the user type or request. In particular, there is a filter parameter that can have 2 different values:
    • /homeworks?filter=ready: shows homeworks that already have an answer and are ready to be evaluated. (Used by teacher)
    • /homeworks?filter=close: shows homeworks that are closed and displays a dashboard with the average score of the authenticated student. (Used by student)
  • Route /homeworks/:id: page containing the detail of a single homework. The content changes dynamically so that a student can provide an answer and a teacher can grade it. The id is used to uniquely identify the homework displayed

API Server

List all homeworks

URL: /api/homeworks

HTTP Method: GET.

Description: Retrieve all homeworks of the current teacher.

Query Parameters:

  • filter (optional): ready to get only homeworks ready to be graded (with all answers submitted)

Response: 200 OK (success) or 500 Internal Server Error (generic error).

Response body:

[
  {
    "id": 1,
    "question": "Quanto fa 4 + 4?",
    "answer": "Fa 8!",
    "state": "close",
    "score": 20.0,
  },
  ...
]

Authorization (user role): teacher

Create a new homework

URL: /api/homeworks

HTTP Method: POST.

Description: Create a new homework for a group of students.

Request body:

{
  "question": "Quanto fa 4 + 4?",
  "studentsIds": [5,7,20]
}

Response: 201 Created (succes, with the created id), or 500 Internal Server Error (generic error). If the request body is not valid, 422 Unprocessable Entity (validation error).

Response body: None

Authorization (user role): teacher

Get a homework

URL: /api/homeworks/<id>

HTTP Method: GET.

Description: Retrieve the homework represented by <id>.

Response: 200 OK (success), 403 Forbidden (unauthorized access), 404 Not Found (wrong id), or 500 Internal Server Error (generic error).

Response body:

{
  "id": 1,
  "question": "Quanto fa 4 + 4?",
  "answer": "Fa 8!",
  "state": "close",
  "score": 20.0,
  "teacherName": "Mario",
  "teacherSurname": "Rossi",
  "group": [
    {
      "id": 2,
      "name": "Mario",
      "surname": "Rossi"
    },
    {
      "id": 3,
      "name": "Edoardo",
      "surname": "Cecchini"
    }
    ...
  ]
}

Authorization: authenticated

Grade a homework

URL: /api/homeworks/<id>/score

HTTP Method: PATCH.

Description: Insert a score for the homework represented by <id>.

Request body:

{
  "score": 0
}

Response: 204 No content (succes), 400 Bad Request (no answer), 404 Not Found (wrong id) or 500 Internal Server Error (generic error). If the request body is not valid, 422 Unprocessable Entity (validation error).

Response body: None

Authorization (user role): teacher

List all students

URL: /api/students

HTTP Method: GET.

Description: Retrieve all students.

Response: 200 OK (success) or 500 Internal Server Error (generic error).

Response body:

[
  {
    "id": 1,
    "name": "Edoardo",
    "surname": "Cecchini",
    "email": "s339169@studenti.polito.it",
  },
  ...
]

Authorization (user role): teacher

List all students stats

URL: /api/students/stats

HTTP Method: GET.

Description: Retrieve for all the students, how many open homework, how many closed homework, and the average score they got in the homework assigned by the current teacher.

Response: 200 OK (success) or 500 Internal Server Error (generic error).

Response body:

[
  {
    "id": 1,
    "name": "Edoardo",
    "surname": "Cecchini",
    "email": "s339169@studenti.polito.it"
    "openHomeworks": 5,
    "closeHomeworks": 20,
    "averageScore": 27.5
  },
  ...
]

Authorization (user role): teacher

List all open homeworks for a student

URL: /api/students/<id>/homeworks

HTTP Method: GET.

Description: Retrieve all the open homeworks assigned to the student represented by <id>.

Response: 200 OK (success), 404 Not Found (wrong id), or 500 Internal Server Error (generic error).

Response body:

[
  {
    "id": 1,
    "question": "Quanto fa 4 + 4?",
    "answer": "Fa 8!"
  },
  ...
]

Authorization (user role): student

Insert an answer for a homework

URL: /api/homeworks/<id>/answer

HTTP Method: PATCH.

Description: Send an answer for the homework identified by <id>.

Request body: A JSON object representing the action.

{
  "answer": "Fa 8!"
}

Response: 204 No content (success), 400 Bad Request (homework close), 404 Not Found (wrong id) or 500 Internal Server Error (generic error). If the request body is not valid, 422 Unprocessable Entity (validation error).

Response body: None

Authorization (user role): student

List stats for all closed homework of a student

URL: /api/students/<id>/homeworks/stats

HTTP Method: GET.

Description: Retrieve the scores and the total average score for all the closed homeworks assigned to the student represented by <id>.

Response: 200 OK (success), 404 Not Found (wrong id) or 500 Internal Server Error (generic error). In case of success, returns an array of questions in JSON format (see below). Else, returns an error message.

Response body:

{
  "homeworks": [
    {
      "id": 1,
      "question": "Quanto fa 4 + 4?",
      "answer": "Fa 8!",
      "state": "close",
      "score": 28
    },
    ...
  ],
  "averageScore": 27.5
}

Authorization (user role): student

Login

URL: /api/sessions

HTTP Method: POST.

Description: Authenticate a user with email and password using Passport.

Request body:

{
  "username": "user@example.com",
  "password": "password123"
}

Response: 201 Created (success), 401 Unauthorized (wrong credentials), or 500 Internal Server Error (generic error).

Response body:

{
  "id": 1,
  "name": "Marco",
  "surname": "Rossi",
  "email": "marco.rossi@student.it",
  "role": "student"
}

Get current session

URL: /api/sessions/current

HTTP Method: GET.

Description: Get information about the currently authenticated user.

Response: 200 OK (authenticated) or 401 Unauthorized (not authenticated).

Response body:

{
  "id": 1,
  "name": "Marco",
  "surname": "Rossi",
  "email": "marco.rossi@student.it",
  "role": "student"
}

Authorization (user role): authenticated

Logout

URL: /api/sessions/current

HTTP Method: DELETE.

Description: Logout the current user and destroy the session.

Response: 200 OK (success) or 500 Internal Server Error (generic error).

Response body: None

Authorization (user role): authenticated

Database Tables

  • Table users
    Contains all registered users. Fields:

    • id (PK) – unique identifier
    • name – first name
    • surname – last name
    • email – email address (username used for login)
    • password – hashed password
    • salt – per‑user salt for hashing
    • role – user type (teacher or student)
  • Table homeworks
    Stores each homework assignment. Fields:

    • id (PK) – unique identifier
    • question – the homework question
    • answer – group's submitted answer (nullable until answered)
    • state – status (open or close)
    • score – numeric grade from 0 to 30 (nullable until graded)
    • teacherId (FK → users.id) – the teacher who created it
  • Table student_homework
    Join table linking students to homeworks, also used to manage groups. Fields:

    • id (PK) – unique identifier
    • studentId (FK → users.id) – the student assigned
    • homeworkId (FK → homeworks.id) – the homework assigned

Main React Components

  • HomeworkList (in HomeworkList.jsx): Displays a filtered list of homeworks as cards with different views based on user role (teacher/student) and filter parameters (close/ready)
  • HomeworkCard (in HomeworkCard.jsx): Individual homework card component showing question preview, answer status, state badge, and score with click navigation to detail view
  • HomeworkDetail (in HomeworkDetail.jsx): Detailed homework view allowing students to submit/edit answers and teachers to grade submissions, with role-based authorization checks
  • NewHomeworkForm (in NewHomeworkForm.jsx): Form component for teachers to create new homework assignments with question input and student group selection
  • StudentList (in StudentList.jsx): Displays class statistics with sortable student cards showing the number of open homework, close homework and the average scores, includes filtering options (alphabetical, total homeworks, average score)
  • Home (in Home.jsx): Dashboard component with role-based navigation buttons providing access to different homework management actions
  • NavHeader (in NavHeader.jsx): Navigation bar with role-based menu items (Class tab only for teachers)
  • DefaultLayout (in DefaultLayout.jsx): Layout wrapper component providing consistent user interface
  • AuthComponents (in AuthComponents.jsx): Contains LoginForm for user authentication and LogoutButton
  • AuthContext (in AuthContext.jsx): React Context provider managing global authentication state and providing user access and login/logout functionality throughout the application
  • RequireRole (in RequireRole.jsx): Wrapper component for role-based route protection, restricting access based on user role (used to prevent students from accessing teacher routes)
  • Utils (in Utils.jsx): Utility components including ConfirmModal for confirmation dialogs, NotFound for 404 pages, and NotAuthorized for access denied messages

Screenshot

Homework creation

Screenshot

Status of the class

Screenshot

Users Credentials

Students:

(password = student123)

Teachers:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors