# Demand

## User demand endpoint

## get demands

<mark style="color:blue;">`GET`</mark> `https://carpoolingbackend.herokuapp.com/v1/apis/demandhe`

Return all demands on a specific offer.

#### Path Parameters

| Name          | Type   | Description                                           |
| ------------- | ------ | ----------------------------------------------------- |
| Authorization | string | The `auth_token` of the  currently authenticated user |

#### Query Parameters

| Name | Type    | Description                       |
| ---- | ------- | --------------------------------- |
| id   | integer | Get a demand on a specific offer. |

{% tabs %}
{% tab title="200 " %}

```
[
  {
    "id": 1,
    "passenger": {
      "first_name": "vick",
      "last_name": null,
      "phone_number": null,
      "profile_pic": "https://carpoolingbackend.herokuapp.com/media/sample.jpg",
      "user": 1
    },
    "origin": {
      "id": 1,
      "name": "Juja",
      "lat": 43.0,
      "lng": 56.0
    },
    "destination": {
      "id": 2,
      "name": "Dellview",
      "lat": 43.0,
      "lng": 56.0
    },
    "available_seats": 1,
    "departure_time": "2020-05-05T02:24:19.008021+03:00",
    "created_at": "2020-01-14T10:02:47.535964+03:00",
    "distance": "30"
  }
]
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
If **No** demand has been made yet, the `GET request` returns an empty array. `( [ ] )`.
{% endhint %}

#### An example of a get request on the demand endpoint.

![get demand endpoint](https://2024038863-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LwmhcyiDwr6i4voPxEn%2F-LyXqJIBlyysHkWp2SWJ%2F-LyXsWTeCfFRIqJUfku8%2Fget_demand_endpoint.png?alt=media\&token=434a0875-c049-432d-ae52-ed71cd342940)

## post demand

<mark style="color:green;">`POST`</mark> `https://carpoolingbackend.herokuapp.com/v1/apis/demand`

Make a demand on a specific offer

#### Path Parameters

| Name          | Type   | Description                                      |
| ------------- | ------ | ------------------------------------------------ |
| Authorization | string | the `auth_token` of the user making the request. |

#### Request Body

| Name             | Type    | Description                                                                                   |
| ---------------- | ------- | --------------------------------------------------------------------------------------------- |
| available\_seats | integer | The number of seats a passenger needs for the ride.                                           |
| departure\_time  | string  | The time of departure for the trip.                                                           |
| distance         | number  | The distance from the `origin` to the `destination` in `Km.`                                  |
| origin           | object  | An object containing the longitude, latitude and the name of the passengers current location. |
| destination      | object  | An object containing the longitude, latitude and name of the user's chosen destination.       |

{% tabs %}
{% tab title="201 Response after a demand is successfully created." %}

```
{
  "id": 1,
  "passenger": {
    "first_name": "vick",
    "last_name": null,
    "phone_number": null,
    "profile_pic": "https://carpoolingbackend.herokuapp.com/media/sample.jpg",
    "user": 1
  },
  "origin": {
    "id": 1,
    "name": "Juja",
    "lat": 43.0,
    "lng": 56.0
  },
  "destination": {
    "id": 2,
    "name": "Dellview",
    "lat": 43.0,
    "lng": 56.0
  },
  "available_seats": 1,
  "departure_time": "2020-05-05T02:24:19.008021+03:00",
  "created_at": "2020-01-14T10:02:47.535964+03:00",
  "distance": "30"
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Note that you have to pass the location as two objects containing the origin and destination.

A sample body of the request is shown below.
{% endhint %}

```
{
	"origin":{
      "name": "Juja",
      "lng": 56.0,
      "lat": 43.0
	},
	"destination":
	{
      "name": "Dellview",
      "lng": 56.0,
      "lat": 43.0
	},
	"available_seats":1,
	"departure_time":"2020-05-05T02:24:19.008021+03:00",
	"distance":30
}
```

#### An example of a post request on the demand endpoint

![post\_on\_demand](https://2024038863-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LwmhcyiDwr6i4voPxEn%2F-LyXwmI4HU7MVDe-7nji%2F-LyXxKGv6n5AE9m4fbYh%2Fpost_on_demand.png?alt=media\&token=912b2b82-b764-4653-b530-73706b0243de)

## delete demand

<mark style="color:red;">`DELETE`</mark> `https://carpoolingbackend.herokuapp.com/v1/apis/demand/{id}`

Delete a demand on a trip.

#### Path Parameters

| Name          | Type   | Description                                       |
| ------------- | ------ | ------------------------------------------------- |
| Authorization | string | The `auth_token` of the currently logged in user. |

#### Query Parameters

| Name | Type    | Description                           |
| ---- | ------- | ------------------------------------- |
| id   | integer | The `id` of the demand to be deleted. |

{% tabs %}
{% tab title="204 The demand has been deleted successfully." %}

```
no body returned for response
```

{% endtab %}
{% endtabs %}
