Skip to content

IPRP/Peer-Review-Platform-Backend

Repository files navigation

Backend

Build Status

Peer-Review-Platform

📦 Requirements

  • Rust (Nightly)

  • MySQL (Tested with version 8.0.23 under WSL2)

    Before running the backend make sure that the Event Scheduler is turned on!

🚀 Run

For convenience checkout the latest releases.

If you want to run it manually use

cargo run

🧰 Configuration

The backend can be configured through the Rocket.toml file.

[global]
# Clear all data (but not events)
db_clear = true
# Insert some mock data
db_insert_mock_data = true
# Set timespan for reviews
review_time_days = 0
review_time_hours = 0
review_time_minutes = 5
# Rocket internal db config
# Please specify a correct db string!
[global.databases]
iprp_db = { url = "mysql://[email protected]:3306/iprp" }

The first two properties allow one to clear the database on start-up and/or insert some mock data.

Note: A user admin with password admin is always created when not already exists

The review time properties specify the duration for reviews. The aggregated time is then used by the system.

The last property asks for a connection string to your MySQL database.

Note: The database must be created manually before starting the Backend.

🗺️ API

Type Definitions:

  • <s> - String
    • <sr> - "teacher" | "student"
    • <sp> - "point" | "grade" | "percentage" | "truefalse"
  • <b> - Boolean
  • <i> - Integer
  • <f> - Float
  • <d> - Date
    Expected format is ISO 8601 without time zone like 2007-04-05T14:30:30
    In JavaScript it can be achieved like this: (new Date()).toISOString().split(".")[0]

Authentication

Route Method Input Output Notes
/login POST Basic Auth Header
{ "id": <i>, "role": <sr> }
Also returns a Session Cookie!
/logout POST Session Cookie Status Code

Teacher

Route Method Input Output Notes
Show all workshops
/teacher/workshops
GET
{ 
  "workshops": [ 
    { "id": <i>, "title": <s>, } , ... 
  ]
}
Retrieve specific workshop
/teacher/workshop/{id}
GET
{ 
  "ok": <b>,
  "workshop": {
    "title": <s>, "content": <s>, 
    "end": <d>, "anonymous": <b>
    "teachers": [ 
      { 
        "id": <i>, "firstname": <s>, 
        "lastname": <s> 
      }, .. 
    ],
    "students": [ 
      { 
        "id": <i>, "firstname": <s>, 
        "lastname": <s>, "group": <s>,
        "submissions": [ 
          {
            "id": <i>, "date": <d>, 
            "title": <s>, "reviewsDone": <b>,
            "studentid": <i>, "noReviews": <b>,
            "points": <f>, "maxPoints": <f>
          }, ..
        ] 
      } 
    ],
    "criteria": [
      {
        "id": <i>, "type": <sp>,
        "title": <s>, "content": <s>,
        "weight": <f>
      }, ..
    ]
  }
}
Points & maxPoints only accessible when reviewsDone true and noReviews false
Create new workshop
/teacher/workshop
POST
{ 
  "title": <s>, "content": <s>,
  "end": <d>, "anonymous": <b>,
  "teachers": [ <i>, ..],
  "students": [ <i>, ..],
  "criteria": [ {
    "type": <sp>, "title": <s>,
    "content": <s>, "weight": <f>}, .. ],
  "attachments": [<i>, ..]
}
{ 
  "ok": <b>,
  "id": <i>
}
Teachers & Students array consists of User Ids
Update existing workshop
/teacher/workshop/{id}
PUT
{ 
  "title": <s>, "content": <s>,
  "end": <d>, 
  "teachers": [ <i>, ..],
  "students": [ <i>, ..],
  "criteria": [ {
    "type": <sp>, "title": <s>,
    "content": <s>, "weight": <f>}, .. ],
  "attachments": [<i>, ..]
}
{ 
  "ok": <b>
}
Delete existing workshop
/teacher/workshop/{id}
DELETE
{ 
  "ok": <b>
}
Get Student from Id
/teacher/search/student
GET Query Parameter: ?id=<i>
{ 
  "ok": <b>,
  "id": <i>, "firstname": <s>, "lastname": <s>
}
Get Student Id from Name
/teacher/search/student
GET Query Parameter: ?firstname=<s>&lastname=<s>
{ 
  "ok": <b>,
  "id": <i>
}
Get all Students from a Group
/teacher/search/student
GET Query Parameter: ?group=<s>
{ 
  "ok": <b>,
  "ids": [<i>, ..]
}
Get all Students
/teacher/search/student
GET Query Parameter: ?all=<b>
{ 
  "ok": <b>,
  "students": [
    {
      "firstname": <s>, "lastname": <s>,
      "id": <i>, "group": <s>
    }, ..
  ]
}
All needs to be "true" (?all=true)

Student

