Skip to content

DanielL29/projeto20-repoprovas-back

Repository files navigation

JavaScriptLogo

RepoProvas

20th Project of Driven Education
An API to manage and storage yout tests

Built With

Project Guide

Features

  • Auth (sign-in/sign-up)
  • Create test
  • Get tests by disciplines
  • Get tests by teachers

API Reference

TL;DR
POST /sign-up

Body:

{
    "email": string,
    "password": string
}
POST /sign-in

Body:

{
    "email": string,
    "password": string
}

Response:

{
   "token": string
}
POST /tests

Headers:

{
  "Authorization": "Bearer {token}"
}

Body:

{
    "name": string,
    "pdfUrl": string,
    "categoryId": number,
    "teacherDisciplineId": number
}
GET /tests/discipline

Headers:

{
  "Authorization": "Bearer {token}"
}

Response:

[
  {
     "id": number,
     "number": number,
     "disciplines": [
        {
           "id": number,
           "name": string,
           "categories": [
              {
                 "id": number,
                 "name": string,
                 "tests": [
                    {
                      "id": number,
                      "name": string,
                      "pdfUrl": string,
                      "categoryId": number,
                      "teacherDiscipline": {
                        "discipline": {
                          "id": number
                        },
                        "teacher": {
                          "name": string
                        }
                      }
                    },
                    ...
                 ]
              },
              ...
           ]
        },
        ...
     ]
  },
  ...
]
GET /tests/teacher

Headers:

{
  "Authorization": "Bearer {token}"
}

Response:

[
  {
     "id": number,
     "number": number,
           "categories": [
              {
                 "id": number,
                 "name": string,
                 "tests": [
                    {
                      "id": number,
                      "name": string,
                      "pdfUrl": string,
                      "categoryId": number,
                      "teacherDiscipline": {
                        "discipline": {
                          "name": string
                        },
                        "teacher": {
                          "id": number
                        }
                      }
                    },
                    ...
                 ]
              },
              ...
           ]
    },
    ...
]

Sign-up

POST /sign-up

Request:

Body Type Description
email string Required. user email
password string Required. user password

Password min length 6


Sign-in

POST /sign-in

Request:

Body Type Description
email string Required. user email
password string Required. user password

Password min length 6


Response:

{
   "token": string
}

Create test

POST /tests

Request:

Headers Type Description
Authorization string Required. give token
Body Type Description
name string Required. test name
pdfUrl string Required. test pdfUrl
categoryId number Required. categoryId of test belong
teacherDisciplineId number Required. teacherDisciplineId of test belong

Get tests by discipline

GET /tests/discipline

Request:

Headers Type Description
Authorization string Required. give token

Response:

[
  {
     "id": number,
     "number": number,
     "disciplines": [
        {
           "id": number,
           "name": string,
           "categories": [
              {
                 "id": number,
                 "name": string,
                 "tests": [
                    {
                      "id": number,
                      "name": string,
                      "pdfUrl": string,
                      "categoryId": number,
                      "teacherDiscipline": {
                        "discipline": {
                          "id": number
                        },
                        "teacher": {
                          "name": string
                        }
                      }
                    },
                    ...
                 ]
              },
              ...
           ]
        },
        ...
     ]
  },
  ...
]

Get tests by teacher

GET /tests/teacher

Request:

Headers Type Description
Authorization string Required. give token

Response:

[
  {
     "id": number,
     "number": number,
           "categories": [
              {
                 "id": number,
                 "name": string,
                 "tests": [
                    {
                      "id": number,
                      "name": string,
                      "pdfUrl": string,
                      "categoryId": number,
                      "teacherDiscipline": {
                        "discipline": {
                          "name": string
                        },
                        "teacher": {
                          "id": number
                        }
                      }
                    },
                    ...
                 ]
              },
              ...
           ]
    },
    ...
]

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

DATABASE_URL = postgres://YOUR-USER-NAME:YOUR-PASSWORD@Hostname:5432/DatabaseName

PORT = number

SECRET_KEY = any string

Run Locally

Clone the project

  git clone https://github.com/DanielL29/projeto20-repoprovas

Go to the project directory

  cd projeto20-repoprovas/

Install dependencies

  npm install

Create database

  npx prisma migrate dev
  npx prisma db seed

Start the server

  npm run dev

Lessons Learned

  • API Architecture
  • TypeScript interfaces
  • TypeScript types
  • Classes
  • Constructor
  • Object Literals
  • Manual tests
  • Integration tests

Acknowledgements

Authors

  • Daniel Lucas Ederli

About

Projeto 20° da Driven Education - RepoProvas (Back)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages