---
# System prepended metadata

title: Dokumentasi Lacak Bagasi
tags: [itb, documentation]

---

###### tags : `itb` `documentation`

---
title: "Dokumentasi Rest API Lacak Bagasi"
---

# Dokumentasi Lacak Bagasi

## 1. Daftar Isi

[TOC]

## 2. Petunjuk Umum

1. Base Url : `http://{ip_address}:8080`
2. Untuk mendapatkan akses api, setiap request perlu disertakan token pada header.
3. Token diperoleh dengan mengakses api token dengan mengirimkan username & password. Server memberi respon berupa token dan refresh_token. Token valid dalam jangka waktu tertentu, jika token sudah tidak valib, gunakan refresh_token untuk mendapatkan token baru.

## 3. Format Respon

```gherkin=
Sample Response:
{
    status: "success",
    result: [
        {data1},
        {data2},
    ]
}

{
    status: "success",
    result: response.data
}

Error response :
{
    error: message
}
```

> Read more about Gherkin here: https://docs.cucumber.io/gherkin/reference/

## 4. Diagram Alir Request

#### Request Token

```sequence
Note left of Client: username & password
Client->Server: request token
Server->Database: query database
Note right of Server: validate payload
Database->Server: send user data
Server->Client: send response
Note left of Client: token & refresh_token
```

#### General Request

```sequence
Note left of Client: payload + token
Client->Server: send request
Note right of Server: validate token
Server->Database: query database
Note right of Database: query data
Database->Server: send data
Server->Client: send response
Note left of Client: data
```

# REST API

## 1. Auth Token

Endpoint : `{base_url}/api/v1/auth`
|No|Metode|Endpoint|Header|Body|Deskripsi|
|:----:|:----:|:-----:|:-----:|:-----:|:-----:|
|1|Post|`{auth_endpoint}/token`|-|username, password|Mendapatkan token & refresh token|
|2|Post|`{auth_endpoint}/refresh`| refresh-token|- |Mendapatkan token & refresh token baru|

> Catatan :
> Masa berlaku token adalah 1 jam sedangkan refresh token 1 hari.

#### Deskripsi Body

| No  |    Item     | Tipe Data |  Catatan  |
| :-: | :---------: | :-------: | :-------: |
|  1  |  username   |  String   | data unik |
|  2  |    email    |  String   |     -     |
|  3  | isSuperuser |  Boolean  |     -     |
|  4  |   isAdmin   |  Boolean  |     -     |

#### Sample Request - Using Curl

##### Get Token

```gherkin=
Request :
curl --location --request POST 'http://127.0.0.1:8080/api/v1/auth/token' \
--header 'Content-Type: application/json' \
--data-raw '{"username":"admin", "password":"bandung123abc"}'

Response:
{
    "status": "success",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjAzMTcxMDU0LCJleHAiOjE2MDMyNTc0NTR9.14jJ_htr460bVCqMvsl3ImcpZDtiYXbavfSo5_l6MHY",
    "max_age": "1d",
    "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjAzMTcxMDU0LCJleHAiOjE2MDMzNDM4NTR9.AsYg6wRyke48ibK2SH2RLydrX_k7KRJavWXVaWyhT3Y"
}
```

##### Refresh Token

```gherkin=
Request :
curl --location --request POST 'http://127.0.0.1:8080/api/v1/auth/refresh' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjAzMTcxMDU0LCJleHAiOjE2MDMzNDM4NTR9.AsYg6wRyke48ibK2SH2RLydrX_k7KRJavWXVaWyhT3Y'

Response:
{
    "status": "success",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjAzMTcxMjkyLCJleHAiOjE2MDMyNTc2OTJ9.DfVLp8JvCt_4uhCTi43Ln9-vkc9qVqpMeRWJduMB270",
    "max_age": "1d",
    "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjAzMTcxMjkyLCJleHAiOjE2MDMzNDQwOTJ9.rOMJ-ipdPdopy4qrzEhxvfxMy35qxqaYByn_yoJjbPk"
}
```

## 2. User

