Skip to content
Dirk Kremer edited this page Mar 28, 2022 · 27 revisions

In the following article, the API is documented. The attribute role definies, which User-Role can access the individual interface.

JWT for Authentication

To authenticate a user, they must send a JWT with each request.
To send the JWT, the header Authorization must be set with the following format: Bearer <token>.
The JWT is signed with a random 64-Byte Token, which will be regenerated at every restart of the server.
It expires after 12 Hours.

Payload of the JWT

{
  "id":user_id,
  "username":"username",
  "fullname":"fullname",
  "role":"student"|"teacher"|"administrator",
  "exp":time_to_expire,
  "course": {
      "id": 1,
      "name": "course"
   } //null if the person isn't assigned to a course
}

Middleware

The middleware verifies and decodes the delievered JWT, if the request is not to /user/login.
If the JWT could not be verified, a response with the HTTP-Status 401 and the message Invalid JWT is send.

/user

POST /user/register

Register a new user

Roles

administrator

Request-Data

{
  "username":"username",
  "password":"password",
  "role":"student"|"teacher"|"administrator",
  "fullname":"fullname",
  "address":"address",
  "matriculationNumber":"matriculationNumber",
  "mail":"[email protected]"
}

It may be noticed, that the role will default to student, if none of the role listed above is used.

Response-Data

On success returns the HTTP-Status 200.
On failure returns the HTTP-Status 500.

POST /user/login

Try to login a user

Roles

Unauthenticated users

Request-Data

{
  "username":"username",
  "password":"password
}

Response-Data

On success returns the HTTP-Status 200 and a JWT for authentication.
On failure returns the HTTP-Status 403 and the message Wrong username or password.

POST /user/delete

Deletes a user from the repository

Roles

administrator

Request-Data

{
  "username":"username"
}

Response-Data

On success returns the HTTP-Status 200 and the message The user has been deleted.
On failure returns the HTTP-Status 500 and the message The user could not be deleted.

POST /user/changePassword

Change the password of the given user

Roles

student & teacher may only change their own password. administrator may change their own password as the password of other users.

Request-Data

{
  "username":"username",
  "password":"password
}

Response-Data

On success returns the HTTP-Status 200 and the message The password has been changed.
On failure returns the HTTP-Status 500 and the message Password could not be changed.

GET /user/getAll

Get all users

Roles

administrator

Request-Data

No request data

Response-Data

An array of the following JSON-Objects

{
    "id": 5,
    "fullname": "fullname",
    "address": "address",
    "matriculationNumber": "matriculationNumber",
    "mail": "[email protected]",
    "userId": {
        "id": 14,
        "username": "username",
        "isTeacher": false|true,
        "isAdministrator": false|true,
        "course": {
             "id": 1,
             "name": "course"
        } //null if the person isn't assigned to a course
    }
}

/grades

GET /grades/:studentId

Returns the grades of the student specified in :studentId

Roles

student may only see his own grades
administrator may see the grades of all students

Reqeust-Data

No request data

Response-Data

An array with the following JSON-Objects

{
    "grade": 3,
    "weight": 100,
    "moduleId": {
        "id": 1,
        "name": "Test",
        "description": "Test"
    }
}

GET /grades/module/:moduleId

Returns the grades of the module specified in :moduleId

Roles

teacher may only see the grades of his own modules
administrator may see the grades of all modules

Reqeust-Data

No request data

Response-Data

An array with the following JSON-Objects

{
    "id": 1
    "grade": 3,
    "weight": 100,
    "studentId": {
        "id": 1,
        "username": "student"
    },
    "studentDetails": {
        "fullname": "fullname",
        "matriculationNumber": "matriculationNumber"
    }
}

POST /grades/insert

Insert or update a new grade

Roles

teacher may insert or update new grades for his module
administrator may insert or update new grades for every module

Request-Data

{
    "id":1, // Only needed if updating a existing grade
    "moduleId":1, 
    "studentId":1,
    "grade":1,
    "weight":100
}

Response-Data

On success returns the HTTP-Status 200 and the message The grade has been saved.
On failure returns the HTTP-Status 500 and the message The grade has not been saved.

POST /grades/delete

