-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,7 @@ | |
|
||
## Project brief | ||
|
||
To build a REST API that delivers FAC19 icebreakers(?), inspired by the morning check-ins and afternoon checkouts. We thought it would be a great idea to buld something on this. | ||
|
||
## Running tests | ||
No tests as of Thursday 5pm | ||
|
||
--- | ||
To build a REST API that delivers FAC19 icebreakers(?), inspired by the morning check-ins and afternoon checkouts. We thought it would be a great idea to build something on this. | ||
|
||
## What our API does | ||
|
||
|
@@ -20,34 +15,94 @@ API allows users to access a database of icebreaker questions and answers. Users | |
--- | ||
|
||
## How to set up the project | ||
### Instructions to install Node and run the server | ||
1. Clone this repo | ||
2. Type `npm install` in the terminal to install all the dependencies associated with this project | ||
3. Once you have installed node, enter `npm run dev` to kickstart the server | ||
|
||
### Instructions to set up database | ||
- Start Posgres by typingon your terminal: `psql` | ||
|
||
- Start Posgres by typing on your terminal: `psql` | ||
- `CREATE USER myuser WITH PASSWORD 'mypassword'` | ||
- then `ALTER USER myuser WITH SUPERUSER` | ||
- then `CREATE DATABASE mydatabase WITH OWNER myuser` | ||
- then connext to the database you created: `\c mydatabase` | ||
- and finally: `\i database/init.sql` | ||
- then connect to the database you created: `\c mydatabase` | ||
- and finally initialise the database: `\i database/init.sql` | ||
- Create a `.env` file in the root folder to save your credential details as follow: | ||
``` | ||
PGDATABASE=mydatabase | ||
PGUSER=myuser | ||
PGPASSWORD=mypassword | ||
JWT_SECRET=a_string | ||
``` | ||
|
||
--- | ||
|
||
## Running tests | ||
No tests as of Thursday 5pm | ||
|
||
### Instructions to install Node and run the server | ||
1. Type `npm install` in the terminal to install all the dependencies associated with this project | ||
2. Once you have installed node, enter `npm run dev` to kickstart the server | ||
--- | ||
|
||
## API functions | ||
- List all questions in the database and the answers | ||
- Allows user to sign up/login to add questions and answers | ||
- Also gives the option of deleting and editing questions/answers | ||
- Can specifically pull all answers associated with a question | ||
- Can specifically pull all answers associated with a question from a specific user | ||
|
||
### Users | ||
- Method `POST` `/users`: allows user to sign up | ||
``` | ||
{ | ||
"username":"your_username", | ||
"password":"your_password" | ||
} | ||
``` | ||
- Method `POST` `/login`: allows user to login and creates token | ||
``` | ||
{ | ||
"username":"your_username", | ||
"password":"your_password" | ||
} | ||
``` | ||
- Method `GET` `/users`: lists all users | ||
|
||
### Questions | ||
- Method `GET` `/questions`: lists all questions in the database | ||
- Method `GET` `/question/:id`: gets specific question | ||
- Method `POST` `/questions`: allows logged in users to create new question | ||
``` | ||
{ | ||
"question":"your_new_question" | ||
} | ||
``` | ||
- Method `PUT` `/questions/:id`: allows logged in users to edit their questions | ||
``` | ||
{ | ||
"question":"your_edited_question" | ||
} | ||
- Method `DEL` `/questions/:id`: allows logged in users to delete their questions | ||
### Answers | ||
- Method `GET` `/answers`: lists all answers, with question ID and users ID | ||
- Method `GET` `/answers/:userId`: lists user's answers | ||
- Method `POST` `/answers/:id`: allows logged in users to add answers (id referes to the question id) | ||
``` | ||
{ | ||
"answer": "your_new_answer" | ||
} | ||
``` | ||
- Method `PUT` `/answers/:id`: allows logged in users to edit their answers | ||
``` | ||
{ | ||
"answer": "your_edited_answer" | ||
} | ||
``` | ||
- Method `DEL` `/answers/:id`: allows logged in users to delete their answers | ||
--- | ||
## Acceptance Criteria | ||
- [x] An Express server that only returns JSON | ||
- [x] A Postgres database to store the data | ||
- [x] Endpoints for creating, reading, updating & deleting resources | ||
- [ ] Token-based authentication so only the owner of a resource can change it | ||
- [x] Token-based authentication so only the owner of a resource can change it | ||
- [x] Correct headers and response metadata | ||
- [ ] Error-handling to make it easy to use the API to build something | ||
- [ ] Tests for server routes and database access | ||
|
@@ -58,18 +113,20 @@ API allows users to access a database of icebreaker questions and answers. Users | |
## What we learned | ||
- 418 http error code | ||
- 418 http error code: 'I'm a teapot' | ||
- Arrays are still JSON | ||
- Utilising the unique keyword in our database schema to prevent multiple users with the same username | ||
- Utilising the UNIQUE keyword in our database schema to prevent multiple users with the same username | ||
--- | ||
## What we struggled with | ||
- Uderstanding the concept of a REST API (project without a client side) | ||
- Understanding the concept of a REST API (project without a client side) | ||
- Deploy database to Heroku | ||
- Time to write tests | ||
## Contributors | ||
lizzy-j <lizzyhj@hotmail.com> | ||
Giovanna <[email protected]> | ||
CampbellDocherty <campbellsofitsidocherty@gmail.com> | ||
vatskan <vatskan@gmail.com> | ||
- [Lizzy-j](https://github.com/Lizzy-j) | ||
- [Giovanna](https://github.com/glrta) | ||
- [CampbellDocherty](https://github.com/CampbellDocherty) | ||
- [Vatskan](https://github.com/VatsKan) |