# Week7-BGJK ![image alt](https://media.giphy.com/media/Uod3eEQvIMHYHl88U2/giphy.gif) --- ## Project brief (G) Build a REST API that delivers FAC19 icebreakers, inspired by the morning check-ins and afternoon checkouts. ![image alt](https://media0.giphy.com/media/XoWR5RTdFBjID5YFq5/giphy.gif) --- ## Workflow (G) ### Day 1 1. Conceptualising the API in Miro 2. Setting up the database 3. Setting up the routes/server --- ### Day 2 1. Finished questions and answers endpoints 2. Authenticating the user's details (mob programme together as a group) 3. Deploying to Heroku --- ## Structuring our database (L) ### Creating the schema: - Made up of three tables ```javascript= CREATE TABLE users( id SERIAL PRIMARY KEY, username VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) ); CREATE TABLE questions( id SERIAL PRIMARY KEY, user_id INTEGER REFERENCES users(id), question TEXT NOT NULL ); CREATE TABLE answers( id SERIAL PRIMARY KEY, user_id INTEGER REFERENCES users(id), question_id INTEGER REFERENCES questions(id), answers TEXT NOT NULL ); ``` --- # Building our API (L) --- ### What does our API do? - Allows users without an account to view a database of icebreakers - View the answers associated with each icebreaker question - Authenticated users can also: - post answers - update answers - delete their answers --- ### API and its endpoints - ```/users``` : lists all users ```javascript= { id: 1, username: "Gio" }, { id: 2, username: "Camboi" }, { id: 3, username: "lizzy" }, ``` --- - ```/answers```: lists all answers and the user id/question id associated with each answer ```javascript= { id: 1, user_id: 1, question_id: 1, answers: "Surveillance Capitalism" } ``` --- - ```/answers/:id```: lists a specific answer based on id ```javascript= { answers: "Surveillance Capitalism" } ``` --- - ```/questions```: lists all questions ```javascript= { id: 1, user_id: null, question: "What book would you add to the school curiculum?" }, { id: 3, user_id: 8, question: "If you could genetically engineer your kids what traits would you give them?" } ``` --- ## What we learned - Difference between imports and require (imports not supported in node) - Making the most of SQL and its functionality - Example ```sql UNIQUE ``` --- ## What we learned continued... - A lot about not testing - Not thinking of the endpoints as frontend web pages, rather... - Abstracting the API - Can see JSON in browser. Not sure --- ## What we struggled with - Conceptualising the project without a front end!!! ![](https://media.giphy.com/media/kaq6GnxDlJaBq/giphy.gif) --- ## Still confused about - What each API function does -- (more comments in code, writing ReadME sooner may have helped, clearer planning on what we want them to do) - What all the id's do! ``` /answers/:id /questions/:id /users/:id ``` -- should have used different names --- - What status codes to use when. Especially when to use ![](https://i.imgur.com/0eEG33J.png) ![](https://media.giphy.com/media/fWZvYFCh4oyl2/giphy.gif) --- # It's Q&A time ![](https://media.giphy.com/media/XqwVE7UegGrpm/giphy.gif) ---
{"metaMigratedAt":"2023-06-15T06:41:20.748Z","metaMigratedFrom":"Content","title":"Week7-BGJK","breaks":true,"contributors":"[{\"id\":\"6898df79-5b31-4c78-acd1-86a97123cdc1\",\"add\":4331,\"del\":2305},{\"id\":\"15813e8a-4a82-4c1f-a14a-8d0c01639173\",\"add\":2103,\"del\":1294},{\"id\":\"fc28ac9f-05b4-4c0c-ba0f-978abbf9d995\",\"add\":593,\"del\":321},{\"id\":\"11eba2be-5fbb-4639-85ec-7ad40264d41d\",\"add\":216,\"del\":113}]"}
    179 views