#### List API User

Endpoint :`{base_url}/api/v1/user`
|No|Metode|Endpoint|Body|Deskripsi|
|:----:|:----:|:-----:|:-----:|:-----:|
|1|Get|`{user_endpoint}`|-|Mendapatkan list user|
|2|Post|`{user_endpoint}`| username, email, isSuperuser, isAdmin |Registrasi User|
|3|Patch|`{user_endpoint}`| command |Memperbarui data password user|
|4|Delete|`{user_endpoint}`| command |menghapus user |

> Catatan :
> Akses api ini hanya bisa dilakukan oleh superuser atau user yang bersangkutan. User yang tidak memiliki izin akan mendapatkan pesan error dengan kode 403.

#### Deskripsi Body

| No  |    Item     | Tipe Data |  Catatan  |
| :-: | :---------: | :-------: | :-------: |
|  1  |  username   |  String   | data unik |
|  2  |    email    |  String   |     -     |
|  3  | isSuperuser |  Boolean  |     -     |
|  4  |   isAdmin   |  Boolean  |     -     |

## 3. Device

#### List API Device

Endpoint :`{base_url}/api/v1/device`
|No|Metode|Endpoint|Param|Body|Deskripsi|
|:----:|:----:|:-----:|:-----:|:-----:|:-----:|
|1|Get|`{device_endpoint}`|limit, offset, _id, airport, terminal, gate, location , search|-|Mendapatkan list device|
|2|Post|`{device_endpoint}`|-|_id, airport, terminal, gate, location |Registrasi Device|
|3|Patch|`{device_endpoint}`|-| _id, airport, terminal, gate, location |Memperbarui data device|
|4|Delete|`{device_endpoint}`|_id|command |Menghapus device |

> Catatan :
> Get data bisa dilakukan oleh semua user yang memiliki token, sedangkan request lainnnya hanya bisa dilakukan oleh admin.

#### Deskripsi Body

| No  |   Item   | Tipe Data |               Catatan                |
| :-: | :------: | :-------: | :----------------------------------: |
|  1  | \_id |  String   |              data unik               |
|  2  | airport  |  String   |                  -                   |
|  3  | terminal |  String   |                  -                   |
|  4  |   gate   |  String   |                  -                   |
|  5  | location |  String   | valid: loading, plane, getout, claim |

#### Sample Request - Using Curl

##### Get Device

```gherkin=
Request :
curl --location --request GET 'http://127.0.01:8080/api/v1/device' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA'

Response:
{
    "result": [
        {
            "created": "2020-11-01T15:47:39.132Z",
            "_id": "device-2",
            "airport": "Husein Sastranegara (BDO)",
            "terminal": "A",
            "gate": "1",
            "location": "2"
        },
        {
            "created": "2020-11-01T15:47:39.132Z",
            "_id": "device-1",
            "airport": "Husein Sastranegara (BDO)",
            "terminal": "A",
            "gate": "1",
            "location": "1"
        }
    ],
    "count": 2
}
```

##### Post Device

```gherkin=
curl --location --request POST 'http://127.0.01:8080/api/v1/device' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'airport=Soekarno Hatta (CGK)' \
--data-urlencode 'terminal=A' \
--data-urlencode 'gate=2' \
--data-urlencode 'location=3' \
--data-urlencode '_id=device-3'

Response:
{
    "message": "success",
    "result": {
        "created": "2020-11-02T15:04:59.165Z",
        "airport": "Soekarno Hatta (CGK)",
        "terminal": "A",
        "gate": "2",
        "location": "3",
        "_id": "device-3",
        "__v": 0
    }
}

```

##### Patch Device

```gherkin=
Request :
curl --location --request PATCH 'http://127.0.01:8080/api/v1/device' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode '_id=device-3' \
--data-urlencode 'terminal=B'

Response:
{
    "message": "success",
    "result": {
        "created": "2020-11-02T15:04:59.165Z",
        "_id": "device-3",
        "airport": "Soekarno Hatta (CGK)",
        "terminal": "B",
        "gate": "2",
        "location": "3",
        "__v": 0
    }
}

```