Delete the grade

Roles

teacher for their own modules administrator for every module

Request-Data

{
    "id":1, // Only needed if updating a existing grade
    "moduleId":1, 
    "studentId":1,
    "grade":1,
    "weight":100
}

Response

On success returns the HTTP-Status 200 and the message The grade has been deleted.
On failure returns the HTTP-Status 500 and the message The grade could not be deleted.

/timetable

POST /timetable/insert

Insert or update a new entry into the timetable

Roles

teacher can insert entries for their module administrator can insert entries for every module

Reqeust

{
    "id":1, // Only needed if updating a existing entry
    "startTime":Date, 
    "endTime":Date,
    "assignedModule":1,
    "description":"description", // can be null
    "room":"A38"
}

Response

On success returns the HTTP-Status 200 and the message The entry has been saved.
On failure returns the HTTP-Status 500 and the message The entry could not be saved.

GET /timetable/getPerson

Retrieve entries for a person

Roles

teacher may get the entries for their modules
student may get the entries for their assigned course

Request

No request data

Response

A array with the following JSON-Objects

{
    "id": 2,
    "startTime": "2022-02-02T11:30:19.490Z",
    "endTime": "2022-02-02T12:30:19.490Z",
    "description": null,
    "room": "A13",
    "assignedModule": {
        "id": 1,
        "name": "tset",
        "description": "Test",
        "assignedCourse": {
            "id": 1,
            "name": "test"
        }
    }
}

GET /timetable/getModule/:moduleId

Retrieve entries for a module, specified by :moduleId

Roles

tbd

Request

No request data

Response

A array with the following JSON-Objects

{
    "id": 2,
    "startTime": "2022-02-02T11:30:19.490Z",
    "endTime": "2022-02-02T12:30:19.490Z",
    "description": null,
    "room": "A13",
    "assignedModule": {
        "id": 1,
        "name": "tset",
        "description": "Test"
    }
}

GET /timetable/getCourse/:courseId

Retrieve entries for a module, specified by :courseId

Roles

tbd

Request

No request data

Response

A array with the following JSON-Objects

{
    "id": 2,
    "startTime": "2022-02-02T11:30:19.490Z",
    "endTime": "2022-02-02T12:30:19.490Z",
    "description": null,
    "room": "A13",
    "assignedModule": {
        "id": 1,
        "name": "tset",
        "description": "Test",
        "assignedCourse": {
            "id": 1,
            "name": "test"
        }
    }
}

POST /timetable/delete

Delete a entry

Roles

teacher may delete the entries of their own module
administrator may delete all entries

Reqeust

{
    "id":1,
    "startTime":Date, 
    "endTime":Date,
    "assignedModule":1,
    "description":"description", // can be null
    "room":"A38"
}

Response

On success returns the HTTP-Status 200 and the message The entry has been deleted.
On failure returns the HTTP-Status 500 and the message The entry could not be deleted.

/course

POST /course/:courseId/changeCourse

Change the name of a course

Roles

administrator

Request

{
    "newName":"newCoursename"
}

Response

On success returns the HTTP-Status 200 and the message The course has been updated.
On failure returns the HTTP-Status 500 and the message Course could not be updated.

POST /course/register

Register a new course

Roles

administrator

Request

{
    "name":"coursename",
    "students":"list of student_id"
}

Response

On success returns the HTTP-Status 200.
On failure returns the HTTP-Status 403.

POST /course/:courseId/delete

Delete a course

Roles

administrator

Request

No request data

Response

On success returns the HTTP-Status 200 and the message The course has been deleted.
On failure returns the HTTP-Status 500 and the message Course could not deleted updated.

POST /course/:courseId/addStudent

Add students to a course

Roles

administrator

Request

{
    "students":"list of student_id"
}

Response

On success returns the HTTP-Status 200 and the message The students have been added.
On failure returns the HTTP-Status 500 and the message Students could not be added.

POST /course/:courseId/deleteStudent

Deletes students from a course

Roles

administrator

Request

{
    "students":"list of student_id"
}

Response

On success returns the HTTP-Status 200 and the message The students have been deleted.
On failure returns the HTTP-Status 500 and the message Students could not be deleted.

