Skip to content

Latest commit

 

History

History
586 lines (514 loc) · 13.8 KB

API.md

File metadata and controls

586 lines (514 loc) · 13.8 KB

Overview

This document covers the REST API routes available in the backend, split by the resource being interacted with.

Users

/users POST

Description

Creates a new user in the database.

Path Params

None

Query Params

None

Body Params

Name Type Description
userId string The user's id generated by Auth0 on login.

Responses

201
User created successfully.

400
Missing userId.

409
User already exists.

/users/:userId/role GET

Description

Gets the role of a user.

Path Params

Name Type Description
userId string The user id of a user to get the role of.

Query Params

None

Body Params

None

Responses

200
role: number
Role retrieved successfully

404 User not found.

Courses

/courses?limit=<limit>&offset=<offset> GET

Description

Gets all courses from the database.

Path Params

None

Query Params

Name Type Description
limit number Return only this many results. 0 < limit <= 1000. Default is 100.
offset number Skip this many results before returning. 0 <= offset. Default is 0

Responses

200
List of all courses retrieved.

[
  {
    "courseCode": string,
    "courseName": string,
    "courseDescription": string,
    "university": string
  }
]

/courses/:courseCode GET

Description

Gets the information for a specific course.

Path Params

Name Type Description
courseCode string Course code to get info for.

Query Params

None

Body Params

None

Responses

200
Object with the course's information.

{
    "courseCode": string,
    "courseName": string,
    "courseDescription": string,
    "university": string
}

404
Course not found.

/courses/:courseCode/exams GET

Description

Returns all exams for a course.

Path Params

Name Type Description
courseCode string Course code to get exams for.

Query Params

None

Body Params

None

Responses

200
List the exams for the course.

[
  {
    examId: number,
    examYear: number,
    examSemester: number,
    examType: string
  }
]

404
Course not found.

/courses/:courseCode/star PATCH

Description

Gives a star rating to a course.

Path Params

Name Type Description
courseCode string Course code to rate.

Query Params

None

Body Params

Name Type Description
starRating number The star rating to give the course.
userId string The user id of the user giving the rating.

Responses

200 Course rated successfully.

400 Missing star or userId, or star rating is not between 0 and 5.

404 Course not found, or user not found.

/courses POST

Description

Creates a new course in the database.

Path Params

None

Query Params

None

Body Params

Name Type Description
courseCode string The course code.
courseName string The course name.
courseDescription string The course description.
university string The university the course is from.

Responses

201
Course created successfully.

400
Missing courseCode, courseName, courseDescription, university, or userId.

403
User does not have permission to create a course.

409
Course already exists.

Exams

/exams/:examId GET

Description

Gets the information for a specific exam.

Path Params

Name Type Description
examId number The exam id

Query Params

None

Body Params

None

Responses

200
Object with the exam's information.

{
  examId: number,
  examYear: number,
  examSemester: number,
  examType: string
}

404
Exam not found.

/exams/:examId/questions GET

Description

Gets the questions for an exam.

Path Params

Name Type Description
examId number The exam id

Query Params

None

Body Params

None

Responses

200
List of questions for the exam.

[
  {
    questionId: number,
    questionText: string,
    questionType: string,
    questionPNG: string
  }
]

404
Exam not found.

/exams POST

Description

Creates a new exam in the database.

Path Params

None

Query Params

None

Body Params

Name Type Description
examYear number The year the exam took place.
examSemester number The semester the exam took place.
examType string The type of exam.
courseCode string The course code of the course the exam is for.
userId string The user id of the user creating the exam.

Responses

201
{ examId: number }
Exam created successfully.

400
Missing examYear, examSemester, examType, courseCode, or userId.

403
User does not have permission to create an exam.

404
Course not found.

Questions

/questions/:questionId GET

Description

Gets the information for a specific question.

Path Params

Name Type Description
questionId number The question id.

Query Params

None

Body Params

None

Responses

200
Object with the question's information.

{
  questionId: nubmer,
  questionText: string,
  questionType: string,
  questionPNG: string
}

404
Question not found.

/questions/:questionId/comments?userId=<userId> GET

Description

Gets the comments for a question.

Path Params

Name Type Description
questionId number The question id.

Query Params

Name Type Description
userId string The user id to check upvote and downvote status for.

