A RESTful API for Study IO, a learning application.
Install the Study IO API dependencies with npm
cd api
npm installDue to security concerns, the Postgres connection string is stored in a config.js file that is not provided. Please make a config.js file using the config.example.js file provided.
To start
npm startStudy IO requires Postgres. To locally load mock data:
Change the filepaths in schema.sql to where your locally stored .csv files are
In your terminal, run psql -h localhost -f schema.sqlQuick Start Guide For PostgreSQL
Mock Data
GET /topicsResponse:
[
{
"id": 1,
"name": "math",
"url": "https://via.placeholder.com/200x200"
},
{
"id": 2,
"name": "science",
"url": "https://via.placeholder.com/200x200"
},
...
] GET /roomsResponse:
[
{
"id": "hJ_Q0GG000",
"name": "the danger zone",
"topic_id": 1,
"created_at": "2021-01-13T12:05:06.000Z",
"thumbnail": "https://via.placeholder.com/200x200",
"max_users": 20,
"is_private": false,
"is_archived": true,
"admin_id": 1
"invite_key": null
},
...
] GET /room/:room_idQuery parameters:
| Parameter | Type | Description |
|---|---|---|
room_id |
string |
Required. Id of room to get details for |
Response:
{
"id": "hJ_Q0GG000",
"name": "the danger zone",
"topic_id": 1,
"created_at": "2021-01-13T12:05:06.000Z",
"thumbnail": "https://via.placeholder.com/200x200",
"max_users": 20,
"is_private": false,
"is_archived": true,
"admin_id": 1,
"invite_key": null,
"user_ids": [
1,
101,
201,
50
]
} GET /topic/:topic_id/roomsQuery parameters:
| Parameter | Type | Description |
|---|---|---|
topic_id |
integer |
Required. Id of topic to get rooms for |
Response:
[
{
"id": 1,
"name": "the danger zone",
"topic_id": 1,
"created_at": "2021-01-13T12:05:06.000Z",
"thumbnail": "https://via.placeholder.com/200x200",
"max_users": 20,
"is_private": false,
"is_archived": true,
"admin_id": 1
"invite_key": null
},
...
] POST /rooms/searchRequest body:
| Parameter | Type | Description |
|---|---|---|
search_value |
string |
Required. Text to search for rooms |
Response:
[
{
"id": "hJ_Q0GG013",
"name": "room4",
"topic_id": 4,
"created_at": "2021-01-26T04:05:06.000Z",
"thumbnail": "https://via.placeholder.com/200x200",
"max_users": 20,
"is_private": false,
"is_archived": false,
"admin_id": 5,
"invite_key": null
},
{
"id": "hJ_Q0GG011",
"name": "room2",
"topic_id": 2,
"created_at": "2021-01-24T04:05:06.000Z",
"thumbnail": "https://via.placeholder.com/200x200",
"max_users": 20,
"is_private": true,
"is_archived": false,
"admin_id": 3,
"invite_key": null
},
...
] POST /:topic_id/rooms/createRequest body:
| Parameter | Type | Description |
|---|---|---|
name |
string |
Required. Unique. Name of room |
thumbnail |
string |
Required. URL of thumbnail image |
max_users |
integer |
Required. Max number of users wanted |
is_private |
boolean |
Required. Mark room as private |
admin_id |
integer |
Required. Id of user making the room |
Response:
{
"room_id": "IYdnM6YiWJ"
} POST /addUserToRoomRequest body:
| Parameter | Type | Description |
|---|---|---|
user_id |
integer |
Required. Id of user to add |
room_id |
string |
Required. Id of room to add user into |
PUT /toggle-archiveRequest body:
| Parameter | Type | Description |
|---|---|---|
room_id |
string |
Required. Id of the room to archive/reactivate |
PUT /rooms/new-invite-keyRequest body:
| Parameter | Type | Description |
|---|---|---|
room_id |
string |
Required. Id of the room to generate an invite key for |
invite_key |
string |
Required. Invite key to room |
POST /rooms/check-invite-keyRequest body:
| Parameter | Type | Description |
|---|---|---|
room_id |
string |
Required. Id of the room to generate an invite key for |
invite_key |
string |
Required. Invite key to room |
Responses:
true if invite key matches
false if not
GET /rooms/:room_id/messagesQuery parameters:
| Parameter | Type | Description |
|---|---|---|
room_id |
string |
Required. Id of room to get messages for |
Response:
[
{
"id": 1,
"room_id": "hJ_Q0GG000",
"user_id": 1,
"body": "testing",
"created_at": "2021-12-14T20:02:41.634Z",
"first_name": "user1",
"last_name": "last name"
},
{
"id": 101,
"room_id": "hJ_Q0GG000",
"user_id": 101,
"body": "what?",
"created_at": "2021-12-14T20:02:41.634Z",
"first_name": "user101",
"last_name": "last name"
},
...
] POST /rooms/:room_id/messagesQuery parameters:
| Parameter | Type | Description |
|---|---|---|
room_id |
string |
Required. Id of room |
Request body:
| Parameter | Type | Description |
|---|---|---|
user_id |
integer |
Required. Id of user posting |
body |
string |
Required. Content of message |
GET /rooms/:room_id/usersQuery parameters:
| Parameter | Type | Description |
|---|---|---|
room_id |
string |
Required. Id of room to get users for |
Response:
[
{
"id": 1,
"first_name": "user1",
"last_name": "last name",
"email": "email1@email.email",
"avatar": "https://via.placeholder.com/50x50",
"created_at": "2021-01-13T12:05:06.000Z"
},
{
"id": 3,
"first_name": "user3",
"last_name": "last name",
"email": "email3@email.email",
"avatar": "https://via.placeholder.com/50x50",
"created_at": "2021-01-13T12:05:06.000Z"
},
...
] GET /user/:user_id/roomsQuery parameters:
| Parameter | Type | Description |
|---|---|---|
user_id |
id |
Required. Id of user to get rooms for |
POST /users/createRequest body:
| Parameter | Type | Description |
|---|---|---|
first_name |
string |
Required. first name of user |
last_name |
string |
Required. last name of user |
email |
string |
Required. email of user |
avatar |
string |
url of user's profile photo |
password |
string |
user's password |
googleId |
string |
user's googleId |
Note: needs a password OR googleId to create a user
GET /rooms/:room_id/goalsQuery parameters:
| Parameter | Type | Description |
|---|---|---|
room_id |
string |
Required. Id of the room to retrive goals from |
Response:
[
{
"id": 1,
"name": "goal1",
"created_at": "2021-04-13T04:05:06.000Z",
"user_id": 1,
"room_id": "hJ_Q0GG000",
"user_ids": [
1,
199
]
},
{
"id": 101,
"name": "goal101",
"created_at": "2021-07-22T04:05:06.000Z",
"user_id": 101,
"room_id": "hJ_Q0GG000",
"user_ids": [
101
]
},
...
] GET /goals/:goal_idQuery parameters:
| Parameter | Type | Description |
|---|---|---|
goal_id |
integer |
Required. Id of the goal to retrieve users from |
Response:
[
{
"id": 1,
"user_id": 1,
"goal_id": 1,
"created_at": "2021-12-11T18:53:40.272Z"
},
{
"id": 199,
"user_id": 199,
"goal_id": 1,
"created_at": "2021-12-11T18:53:40.272Z"
},
...
] POST /rooms/:room_id/goalsQuery parameters:
| Parameter | Type | Description |
|---|---|---|
room_id |
string |
Required. Id of room the goal belongs to |
Request body:
| Parameter | Type | Description |
|---|---|---|
name |
string |
Required. Name of the goal |
user_id |
integer |
Required. Id of user who created the goal |
goal_date |
date |
End date to reach goal (optional) |
Response:
{
"goal_id": 1
} PUT /goals/:goal_idQuery parameters:
| Parameter | Type | Description |
|---|---|---|
goal_id |
string |
Required. Id of the goal |
Request body:
| Parameter | Type | Description |
|---|---|---|
name |
string |
Required. Name of the goal |
goal_date |
date |
Date of the goal (optional) |
DELETE /goals/:goal_idQuery parameters:
| Parameter | Type | Description |
|---|---|---|
goal_id |
integer |
Required. Id of the goal to delete |
POST /goals/add-userRequest body:
| Parameter | Type | Description |
|---|---|---|
user_id |
integer |
Required. Id of the user to add to a goal |
goal_id |
integer |
Required. Id of goal receiving a user |
GET /rooms/:room_id/eventsQuery parameters:
| Parameter | Type | Description |
|---|---|---|
room_id |
string |
Required. Id of the room to retrieve events from |
Response:
[
{
"id": 1,
"name": "study session",
"user_id": 1,
"room_id": "hJ_Q0GG000",
"created_at": "2021-03-13T04:05:06.000Z",
"event_date": "2021-03-14T00:00:00.000Z",
"event_time": "11:00:00"
},
...
] POST /rooms/create_eventRequest body:
| Parameter | Type | Description |
|---|---|---|
name |
string |
Required. Name of the event |
user_id |
integer |
Required. Id of user who created the event |
room_id |
string |
Required. Id of the room where the event was created |
event_date |
date |
Required. Date of the event |
event_time |
time |
Required. Time of the event |
Response:
{
"event_id": 101
} PUT /events/:event_idQuery parameters:
| Parameter | Type | Description |
|---|---|---|
event_id |
integer |
Required. Id of the event |
Request body:
| Parameter | Type | Description |
|---|---|---|
name |
string |
Required. Name of the event |
event_date |
date |
Required. Date of the event |
event_time |
time |
Required. Time of the event |
DELETE /events/:event_idQuery parameters:
| Parameter | Type | Description |
|---|---|---|
event_id |
integer |
Required. Id of the event to delete |
GET /rooms/:room_id/filesQuery parameters:
| Parameter | Type | Description |
|---|---|---|
room_id |
string |
Required. Id of the room to retrieve file URLs from |
Response:
[
{
"id": 1,
"url": "https://via.placeholder.com/50x50",
"name": "placeholder1",
"room_id": "hJ_Q0GG000",
"user_id": 1,
"created_at": "2021-12-14T20:02:41.665Z"
}
...
] POST /rooms/:room_id/filesQuery parameters:
| Parameter | Type | Description |
|---|---|---|
room_id |
string |
Required. Id of the room to add file into |
Request Body:
| Parameter | Type | Description |
|---|---|---|
url |
string |
Required. Url of the file from file hosting storage |
name |
string |
Required. Name of the file |
user_id |
string |
Required. Id of the user who is posting the file |
Response:
{
"file_id": 99
} DELETE /files/:file_id/deleteQuery parameters:
| Parameter | Type | Description |
|---|---|---|
file_id |
integer |
Required. Id of the file to delete |
POST /users/authRequest Body:
| Parameter | Type | Description |
|---|---|---|
email |
string |
Required. Email of the user |
password |
string |
Password for the user |
googleId |
string |
Google ID provided by google authentication |
Note: Password OR Google ID can be provided
Responses: On successful authenthication:
{
"id": 307,
"first_name": "bobby",
"last_name": "hill",
"email": "anotherEmail@email.com",
"avatar": "https://via.placeholder.com/50x50",
"created_at": "2021-12-13T20:04:55.146Z"
}On unsuccessful authentication:
false