##### Delete Device

```gherkin=
Request :
curl --location --request DELETE 'http://127.0.01:8080/api/v1/device?_id=device-3' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA'

Response:
{
    "message": "deleted",
    "deletedCount": 1
}
```

## 4. Flight

#### List API Flight

Endpoint :`{base_url}/api/v1/flight`
|No|Metode|Endpoint|Param|Body|Deskripsi|
|:----:|:----:|:-----:|:-----:|:-----:|:-----:|
|1|Get|`{flight_endpoint}`|limit, offset, _id, airline, departureAirport, arrivalAirport|-|Mendapatkan list flight|
|2|Post|`{flight_endpoint}`| -|_id, airline, departureAirport, arrivalAirport |Registrasi Flight|
|3|Patch|`{flight_endpoint}`| -|_id, airline, departureAirport, arrivalAirport |Memperbarui data penerbangan|
|4|Delete|`{flight_endpoint}`|_id|- |Menghapus penerbangan|

> Catatan :
> Get data bisa dilakukan oleh semua user yang memiliki token, sedangkan request lainnnya hanya bisa dilakukan oleh admin.

#### Deskripsi Body

| No  |       Item       | Tipe Data | Catatan |
| :-: | :--------------: | :-------: | :-----: |
|  1  |   \_id    |  String   |    Nomor Penerbangan   | 
|  2  |     airline      |  String   |    -    |
|  3  | departureAirport |  String   |    -    |
|  4  |  arrivalAirport  |  String   |    -    |

#### Sample Request - Using Curl

##### Get Flight

```gherkin=
Request :
curl --location --request GET 'http://127.0.01:8080/api/v1/flight?airline=Wings%20Air' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA'

Response:
{
    "result": [
        {
            "_id": "IW 1951",
            "airline": "Wings Air",
            "departureAirport": "Husein Sastranegara (BDO)",
            "arrivalAirport": "Soekarno Hatta (CGK)"
        }
    ],
    "count": 1
}
```

##### Post Flight

```gherkin=
Request :
curl --location --request POST 'http://127.0.01:8080/api/v1/flight' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode '_id=IW 1951' \
--data-urlencode 'airline=Wings Air' \
--data-urlencode 'departureAirport=Husein Sastranegara (BDO)' \
--data-urlencode 'arrivalAirport=Soekarno Hatta (CGK)'

Response:
{
    "error": "flight already registered"
}

```

##### Patch Flight

```gherkin=
Request :
curl --location --request PATCH 'http://127.0.01:8080/api/v1/flight' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode '_id=IW 1951' \
--data-urlencode 'arrivalAirport=Soekarno Hatta (CGK)'

Response:
{
    "message": "success",
    "result": {
        "_id": "IW 1951",
        "airline": "Wings Air",
        "departureAirport": "Husein Sastranegara (BDO)",
        "arrivalAirport": "Soekarno Hatta (CGK)",
        "__v": 0
    }
}

```

##### Delete Flight

```gherkin=
Request :
curl --location --request DELETE 'http://127.0.01:8080/api/v1/flight?_id=IW%201951' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA'

Response:
{
    "message": "deleted",
    "deletedCount": 1
}

```

## 5. Schedule

#### List API Schedule

Endpoint :`{base_url}/api/v1/schedule`
|No|Metode|Endpoint|Body|Deskripsi|
|:----:|:----:|:-----:|:-----:|:-----:|
|1|Get|`{schedule_endpoint}`|limit, offset, departureTerminal, departureGate, arrivalTerminal, arrivalGate, flight, search |Mendapatkan list schedule|
|2|Post|`{schedule_endpoint}`| departureDatetime, departureDelay, departureTerminal, departureGate, arrivalDatetime, arrivalDelay, arrivalTerminal, arrivalGate, flight |Registrasi Flight|
|3|Patch|`{schedule_endpoint}`| \_id, departureDatetime, departureDelay, departureTerminal, departureGate, arrivalDatetime, arrivalDelay, arrivalTerminal, arrivalGate, flight |Memperbarui data penerbangan|
|4|Delete|`{schedule_endpoint}`| \_id |Menghapus penerbangan|