GET /course/:courseId

Return the informations of a course

Roles

tbd

Request

No request data

Response

On success returns the HTTP-Status 200 and a Course-Object.
On failure returns the HTTP-Status 500 and the message Could not find the course.

GET /course/getAll

Return all course, with their assigned students and their assigned modules

Roles

administrator may see all courses

Request

No request data

On success return the HTTP-Status 200 and a array of the following objects

    {
        "id": 1,
        "name": "course",
        "students": [
            {
                "id": 4,
                "userDetail": {
                    "fullname": "student"
                }
            }
        ],
        "assignedModules": [
            {
                "id": 1,
                "name": "module"
            }
        ]
    }

/module

POST /module/register

Register a new module

Roles

administrator

Request

{
    "name": "modulename",
    "description": "description",
    "assignedTeacher": "list of teacher_id",
    "assignedCourse": "course_id",
    "submodule": "list of submodule_id"
}

Response

On success returns the HTTP-Status 200.
On failure returns the HTTP-Status 403.

POST /module/:moduleId/changeName

Changes the name of a module

Roles

administrator

Request

{
    "name": "newname"
}

Respone

On success returns the HTTP-Status 200 and the message The Name has been changed.
On failure returns the HTTP-Status 500 and the message Name could not be changed.

Post /module/:moduleId/addSubmodule

Adds a submodule to a module

Roles

administrator

Request

{
    "submodule": "List of submodule_id"
}

Response

On success returns the HTTP-Status 200 and the message The Submodule have been added.
On failure returns the HTTP-Status 500 and the message Submodule could not be added.

POST module/:moduleId/deleteSubmodule

Deletes a submodule of a module

Roles

administrator

Request

{
    "submodule": "List of submodule_id"
}

Response

On success returns the HTTP-Status 200 and the message The Submodule have been deleted.
On failure returns the HTTP-Status 500 and the message Submodule could not bee deleted.

POST /module/:moduleId/changeDescription

Changes the description of a module

Roles

administrator

Request

{
    "description": "new description"
}

Response

On success returns the HTTP-Status 200 and the message The Description has been changed.
On failure returns the HTTP-Status 500 and the message Description could not be changed.

POST /module/:moduleId/deleteCourse

Deletes the course from the module

Roles

administrator

Request

No request data

Response

On success returns the HTTP-Status 200 and the message The Course has been deleted.
On failure returns the HTTP-Status 500 and the message Course could not be deleted.

POST /module/:moduleId/addCourse

Add a course to the module

Roles

administrator

Request

{
    "course": "course_id"
}

Response

On success returns the HTTP-Status 200 and the message The Course has been added.
On failure returns the HTTP-Status 500 and the message Course could not be added.

POST /module/:moduleId/addTeacher

Add a teacher to the module

Roles

administrator

Request

{
    "teacher": "list of teacher_id"
}

Response

On success returns the HTTP-Status 200 and the message The Teacher has been added.
On failure returns the HTTP-Status 500 and the message Teacher could not be added.

POST /module/:moduleId/deleteTeacher

Deletes a teacher from the module

Roles

administrator

Request

{
    "teacher": "list of teacher_id"
}

Response

On success returns the HTTP-Status 200 and the message The Teacher has been deleted.
On failure returns the HTTP-Status 500 and the message Teacher could not be deleted.

POST /module/:moduleId/deleteModule

Deletes the module

Roles

administrator

Requst

No request data

Response

On success returns the HTTP-Status 200 and the message The Module has been deleted.
On failure returns the HTTP-Status 500 and the message Module could not be deleted.

GET /module/:moduleId

Return the information of a module

Roles

tbd

Request

No request data

Response

On success returns the HTTP-Status 200 and the Module-Object.
On failure returns the HTTP-Status 500 and the message Could not find the module.

Get /module/getModules

Return all modules of the specific module

Roles

students and teacher can get all their assigned modules

Request

No request data

Response

On success returns the HTTP-Status 200 and a array of the following objects

    {
        "id": 1,
        "name": "module",
        "description": "module"
    }

On failure returns the HTTP-Status 500 and the message Could not retrieve modules.

/moduleItem

