eddie-2020 / bcycom-backend

This project comprises of the back end of a motorcycle booking store you can view the front end of this app repo here https://github.com/Dagic-zewdu/final-capstone-frontend
1 stars 0 forks source link

[2pt] Create the Api(Get, post) for reservations page #21

Closed eddie-2020 closed 2 years ago

eddie-2020 commented 2 years ago
Dagic-zewdu commented 2 years ago

For the get API we have six endpoints

  1. http://localhost:3000/api/v1/reservations, should return all reservations
  2. http://localhost:3000/api/v1/reservation/1, should return a single reservation
    {
    user: {
     "id": 2,
    "photo": "https://lh3.googleusercontent.com/a-/AFdZucr30ljEL5GxFopjvqkvsMs_V9RGIGth2ldxwcNxJQ=s96-c",
    "username": "Dagi Zewdu",
    "email": "dagi.zewdu.dz@gmail.com",
    "created_at": "2022-07-14T08:42:06.174Z",
    "updated_at": "2022-07-14T08:42:06.174Z"
    },
    motorcycle :{
     "id": 8,
        "title": "Vespas v-18",
        "model": "elas user-2",
        "description": "Vespas blaba",
        "cylinder": 2,
        "acceleration": "80MHP to 100 MHP",
        "price": 8800.0,
        "duration": 8,
        "discount": 0,
        "user_id": 1,
        "created_at": "2022-07-15T07:07:48.774Z",
        "updated_at": "2022-07-15T07:08:29.574Z",
        "images": [
            "ur1",
            "ur2"
        ],
    "created_by": {
        "id": 1,
        "photo": "12345678",
        "username": "dagic",
        "email": "ezward.zewdu.dz@gmail.com",
        "created_at": "2022-07-13T20:42:12.105Z",
        "updated_at": "2022-07-13T20:42:12.105Z"
    }
    },
    phone: "980345"
    }
  3. For the post API endpoint http://localhost:3000/api/v1/reservation the body should look accept the following body and save it to the database
    {
    "user_id":1, // required
    "motorcycle_id":1, // required
    "phone": string, // optional 
    }
  4. To filter reservations that are added we need http://localhost:3000/api/v1/getreservation the body should accept the following
    {
    "user_id":1, // optional
    "motorcycle_id":1, // optional
    }
  5. We have the updated API with the put endpoint http://localhost:3000/api/v1/reservation/1. The body should look accept the following body and save it to the database. Remember always compare the creator of the reservation with the token provided.
    {
    "user_id":1, // required
    "motorcycle_id":1, // required
    "phone": string, // optional 
    }
  6. we have a delete endpoint with http://localhost:3000/api/v1/reservation/1 to delete the reservation . Remember always compare the creator of the reservation with the token provided.