> Catatan :
> Get data bisa dilakukan oleh semua user yang memiliki token, sedangkan request lainnnya hanya bisa dilakukan oleh admin.

#### Deskripsi Body

| No  |       Item        | Tipe Data |    Catatan    |
| :-: | :---------------: | :-------: | :-----------: |
|  1  |       \_id        |  String   |       -       |
|  2  | departureDatetime | Datetime  |       -       |
|  3  |  departureDelay   |  Number   |       -       |
|  4  | departureTerminal |  String   |       -       |
|  5  |   departureGate   |  String   |       -       |
|  6  |  arrivalDatetime  | Datetime  |       -       |
|  7  |   arrivalDelay    |  Number   |       -       |
|  8  |  arrivalTerminal  |  String   |       -       |
|  9  |    arrivalGate    |  String   |       -       |
| 10  |      flight       |  String   | Flight Number |

#### Sample Request - Using Curl

##### Get Schedule

```gherkin=
Request :
curl --location --request GET 'http://127.0.01:8080/api/v1/schedule?limit=1&offset=2' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA'

Response:

{
    "result": [
        {
            "departureDelay": 0,
            "departureGate": "1",
            "arrivalDelay": 0,
            "arrivalGate": "2",
            "_id": "5f9ee2e233dbda48385ad6ae",
            "departureDatetime": "2020-11-01T00:00:00.000Z",
            "departureTerminal": "A",
            "arrivalDatetime": "2020-11-01T03:10:00.000Z",
            "arrivalTerminal": "A",
            "flight": {
                "_id": "JT-3961",
                "airline": "Lion Air",
                "departureAirport": "Husein Sastranegara (BDO)",
                "arrivalAirport": "Kualanamu (KNO)"
            }
        }
    ],
    "count": 3
}
```

##### Post Schedule

```gherkin=
Request :
curl --location --request POST 'http://127.0.01:8080/api/v1/schedule' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'departureDatetime=2020-10-15 15:40:00' \
--data-urlencode 'departureTerminal=A' \
--data-urlencode 'departureGate=1' \
--data-urlencode 'arrivalDatetime=2020-10-15 18:00:00' \
--data-urlencode 'arrivalTerminal=A' \
--data-urlencode 'arrivalGate=1' \
--data-urlencode 'flight=JT-3961'

Response:
{
    "message": "success",
    "result": {
        "departureDelay": 0,
        "departureGate": "1",
        "arrivalDelay": 0,
        "arrivalGate": "1",
        "_id": "5fa0277209ea62e13496f703",
        "departureDatetime": "2020-10-15T08:40:00.000Z",
        "departureTerminal": "A",
        "arrivalDatetime": "2020-10-15T11:00:00.000Z",
        "arrivalTerminal": "A",
        "flight": {
            "_id": "JT-3961",
            "airline": "Lion Air",
            "departureAirport": "Husein Sastranegara (BDO)",
            "arrivalAirport": "Kualanamu (KNO)",
            "__v": 0
        },
        "__v": 0
    }
}

```

##### Patch Schedule

```gherkin=
Request :
curl --location --request PATCH 'http://127.0.01:8080/api/v1/schedule' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode '_id=5fa0277209ea62e13496f703' \
--data-urlencode 'arrivalDatetime=2020-10-15T11:20:00.000Z'

Response:
{
    "message": "success",
    "result": {
        "departureDelay": 0,
        "departureGate": "1",
        "arrivalDelay": 0,
        "arrivalGate": "1",
        "_id": "5fa0277209ea62e13496f703",
        "departureDatetime": "2020-10-15T08:40:00.000Z",
        "departureTerminal": "A",
        "arrivalDatetime": "2020-10-15T11:20:00.000Z",
        "arrivalTerminal": "A",
        "flight": "JT-3961",
        "__v": 0
    }
}
```

##### Delete Schedule