Route Method Input Output Notes
Show all workshops
/student/workshops
GET
{ 
  "workshops": [ 
    { "id": <i>, "title": <s>, } , ... 
  ]
}
Retrieve specific workshop
/student/workshop/{id}
GET
{ 
  "ok": <b>,
  "workshop": {
    "title": <s>, "content": <s>, 
    "end": <d>,
    "teachers": [ 
      { 
        "id": <i>, "firstname": <s>, 
        "lastname": <s> 
      }, .. 
    ],
    "students": [ 
      { 
        "id": <i>, "firstname": <s>, 
        "lastname": <s>, "group": <s>
      } 
    ],
    "submissions": [ 
      {
        "id": <i>, "title": <s>, 
        "date": <d>, "locked": <b>,
        "reviewsDone": <b>, "noReviews": <b>
        "points": <f>, "maxPoints": <f>
      }, ..
    ],
    "reviews": [
      {
        "id": <i>, "done": <b>,
        "deadline": <d>, "title": <s>,
        "firstname": <s>, "lastname": <s>
      }
    ]
  }
}
Points & maxPoints only accessible when reviewsDone true and noReviews false
Firstname & Lastname of Reviewer is only accessible in non anonymous workshops
Get given reviews and submissions that need attention
/student/todos
GET
{
  "ok": <b>,
  "reviews": [
    {
      "id": <i>, "done": <b>,
      "deadline": <d>, "title": <s>,
      "firstname": <s>, "lastname": <s>,
      "submission": <i>, "workshopName": <s>
    }, ..
  ],
  "submissions": [
    {
      "id": <i>, "workshopName": <s>
    }
  ]
}
Id property in "submissions" relates to the workshop Id

Submissions & Reviews

Route Method Input Output Notes
Add submission
/submission/{workshop_id}
POST
{
  "title": <s>, "comment": <s>,
  "attachments": [<i>, ..]
}
{
  "ok": <b>,
  "id": <i>
}
Attachments is a list of attachment Ids
Get submission
/submission/{submission_id}
GET Student (Own submission) & Teacher
{
  "ok": <b>,
  "title": <s>, "comment": <s>,
  "attachments": [
    { "id": <i>, "title": <s>}, ..
  ],
  "locked": <b>, "date": <d>,
  "firstname": <s>, "lastname": <s>,
  "reviewsDone": <b>, "noReviews": <b>,
  "points": <f>, "maxPoints": <f>,
  "reviews": [
    {
      "id": <i>, "firstname": <s>,
      "lastname": <s>, "feedback": <s>,
      "points": [
        {
          "id": <i>, "type": <sp>,
          "title": <s>, "content: <s>,
          "points": <f>, "weight": <f>
        }
      ]
    }
  ],
  "missingReviews": [
    {
      "id": <i>, "firstname": <s>,
      "lastname": <s>
    }
  ]
}

Student (Other student submission)
{
  "ok": <b>,
  "title": <s>, "comment": <s>,
  "attachments": [
    { "id": <i>, "title": <s>}, ..
  ],
  "criteria": [
    {
       "id": <i>, "type": <sp>,
       "title": <s>, "content": <s>,
       "weight": <f>
    }, ..
  ]
}

Reviewers first- & lastname are not available for students in anonymous workshops. Missing Reviews is only available for teachers.
Update submission
/submission/{submission_id}
Not implemented yet
PUT
{
  "title": <s>, "comment": <s>,
  "attachments": [<i>, ..]
}
{
  "ok": <b>
}
Attachments is a list of attachment Ids
Add attachment
/submission/upload
POST Form data with key "file" containing the file and key "title" with a backup filename
{
  "ok": <b>,
  "attachment": {
    "id": <i>, "title": <s>
  }
}
Remove attachment
/submission/remove/{att_id}
DELETE
{
  "ok": <b>
}
Download attachment
/submission/download/{att_id}
GET Filestream
Update review
/review/{review_id}
PUT
{
  "feedback": <s>, "points": [
    {
      "id": <i>, "points": <f>
    }
  ]
}
{
  "ok": <b>,
  "id": <i>
}
Points Id is received through Criteria property from GET /submission/{submission_id}
Grading with Points:
"point": 1.0 - 10.0
"grade": 1.0 (A) - 5.0 (F)
"percentage": 0.0 - 100.0
"truefalse": 0.0 False, 1.0 True
Get review
/review/{review_id}
GET
{
  "ok": <b>,
  "id": <i>, "firstname": <s>,
  "lastname": <s>, "notSubmitted": <b>,
  "feedback": <s>, "points": [
    {
      "type": <sp>, "title": <s>,
      "content": <s>, "points": <f>,
      "weight": <f>
    }
  ]
}
Reviewers first- & lastname are not available in anonymous workshops

Creating user accounts

Only possible with admin account (= username admin).

Route Method Input Output Notes
/users/student POST
{"username": <s>, "firstname": <s>,"lastname": <s>,"password": <s>,"group": <s>}
Status Code
/users/teacher POST
{"username": <s>, "firstname": <s>,"lastname": <s>,"password": <s>}
Status Code

📖 Help

  • [Windows] Build shows libssl-1_1-x64.dll not found

    Install OpenSSL add it to the path

    choco install openssl
    
    scoop install openssl
    
  • [Windows] Problems with libmysql.dll (in binary or Diesel CLI)

    Install the C-Connector from here to a directory and it to the path like this:

    setx MYSQLCLIENT_LIB_DIR "<your path>"	
    

    Also put libmysql.dll from the C-Connector to the folder of the Diesel binary in C:\Users\<user>\.cargo\bin if you still encounter problems with the Diesel CLI.

  • [Windows] Problems with connecting to MySQL databases (binary or Diesel CLI)

    For now, Diesel on Windows does not support SSL for MySQL. In order to use it, one must disable SSL on the Server.

    sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
    

    Now add following command

    [mysqld]
    ...
    skip_ssl
    ...
    
  • Migrations with Diesel CLI

    If you want to run the migrations with the CLI (is not needed/recommended) you can run

    diesel setup --database-url "mysql://[email protected]:3306/iprp"
    
    diesel migration run --database-url "mysql://[email protected]:3306/iprp"
    
  • [Windows] Building Rust-Crypto (dependency) fails on MinGW

    Set environment variable CC=gcc

    Source