# Travel Api
## Agoda Travel Api
We have some list of hotels in our database. And each hotel can have multiple rooms. Hotels are identified by `hotel-id` and rooms are identified by `room-id`. This service is consumed by several types of clients identified by `client-id`. Each room has prices and can be selled at different prices based on customer's loyalty level identified by `loyalty`.
There are 3 (three) loyalty levels(along with `loyalty` id) for now
* *Default*: 10
* *Discount*: 11
* *Vip*: 12
Also, We've 3(three) clients(along with `client-id`) for now
* *Desktop*: 1
* *Mobile app*: 2
* *Google search*: 3
### BaseURL: {scheme}://{host}:{port}
### Example URL: http://localhost:8000
## Ping the service
* **Description:** Pings the service
* **Method:** `GET`
* **Endpoint:** `/`
* **Headers:** `{Content-Type: application/json}`
* **Request Example:** `http://localhost:8000`
* **Response:**
```json=
{
"message": "success",
"data": {
"method": "GET",
"service_name": "Travel REST api"
}
}
```
## Create/Update room price
* **Description:** Creates/updates room prices. We can create/update price for a single client at a time.
* **Method:** `POST`
* **Endpoint:** `/api/v1/prices`
* **Headers:** `{Content-Type: application/json}`
* **Body:**
```json=
{
"hotel_id": 1,
"room_id": 101,
"prices": {
"client_id": 1,
"price": {
"default": 100.00,
"vip": 90.00,
"discount": 95
}
}
}
```
* **Request curl:**
```json=
curl --request POST \
--url http://localhost:8000/api/v1/prices \
--header 'Content-Type: application/json' \
--data '{
"hotel_id": 1,
"room_id": 101,
"prices": {
"client_id": 1,
"price": {
"default": 100.00,
"vip": 90.00,
"discount": 95
}
}
}'
```
* **Body Description :**
* **hotel_id:** (`required`) - Id of the hotel | `integer`
* **room_id:** (`required`) - Id of the room | `integer`
* **client_id:**(`required`) - Id of the client for which the price will be created/updated | `integer` | `any value from 1, 2 or 3`
* **default:** (`required`) - Price for loyalty level Default | `number`
* **discount:**(`optional`) - Price for loyalty level Discount | `number`
* **vip:**(`optional`) - Price for loyalty level Vip | `number`
* **Response:**
```json=
{
"message": "successful",
"data": {
"hotel_id": 1,
"room_id": 101,
"client_id": 1
}
}
```
## Get Rooms
* **Description:** Finds rooms by given criteria specified in query params
* **Method:** `GET`
* **Endpoint:** `/api/v1/hotels/{hotel-id}`
* **Headers:** `{Content-Type: application/json}`
* **Query Params:**
* *`room-id:`* return all rooms in the hotel if `room-id` is not provided
* *`client-id:`* if not provided return prices for all available clients, if provided return prices for the exact client
* *`loyalty:`* if not provided return prices for all available loyalty levels | `any value from 10, 11 or 12`
* *`limit:`* limit the maximum number of rooms this endpoint can return, default is 2 if not provided
* **Request:** `/api/v1/hotels/1?room-id=102&client-id=1&loyalty=10&limit=1`
* **Request curl:**
```json=
curl --request GET \
--url 'http://localhost:8000/api/v1/hotels/1?room-id=101&client-id=1&loyalty=10&limit=1'
```
* **Response:**
```json=
{
"next": "/api/v1/hotels/1?limit=1&page=2",
"previous": "",
"message": "successful",
"data": {
"hotel_id": 1,
"rooms": [
{
"room_id": 101,
"prices": [
{
"client_id": 1,
"price": {
"default": 100
}
}
]
}
]
}
}
```
* **Response Description :**
* **next:** url for next rooms with given limit
* **prev:** ulr for previous rooms with given limit
* **Request:** `/api/v1/hotels/1`
* **Request curl:**
```json=
curl --request GET \
--url http://localhost:8000/api/v1/hotels/1
```
* **Response:**
```json=
{
"next": "/api/v1/hotels/1?limit=2&page=2",
"previous": "",
"message": "successful",
"data": {
"hotel_id": 1,
"rooms": [
{
"room_id": 100,
"prices": [
{
"client_id": 1,
"price": {
"default": 100,
"vip": 90,
"discount": 98
}
}
]
},
{
"room_id": 101,
"prices": [
{
"client_id": 1,
"price": {
"default": 100,
"vip": 90,
"discount": 95
}
},
{
"client_id": 2,
"price": {
"default": 100,
"vip": 90,
"discount": 95
}
}
]
}
]
}
}
```