Responses

200
List of comments for the question.

[
  {
    commentId: number,
    parentCommentId: number,
    commentText: string,
    commentPNG: string,
    isCorrect: boolean,
    isDeleted: boolean,
    upvotes: number,
    downvotes: number,
    createdAt: timestamp,
    updatedAt: timestamp,
    upvoted: boolean,
    downvoted: boolean
  }
]

400
Missing userId.

404
Question not found, or user not found.

/questions POST

Description

Adds a new question to the database.

Path Params

None

Query Params

None

Body Params

The body for this request is multi-part form data.

Name Type Description
questionPNG binary The question's picture.
questionText string The question's text.
questionType string The type of question i.e. multiple choice.
examId number The course code of the course.

Responses

201
{ questionId: number } Question created successfully.

400
Missing questionType, or examId.

404
Exam not found.

/questions/:questionId/edit PATCH

Description

Edits a question.

Path Params

Name Type Description
questionId number The question's id.

Query Params

None

Body Params

The body for this request is multi-part form data.

Name Type Description
questionPNG binary The question's picture.
questionText string The question's text.
questionType string The type of question i.e. multiple choice.
examId number The course code of the course.

Responses

200
Question edited successfully.

400 No changes made.

404 Question not found.

Comments

/comments/:commentId GET

Description

Gets the information for a specific comment.

Path Params

Name Type Description
commentId number The comment id.

Query Params

None

Body Params

None

Responses

200
Object with the comment's information.

{
  commentId: number,
  parentCommentId: number,
  commentText: string,
  commentPNG: string,
  isCorrect: boolean,
  isDeleted: boolean,
  upvotes: number,
  downvotes: number,
  createdAt: timestamp,
  updatedAt: timestamp
}

404 Comment not found.

/comments/ POST

Description

Adds a new comment to the database.

Path Params

Name Type Description
commentId number The comment's id.

Query Params

None

Body Params

The body for this request is multi-part form data.

Name Type Description
questionId string The question id the comment belongs to.
parentCommentId number The parent comment id, if needed.
commentPNG binary The comment's picture.
commentText string The comment's text.
userId string The user id of the user writing the comment.

Responses

201
{ commentId: number }
Comment created successfully.

400
Missing questionId, commentText, or userId.

404
Question not found, or parent comment not found.

/comments/:commentId/edit PUT

Description

Edits a comment.

Path Params

Name Type Description
commentId number The comment's id.

Query Params

None

Body Params

The body for this request is multi-part form data.

Name Type Description
commentPNG binary The comment's picture.
commentText string The comment's text.
userId string The user id of the user writing the comment.

Responses

200
Comment edited successfully.

400
No changes made, or no commentId or userId.

401
User does not have permission to edit the comment.

404
Comment not found.

/comments/:commentId/upvote PATCH

Description

Upvotes a comment.

Path Params

Name Type Description
commentId number The comment's id.

Query Params

None

Body Params

Name Type Description
userId string The user id of the user upvoting the comment.

Responses

200
Comment upvoted successfully.

400
Missing userId.

404
Comment not found, or user not found.

/comments/:commentId/downvote PATCH

Description

Downvotes a comment.

Path Params

Name Type Description
commentId number The comment's id.

Query Params

None

Body Params

Name Type Description
userId string The user id of the user downvoting the comment.

Responses

200
Comment downvoted successfully.

400
Missing userId.

404
Comment not found, or user not found.

/comments/:commentId/correct PATCH

Description

Marks a comment as correct.

Path Params

Name Type Description
commentId number The comment's id.

Query Params

None

Body Params

None

Responses

200
Comment marked as correct successfully.

404
Comment not found.

/comments/:commentId/incorrect PATCH

Description

Marks a comment as incorrect.

Path Params

Name Type Description
commentId number The comment's id.

Query Params

None

Body Params

None

Responses

200
Comment marked as incorrect successfully.

404
Comment not found.

/comments/:commentId/delete PATCH

Description

Deletes a comment.

Path Params

Name Type Description
commentId number The comment's id.

Query Params

None

Body Params

Name Type Description
userId string The user id of the user deleting the comment.

Responses

200
Comment deleted successfully.

401
User does not have permission to delete the comment.

404
Comment not found.