ctc-uci/lpa

Create endpoints 3

Opened this issue · 0 comments

Setup

Before you can work on the repo, you need to add the secrets.
For the Frontend .env, put it in /client.
For the Backend .env, put it in /server.

You also need to add this file in /server/config

Task

Create the following API endpoints:

GET         /bookings?start=[val]&end=[val]
POST        /bookings
PUT         /bookings/:id
DELETE      /bookings/:id

For a description of each of these endpoints, see the DB model.
Follow proper API conventions and return status codes along with your response. Namely 200, 404, 500, etc.

Put your endpoints into /server/routes/[FILENAME].js
Replace FILENAME with the name of the DB table that the endpoint is for.

Don't Forget: use the keysToCamel function, as seen in the sample users.ts file, to make the SQL keys into camel case

Some sample files have been provided. They are in TS not JS, but you can ignore the TS stuff (and work in JS)

Steps

  1. Create file for each endpoint (bookings)
  2. Create a router for this file (see examples)
  3. Import and place this router into /server/src/App.ts (see line 40)
  4. Create the functions for get/post/delete/put

Example

GET /users/:id
Place this into /server/routes/users.js
See users.ts for the best examples.

Testing

To test your implementation, you can use Postman like we have in the bootcamps.

If you put your endpoints in sample.js (for example only), then you will need to send requests to:
127.0.0.1:3001/sample/<your endpoint>

Resources

Secrets (.env)
PostgreSQL DB Login
DB Schema

Checklist

  • Create all endpoints
  • Test all endpoints
  • Commit changes
  • Push changes, create PR