```gherkin=
Request :
curl --location --request DELETE 'http://127.0.01:8080/api/v1/schedule?_id=5fa0277209ea62e13496f703' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA'

Response:
{
    "message": "deleted",
    "deletedCount": 1
}
```

## 6. Passenger

#### List API Passenger

Endpoint :`{base_url}/api/v1/passenger`
|No|Metode|Endpoint|Param|Body|Deskripsi|
|:----:|:----:|:-----:|:-----:|:-----:|:-----:|
|1|Get|`{passenger_endpoint}`|limit, offset, idType, passengerId, firstName, lastName, nationality, email, search |-|Mendapatkan list passenger|
|2|Post|`{passenger_endpoint}`|-|passengerId, idType, firstName, lastName, nationality, email, phone|Registrasi passenger|
|3|Patch|`{passenger_endpoint}`|-| passengerId, email, phone |Memperbarui data passenger|
|4|Delete|`{passenger_endpoint}`|passengerId| - |Menghapus passenger|

> Catatan :
> Get data bisa dilakukan oleh semua user yang memiliki token, sedangkan request lainnnya hanya bisa dilakukan oleh admin.

#### Deskripsi Body

| No  |    Item     | Tipe Data | Catatan |
| :-: | :---------: | :-------: | :-----: |
|  1  | passengerId |  String   |    -    |
|  2  |   idType    |  String   |    -    |
|  3  |  firstName  |  String   |    -    |
|  4  |  lastName   |  String   |    -    |
|  5  | nationality |  String   |    -    |
|  6  |    email    |  String   |    -    |
|  7  |    phone    |  String   |    -    |

#### Sample Request - Using Curl

##### Get Passenger

```gherkin=
Request :
curl --location --request GET 'http://127.0.01:8080/api/v1/passenger?limit=1' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA'

Response:
{
    "result": [
        {
            "_id": "234",
            "idType": "ktp",
            "firstName": "Fitria",
            "lastName": "Miftasani",
            "nationality": "indonesia",
            "email": "",
            "phone": "",
            "created": "2020-11-01T15:50:36.664Z"
        }
    ],
    "count": 2
}

```

##### Post Passenger

```gherkin=
Request :
curl --location --request POST 'http://127.0.01:8080/api/v1/passenger' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode '_id=123456' \
--data-urlencode 'idType=passport' \
--data-urlencode 'firstName=ghazi' \
--data-urlencode 'lastName=el ghiifari' \
--data-urlencode 'nationality=indonesia'


Response:
{
    "message": "success",
    "result": {
        "_id": "123456",
        "idType": "passport",
        "firstName": "ghazi",
        "lastName": "el ghiifari",
        "nationality": "indonesia",
        "created": "2020-11-02T15:41:15.553Z",
        "__v": 0
    }
}

```

##### Patch Passenger

```gherkin=
Request :
curl --location --request PATCH 'http://127.0.01:8080/api/v1/passenger' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode '_id=123456' \
--data-urlencode 'email=ghazi@mail.com'

Response:
{
    "message": "success",
    "result": {
        "_id": "123456",
        "idType": "passport",
        "firstName": "ghazi",
        "lastName": "el ghiifari",
        "nationality": "indonesia",
        "created": "2020-11-02T15:41:15.553Z",
        "__v": 0,
        "email": "ghazi@mail.com"
    }
}

```

##### Delete Passenger

```gherkin=
Request :
curl --location --request DELETE 'http://127.0.01:8080/api/v1/passenger?_id=12345' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA'

Response:
{
    "error": "data not found",
    "deletedCount": 0
}

```

## 7. Luggage

#### List API Luggage

Endpoint :`{base_url}/api/v1/luggage`
|No|Metode|Endpoint|Param|Body|Deskripsi|
|:----:|:----:|:-----:|:-----:|:-----:|:-----:|
|1|Get|`{luggage_endpoint}`|limit, offset, \_id, passenger , search|-| Mendapatkan list luggage |
|2|Get|`{luggage_endpoint}/detail`|\_id|-| Mendapatkan detail luggage |
|2|Post|`{luggage_endpoint}`|-|\_id, weight, dimension, lastStatus, lastUpdate, passenger, flight|Registrasi luggage|
|3|Delete|`{luggage_endpoint}`|\_id|-|Menghapus luggage|