POST /module/:moduleId/addModuleItem

Registers a new ModuleItem for the Module

Roles

administrator

Requst

{
    "content": "content",
    "webLink": "webLink",
    "hasFileUpload": boolean,
    "downloadableFile": {
        "owner": "user_id",
        "name": "name",
        "path": "path"
    },
    "isVisible": "boolean",
    "dueDate": "dueDate"
}

Response

On success returns the HTTP-Status 200.
On failure returns the HTTP-Status 403.

GET /module/:moduleId/:moduleItemId/select

Return the information of a moduleitem

Roles

tbd

Requst

No request data

Response

On success returns the HTTP-Status 200 and the moduleitem.
On failure returns the HTTP-Status 500 and the message ModuleItem could not be found.

GET /module/:moduleId/selectModuleItems

Return the informations of all moduleitems

Roles

tbd

Requst

No request data

Response

On success returns the HTTP-Status 200 and the moduleitems.
On failure returns the HTTP-Status 500 and the message No ModuleItems found for Module.

POST /module/:moduleId/:moduleItemId/changeModuleItem

Changes a moduleitem

Roles

teacher may only change their own moduleitems, administrator may change every moduleitem

Requst

{
    "content": "content",
    "webLink": "webLink",
    "hasFileUpload": boolean,
    "isVisible": boolean,
    "dueDate": "dueDate"
}

Response

On success returns the HTTP-Status 200 and the message ModuleItem has been changed.
On failure returns the HTTP-Status 500 and the message ModuleItem could not be changed.

POST /module/:moduleId/:moduleItemId/deleteModuleItem

Deletes a moduleitem

Roles

teacher may only delete their own moduleitems, administrator may delete every moduleitem

Requst

No request data

Response

On success returns the HTTP-Status 200 and the message The ModuleItem has been deleted.
On failure returns the HTTP-Status 500 and the message ModuleItem could not be deleted.

POST /module/:moduleId/deleteAllModuleItems

Deletes all moduleitems of a module

Roles

teacher may only delete their own moduleitems, administrator may delete every moduleitem

Requst

No request data

Response

On success returns the HTTP-Status 200 and the message The ModuleItems have been deleted.
On failure returns the HTTP-Status 500 and the message ModuleItems could not be deleted.

POST /module/:moduleId/:moduleItemId/addDownloadFile

Registers a downloadable file for a moduleitem

Roles

teacher may only add to their own moduleitems, administrator may add every moduleitem

Requst

{
    "owner": "user_id",
    "name": "name",
    "path": "path"
}

Response

On success returns the HTTP-Status 200 and the message Added new File to ModuleItem.
On failure returns the HTTP-Status 500 and the message Could not add File to ModuleItem.

POST /module/:moduleId/:moduleItemId/deleteFile

Deletes the downloadable file from a moduleitem

Roles

teacher may only add to their own moduleitems, administrator may add every moduleitem

Requst

No request data

Response

On success returns the HTTP-Status 200 and the message Deleted File.
On failure returns the HTTP-Status 500 and the message Could not delete File.

POST /module/:moduleId/:moduleItemId/uploadFile

Registers a uploaded file for a moduleitem if allowed

Roles

No permission restrictions

Requst

{
    "owner": "user_id",
    "name": "name",
    "path": "path"
}

Response

On success returns the HTTP-Status 200 and the message File has been uploaded.
On failure returns the HTTP-Status 500 and the message Could not upload File.

POST /module/:moduleId/:moduleItemId/deleteUploadedFile

Deletes a uploaded file from a moduleitem

Roles

student & teacher may delete their own file, administrator may delete all files

Requst

{
    "fileId": "file_id"
}

Response

On success returns the HTTP-Status 200 and the message File has been deleted.
On failure returns the HTTP-Status 500 and the message Could not delete file.

POST /module/:moduleId/:moduleItemId/deleteAllUploadedFiles

Deletes all uploaded file from a moduleitem

Roles

teacher may delete files from their own moduleitems, administrator may delete all files

Requst

No request data

Response

On success returns the HTTP-Status 200 and the message Files have been deleted.
On failure returns the HTTP-Status 500 and the message Could not delete files.

Clone this wiki locally