An online system that allows students and tutors to communicate through files.
- Tech stack used: Nodejs, Nestjs, Postgres, Typescript
# Method to run api on local
- install node version 18.17.1
- You can install specific node version using nvm
- run npm i in root directory
- setup your .env profile in the root directory, sample env provided in the root directory.
- Add this file in your root directory
- npm run start
- NOTE: No need of SQL file to create tables as code automatically creates them in the DB.
- If setting up on local then set use base url as
localhost:3000
.
- This api has been hosted on render.
- Below is the Api endpoint.
# url
https://class-files-api.onrender.com
- Api Details are provided below.
- Authentication endpoint is public.
- Since requirement was to mock authentication signup and login endpoints are there.
- There can be 2 types of users:
student
andtutor
- While signing up
userType
has to mentioned in body(more details below) - JWT authenticatoin has been implemented.
- Login api returns the token which has to be passed in protected apis.
- Guard implementation has been done for roles to restrict apis on roles level.
- For this service files are being uploaded locally in project directory.
# user
id: number;
username: string;
password: string;
userType: string;
createdAt: Date;
updatedAt: Date;
# classroom
id: number;
name: string;
tutorId: number;
isArchived: boolean;
createdAt: Date;
updatedAt: Date;
# classroom_student
id: number;
studentId: number;
classroomId: number;
isArchived: boolean;
createdAt: Date;
updatedAt: Date;
# file
id: number;
name: string;
description: string;
classroomId: number;
uploadedBy: number;
updatedBy: number;
fileType: string;
fileDetails: string;
isArchived: boolean;
createdAt: Date;
updatedAt: Date;
-
Signup (method POST)
- endpoint ->
https://class-files-api.onrender.com/auth/signup
curl --location 'https://class-files-api.onrender.com/auth/signup' \--header 'Content-Type: application/json' \--data '{ "username":"muneeb", "password":"password", "userType":"tutor"}'
- endpoint ->
-
Login (method POST)
- endpoint ->
https://class-files-api.onrender.com/auth/login
curl --location 'https://class-files-api.onrender.com/auth/login' \--header 'Content-Type: application/json' \--data '{ "username":"muneeb", "password":"password"}'
- endpoint ->
-
Add classroom (method POST)
- endpoint ->
https://class-files-api.onrender.com/class-files/classroom
curl --location 'https://class-files-api.onrender.com/class-files/classroom' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im11bmVlYiIsInVzZXJJZCI6MiwidXNlclR5cGUiOiJ0dXRvciIsImlhdCI6MTY5NDcyMjM1MSwiZXhwIjoxNjk0NzQwMzUxfQ.TDT8JyGaetrLbym1lLsKTc58oI8z_Qh2iKe7NuRWQhA' \--data '{ "name":"classroom1"}'
- endpoint ->
-
Update classroom (method PATCH)
- endpoint ->
https://class-files-api.onrender.com/class-files/classroom/:id
curl --location --request PATCH 'https://class-files-api.onrender.com/class-files/classroom/1' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im11bmVlYiIsInVzZXJJZCI6MSwidXNlclR5cGUiOiJ0dXRvciIsImlhdCI6MTY5NDYxNjMwOCwiZXhwIjoxNjk0NjM0MzA4fQ.HTX4o8pnFr2_VUxJ8ef2QiCO96R501xQy8y1PWGnQP0' \--data '{ "name":"classroom1"}'
- endpoint ->
-
Delete classroom (method Delete)
- endpoint ->
https://class-files-api.onrender.com/class-files/classroom/:id
curl --location --request DELETE 'https://class-files-api.onrender.com/class-files/classroom/1' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im11bmVlYiBzdHVkZW50IiwidXNlcklkIjozLCJ1c2VyVHlwZSI6InN0dWRlbnQiLCJpYXQiOjE2OTQ2MzExNTksImV4cCI6MTY5NDY0OTE1OX0.874W8GkX2JDIcrcw3J6kOun6yIPcBLKsocv6GUye3N8'
- endpoint ->
-
Add student to classroom (method Post)
- endpoint ->
https://class-files-api.onrender.com/class-files/addStudent
curl --location 'https://class-files-api.onrender.com/class-files/addStudent' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im11bmVlYiIsInVzZXJJZCI6MSwidXNlclR5cGUiOiJ0dXRvciIsImlhdCI6MTY5NDYxNjMwOCwiZXhwIjoxNjk0NjM0MzA4fQ.HTX4o8pnFr2_VUxJ8ef2QiCO96R501xQy8y1PWGnQP0' \--data '{ "classroomId":1, "studentId":1}'
- endpoint ->
-
Get class feed (method GET)
- endpoint ->
https://class-files-api.onrender.com/class-files/class-feed
curl --location 'https://class-files-api.onrender.com/class-files/class-feed' \--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im11bmVlYiBzdHVkZW50IiwidXNlcklkIjozLCJ1c2VyVHlwZSI6InN0dWRlbnQiLCJpYXQiOjE2OTQ2MzExNTksImV4cCI6MTY5NDY0OTE1OX0.874W8GkX2JDIcrcw3J6kOun6yIPcBLKsocv6GUye3N8'
- endpoint ->
-
Get files feed (method GET)
- endpoint ->
https://class-files-api.onrender.com/class-files/files/:classroomId
curl --location 'https://class-files-api.onrender.com/class-files/files/1' \--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im11bmVlYiIsInVzZXJJZCI6MiwidXNlclR5cGUiOiJ0dXRvciIsImlhdCI6MTY5NDcyMjM1MSwiZXhwIjoxNjk0NzQwMzUxfQ.TDT8JyGaetrLbym1lLsKTc58oI8z_Qh2iKe7NuRWQhA'
- endpoint ->
-
Add file (method POST)
- endpoint ->
https://class-files-api.onrender.com/class-files/file
curl --location 'https://class-files-api.onrender.com/class-files/file' \--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im11bmVlYiIsInVzZXJJZCI6MiwidXNlclR5cGUiOiJ0dXRvciIsImlhdCI6MTY5NDcyMjM1MSwiZXhwIjoxNjk0NzQwMzUxfQ.TDT8JyGaetrLbym1lLsKTc58oI8z_Qh2iKe7NuRWQhA' \--form 'file=@"/Users/muneebadil/Downloads/file_example_MP3_700KB.mp3"' \--form 'name="myMusic"' \--form 'description="description"' \--form 'classroomId="1"' \--form 'fileType="audio"' \--form 'fileDetails="file detail"'
- NOTE: Attach the file in postman again
- endpoint ->
-
Rename file (method PATCH)
- endpoint ->
https://class-files-api.onrender.com/class-files/file/:id
curl --location --request PATCH 'https://class-files-api.onrender.com/class-files/file/2' \--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im11bmVlYiIsInVzZXJJZCI6MSwidXNlclR5cGUiOiJ0dXRvciIsImlhdCI6MTY5NDYyNzQwMywiZXhwIjoxNjk0NjQ1NDAzfQ.V4rO91fWQCCF0W2UpC23y9KQBApTtE2xdbaIXGr_RY8' \--header 'Content-Type: application/json' \--data '{ "newName":"mynewfile"}'
- endpoint ->
-
Delete classroom (method Delete)
- endpoint ->
https://class-files-api.onrender.com/class-files/file/:id
curl --location --request DELETE 'https://class-files-api.onrender.com/class-files/file/2' \--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im11bmVlYiIsInVzZXJJZCI6MSwidXNlclR5cGUiOiJ0dXRvciIsImlhdCI6MTY5NDYyNzQwMywiZXhwIjoxNjk0NjQ1NDAzfQ.V4rO91fWQCCF0W2UpC23y9KQBApTtE2xdbaIXGr_RY8' \--header 'Content-Type: application/json'
- endpoint ->