> Catatan :
> Get data bisa dilakukan oleh semua user yang memiliki token, sedangkan request lainnnya hanya bisa dilakukan oleh admin.

#### Deskripsi Body

| No  |     Item     | Tipe Data |              Catatan              |
| :-: | :----------: | :-------: | :-------------------------------: |
|  1  |  \_id   |  String   |                 -                 |
|  2  |    weight    |  String   |                 -                 |
|  3  |  dimension   |  String   | format: p x l x t dalam satuan cm |
|  4  |  lastStatus  |  String   |                 -                 |
|  5  |  lastUpdate  |  String   |                 -                 |
|  6  |   passenger    |  String   |    Id Penumpang                 |
|  7  | flight |  String   |        Kode Penerbangan                 |

#### Sample Request - Using Curl

##### Get Luggage

```gherkin=
Request :
curl --location --request GET 'http://127.0.01:8080/api/v1/luggage?search=bagasi-1' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA'

Response:
{
    "result": [
        {
            "created": "2020-11-01T17:07:34.699Z",
            "lastStatus": "0",
            "lastUpdate": "2020-11-01T17:07:34.699Z",
            "_id": "bagasi-1",
            "weight": 20,
            "dimension": "20x20x20",
            "passenger": {
                "_id": "123",
                "firstName": "Yudi",
                "lastName": "Aditya"
            },
            "schedule": {
                "_id": "5f9ee2e233dbda48385ad6ae",
                "flight": {
                    "_id": "JT-3961",
                    "airline": "Lion Air",
                    "departureAirport": "Husein Sastranegara (BDO)",
                    "arrivalAirport": "Kualanamu (KNO)",
                    "__v": 0
                }
            }
        }
    ],
    "count": 1
}

```

##### Get Luggage Detail

```gherkin=
Request :
curl --location --request GET 'http://127.0.01:8080/api/v1/luggage/detail/?_id=bagasi-1' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA'

Response:
{
    "result": {
        "created": "2020-11-01T17:07:34.699Z",
        "_id": "bagasi-1",
        "weight": 20,
        "dimension": "20x20x20",
        "passenger": "123",
        "schedule": {
            "_id": "5f9ee2e233dbda48385ad6ae",
            "departureDatetime": "2020-11-01T00:00:00.000Z",
            "arrivalDatetime": "2020-11-01T03:10:00.000Z",
            "flight": {
                "_id": "JT-3961",
                "airline": "Lion Air",
                "departureAirport": "Husein Sastranegara (BDO)",
                "arrivalAirport": "Kualanamu (KNO)"
            }
        }
    }
}

```

##### Post Luggage

```gherkin=
Request :
curl --location --request POST 'http://127.0.01:8080/api/v1/luggage' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode '_id=12345678' \
--data-urlencode 'passenger=12345' \
--data-urlencode 'flight=JT 3961'

Response:
{
    "error": "passenger was not found"
}

```

##### Delete Luggage

```gherkin=
Request :
curl --location --request DELETE 'http://127.0.01:8080/api/v1/luggage/?_id=bagasi-1' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0MzI5Nzc3LCJleHAiOjE2MDQ0MTYxNzd9.NoNOLN1UfJSqnQCsQf9oKrKorxCL1xSMqJhQJInYVZA'

Response:
{
    "message": "deleted",
    "deletedCount": 1
}

```

## 8. LuggageLog

#### List API LuggageLog

Endpoint :`{base_url}/api/v1/luggage-log`
|No|Metode|Endpoint|Param|Body|Deskripsi|
|:----:|:----:|:-----:|:-----:|:-----:|:-----:|
|1|Get|`{luggageLog_endpoint}`|limit, offset, status, luggage, device, search |Mendapatkan list luggage Log|
|2|Get|`{luggageLog_endpoint}/detail`|luggage |Mendapatkan riwayat Log detail|
|3|Post|`{luggageLog_endpoint}`|-| timestamp, \_id, device | Registrasi luggage Log |
|4|Delete|`{luggageLog_endpoint}`|\_id|-|Menghapus luggage Log|

> Catatan :
> Get data bisa dilakukan oleh semua user yang memiliki token, sedangkan request lainnnya hanya bisa dilakukan oleh admin.

#### Deskripsi Body

| No  |   Item    | Tipe Data | Catatan |
| :-: | :-------: | :-------: | :-----: |
|  1  | timestamp | Datetime  |    -    |
|  2  | luggage |  String   |    -    |
|  3  | device  |  String   |    -    |

#### Sample Request - Using Curl

##### Get LuggageLog

```gherkin=
Request :
curl --location --request GET 'http://127.0.01:8080/api/v1/luggage-log?luggage=bagasi-001' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0NDk5NjM5LCJleHAiOjE2MDQ1ODYwMzl9.o5hFJEH3kEUQjFopYxNx0hdeFjmx05F4WxMjpy_rTj0'

Response:
{
    "result": [
        {
            "timestamp": "2020-11-04T14:57:38.413Z",
            "_id": "5fa2c17c9664fe2dc03f8507",
            "luggage": {
                "_id": "bagasi-001",
                "passenger": {
                    "_id": "ktp-001",
                    "firstName": "Yudi",
                    "lastName": "Aditya"
                }
            },
            "status": 0,
            "message": "ok"
        }
    ],
    "count": 1
}

```

##### Get LuggageLog Detail

```gherkin=
Request :
curl --location --request GET 'http://127.0.01:8080/api/v1/luggage-log/detail?luggage=bagasi-001' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0NDk5NjM5LCJleHAiOjE2MDQ1ODYwMzl9.o5hFJEH3kEUQjFopYxNx0hdeFjmx05F4WxMjpy_rTj0'

Response:
{
    "result": {
        "history": [
            {
                "status": 0,
                "timestamp": "2020-11-04T14:57:38.413Z",
                "isDone": true
            },
            {
                "status": 1,
                "timestamp": "2020-11-04T15:43:42.409Z",
                "isDone": true
            },
            {
                "status": 2,
                "timestamp": "2020-11-04T15:43:42.409Z",
                "isDone": true
            }
        ],
        "luggage": {
            "created": "2020-11-04T14:57:38.405Z",
            "_id": "bagasi-001",
            "weight": 20,
            "dimension": "20x20x20",
            "passenger": "ktp-001",
            "schedule": {
                "_id": "5fa2bd587e6a062ce8a1726f",
                "departureDatetime": "2020-11-04T15:10:00.000Z",
                "arrivalDatetime": "2020-11-04T16:50:00.000Z",
                "flight": {
                    "_id": "JT-3961",
                    "airline": "Lion Air",
                    "departureAirport": "Husein Sastranegara (BDO)",
                    "arrivalAirport": "Kuala Namu (KNM)"
                }
            }
        }
    }
}

```

##### Post LuggageLog

```gherkin=
Request :
curl --location --request POST 'http://127.0.01:8080/api/v1/luggage-log' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0NDk5NjM5LCJleHAiOjE2MDQ1ODYwMzl9.o5hFJEH3kEUQjFopYxNx0hdeFjmx05F4WxMjpy_rTj0' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'luggage=bagasi-001' \
--data-urlencode 'device=device-001'

Response:
{
    "message": "success"
}

```

##### Delete LuggageLog

```gherkin=
Request :
curl --location --request DELETE 'http://127.0.01:8080/api/v1/luggage-log?_id=5fa2c79a6f265127c463bcb3' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjA0NDk5NjM5LCJleHAiOjE2MDQ1ODYwMzl9.o5hFJEH3kEUQjFopYxNx0hdeFjmx05F4WxMjpy_rTj0'

Response:
{
    "message": "deleted",
    "deletedCount": 1
}
```
