---
# System prepended metadata

title: API SPEC

---

# API SPEC

**Entity**

| Users         | Menu       | Order       | TopSelling  | Table| OrderQueue | Summary |
| ------------- |--------    | ------      |-----        |----- |-----| --- |
| email (PK)    |idMenu (PK) |idOrder (PK) |id (PK)|idTable (PK) | id (PK) | totalRevenue
| username      |name        |datetime     |idMenu       | capacity (int) | idTable | totalCustomer
| displayName   |description |table        |month        |layout Point(x1: int,y1: int) | capacity | totalFnBOrdered
| password      |image       |people       |year         |validUntil | idOrder | month
| phoneNo       |price       |status       |quantity          | validFrom | timestamp | year
| role          | deleted           |menuQuantity [idMenu, price, quantity]  |             | active
| image         |            |email        |             |
| lastEdit |

Image using base64

## Login
* Endpoint : `/api/login`
* HTTP Method : `POST`
* Request Header : 
    * Accept : `application/json`
    * Content-type : `application/json`
* Notes : 
    * username and password is mandatory. username can be filled with user's username or email, and will be detected in BE (username/email) || nanti pass dihash
* Request Body : 
```
{
    "username" : "adminbetutu@ayambetutubali.com",
    "password" : "test123"
}
```
* Request Parameter : -
* Response Body (Success) : 
```
    "code" : 200,
    "status" : "OK",
    "data" : {
        "id" : "621312317134234",
        "displayName" : "Admin Betutu",
        "email" : "adminbetutu@ayambetutubali.com",
        "phoneNo": "089123456789",
        "role": "admin",
        "image": "",
        "token": "ufByr123bdO4NutI"
    }
```
* Response Body (Failure) : 
```
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error login"
    }
```

## Register
* Endpoint : `/api/register`
* HTTP Method : `POST`
* Request Header : 
    * Accept : `application/json`
    * Content-type : `application/json`
* Notes : `Jika mendaftarkan role admin, maka akan dicek token pendaftar, teregister sebagai admin`
* Request Body : 
```
{
    "username" : "adminbetutu",
    "displayName" : "Admin Betutu",
    "email" : "adminbetutu@ayambetutubali.com",
    "password" : "test123",
    "phoneNo" : "089123456789",
    "role" : "admin"
}
```
* Request Parameter : -
* Response Body (Success) : 
```
{
    "code" : 200,
    "status" : "OK",
    "data" : {
        "id" : "621312317134234",
        "displayName" : "Admin Betutu",
        "email" : "adminbetutu@ayambetutubali.com",
        "phoneNo" : "089123456789",
        "role" : "admin",
        "token" : "ufByr123bdO4NutI"
    }
}
```
* Response Body (Failure) : 
```
{
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error register"
    }
}
```

## Forgot Password
* Endpoint : `/api/login/forgot-password`
* HTTP Method : `POST`
* Request Header : 
    * Accept : `application/json`
    * Content-type : `application/json`
* Notes : 
    * After sending request body, backend will send password to the user's email. 
* Request Body : 
```
{
    "email" : "adminbetutu@ayambetutubali.com"
}
```
* Request Parameter : -
* Response Body (Success) : 
```
{
    "code" : 200,
    "status" : "OK",
    "data": {
        "message" : "We have sent to your email."
    }
}
```
* Response Body (Failure) : 
```
{
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        message" : "Failed to sent to your email."
    }
}
```
## Get Last Edit on Password
* Endpoint : `/api/login/lastedit-password/:id`
* HTTP Method : `GET`
* Request Header : 
    * Accept : `application/json`
    * Authorization : `token`
    * Content-type : `application/json`
* Notes : 
* Request Body : -
* Request Parameter : -
* Response Body (Success) : 
```
{
    "code" : 200,
    "status" : "OK",
    "data": {
        "lastEdit" : 1616300578057
    }
}
```
* Response Body (Failure) : 
```
{
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        message" : "Error get last edit on password"
    }
}
```

## Edit Profile

* Endpoint : `/api/profile/:id`
* HTTP Method : `PUT`
* Request Header : 
    * Accept : `application/json`
    * Authorization : `token`
    * Content-type : `application/json`
* Notes : jika password berganti, maka last edit password diupdate
* Request Body : 
```
{
    "displayName": "adminbetutu",
    "phoneNo" : "089123456789",
    "currentPassword" : "test123",
    "newPassword" : "change123"
}
```
* Request Parameter : -
* Response Body (Success) : 
```
    "code" : "200",
    "status" : "OK",
    "data" : {
        "message" : "Profile has been updated"
    }
```
* Response Body (Failure) : 
```
    "code" : "400",
    "status" : "Bad Request",
    "data" : {
        "message" : "Error updating profile"
    }
```

## Get Order by Email
* Endpoint : `/api/order`
* HTTP Method : `GET`
* Request Header : 
    * Authorization : `token`
* Notes : 
* Request Body : -
* Request Parameter : email
* Response Body (Success) : 
```
{
    "code" : 200,
    "status" : "OK",
    "data": [{
        "idOrder" : 1,
        "datetime" : 1616300578057,
        "table" : 5,
        "people" : 4,
        "status": "waiting",
        "menuQuantity" : [
            {
                "menu" : {
                    "id" : "1fewuhuifhiwe",
                    "name" : "Ayam Betutu",
                    "description" : "Ayam betutu paling enak",
                    "image" : "",
                    "price" : 120000
                },
                quantity: 3,
            },
            {
                "menu" : {
                    "id" : 2,
                    "name" : "Es Jeruk",
                    "description" : "Es Jeruk segar",
                    "image" : "",
                    "price" : 12000
                },
                quantity: 4,
            }
        ],
        "email": "kevin@gmail.com"
    }]
}
```
* Response Body (Failure) : 
```
{
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error get order by email"
    }
}
```


## Get Order By Id
* Endpoint : `/api/order/:id`
* HTTP Method : `GET`
* Request Header : 
    * Authorization : `token`
* Notes : -
* Request Body : - 
* Request Parameter : -
* Response Body : 
```
{
    "code" : 200,
    "status" : "OK",
    "data" : {
        "datetime" : 1616300578057,
        "table" : 5,
        "people" : 4,
        "status" : "approved",
        "menuQuantity" : [
            {
                "menu" : {
                    "id" : 1,
                    "name" : "Ayam Betutu",
                    "description" : "Ayam betutu paling enak",
                    "image" : "",
                    "price" : 120000
                },
                quantity: 3
            },
            {
                "menu" : {
                    "id" : 2,
                    "name" : "Es Jeruk",
                    "description" : "Es Jeruk segar",
                    "image" : "",
                    "price" : 12000
                },
                quantity: 4
            } 
        ],
        "email": "kevin@gmail.com"
    }
}
```
* Response Body (Failure) : 
```
{
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error get order by id"
    }
}
```

## Add New Order
* Endpoint : `/api/order`
* HTTP Method : `POST`
* Request Header : 
    * Accept : `application/json`
    * Authorization : `token`
    * Content-type : `application/json`
* Notes : Backend mengurus email dan status ("waiting"). Backend juga akan mengecek orderTimeStampList pada Table. (Hanya mengecek, pemasukan ke orderTimeStampList dilakukan jika sudah diapprove)
* Request Body : 
```
{
    "datetime" : 1616300578057,
    "table" : 3,
    "people": 2
    "menuQuantity" : [
        {
            "menuId" : "1fferhggr",
            "price": 30000,
            "quantity" : 2
        } 
    ],
}

```
* Request Parameter : -
* Response Body (Success) : 
```
{    
    "code" : 200,
    "status" : "OK",
    "data" : {
        "idOrder": 23
        "message" : "Done making new order"
    }
}
```
* Response Body (Failure) : 
```
{    
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error add new order"
    }
}
```

## Update Order
* Endpoint : `/api/order/:id`
* HTTP Method : `PUT`
* Request Header : 
    * Accept : `application/json`
    * Authorization : `token`
    * Content-type : `application/json`
* Notes : front end tetap mengirim menu lengkap. Status can be changed into approved or declined. Saat approve, tambahkan data ke OrderQueue, dan otomatis decline seluruh order di table tersebut pada jam yang bertabrakan
* Request Body : 
```
{
    "menuQuantity": [
        {
            "menuId" : 1,
            "quantity" : 3,
            "price": 13000
        },
    ],
    "status" : "approved"
}
```
* Request Parameter : -
* Response Body (Success) : 
```
{
    "code" : 200,
    "status" : "OK",
    "data" : {
        "message" : "Order updated"
    }
}
```
* Response Body (Failure) : 
```
{
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error updating order"
    }
}
```

## Get Top Selling
* Endpoint : `/api/top-selling`
* HTTP Method : `GET`
* Request Header : -
* Notes : -
* Request Body : -
* Request Parameter : month & year
* Response Body (Success) : 
```
{
    "code" : 200,
    "status" : "OK",
    "data" : [{
        "menu" : {
            "id" : "1ifwh",
            "name" : "Ayam Betutu",
            "description" : "Ayam betutu paling enak",
            "image" : "",
            "price" : 120000
        },
        "month": "January",
        "year": 2021,
        "quantity": 30
    }]
}
```
* Response Body (Failure) : 
```
{
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error get summary"
    }
}
```

## Get Menu
* Endpoint : `/api/menu`
* HTTP Method : `GET`
* Request Header : -
* Notes : -
* Request Body : -
* Request Parameter : -
* Response Body (Success) : 
```
{
    "code" : 200,
    "status" : "OK",
    "data" : [{
        "id" : "hfw7y7Hjfd",
        "name" : "Ayam bakar",
        "description" : "Ayam bakar khas nusantara",
        "image" : ,
        "price": 23000
    }]
}
```
* Response Body (Failure) : 
```
{
    "code" : 500,
    "status" : "Internal Server Error",
    "data" : {
        "message" : "There is an error"
    }
}
```


## Update Menu
* Endpoint : `/api/menu/:id`
* HTTP Method : `PUT`
* Request Header : 
    * Accept : `application/json`
    * Authorization: `token`
    * Content-type : `application/json`
* Notes : -
* Request Body : 
```
{
    "name" : "Ayam Betutu",
    "description" : "Ayam betutu paling enak",
    "image" : "",
    "price" : 120000
}
```
* Request Parameter : -
* Response Body (Success) : 
```
{
    "code" : 200,
    "status" : "OK",
    "data" : {
        "message": "Menu update success"
    }
}
```
* Response Body (Failure) : 
```
{
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error update menu"
    }
}
```

## Add New Menu
* Endpoint : `/api/menu`
* HTTP Method : `POST`
* Request Header : 
    * Accept : `application/json`
    * Authorization: `token`
    * Content-type : `application/json`
* Notes : -
* Request Body : 
```
{
    "name" : "Ayam Betutu",
    "description" : "Ayam betutu paling enak",
    "image" : "",
    "price" : 120000
}
```
* Request Parameter : -
* Response Body (Success) : 
```
{
    "code" : 201,
    "status" : "Created",
    "data" : {
        "message" : "Menu has been created"
    }
}
```
* Response Body (Failure) : 
```
{
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error add new menu"
    }
}
```

## Delete Menu
* Endpoint : `/api/menu/:id`
* HTTP Method : `DELETE`
* Request Header : 
    * Authorization: `token`
* Notes : -
* Request Body : -
* Request Parameter : -
* Response Body (Success) : 
```
{
    "code" : 200,
    "status" : "OK",
    "data" : {
        "message" : "Menu has been deleted"
    }
}
```
* Response Body (Failure) : 
```
{
    "code" : 404,
    "status" : "Not Found",
    "data" : {
        "message" : "Id Menu not found"
    }
}
```

## Check Availability
* Endpoint : `/api/available`
* HTTP Method : `GET`
* Request Header : -
* Notes : -
* Request Body : 
* Request Parameter : datetime (Long) & people (Int)
* Response Body (Success) : 
```
{
    "code" : 200,
    "status" : "OK",
    "data" : {
        "tableIds" : [2,3,5]
    }
}
```
* Response Body (Failure) : 
```
{
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error check availability"
    }
}
```

## Get Summary
* Endpoint : `/api/summary`
* HTTP Method : `GET`
* Request Header : 
    * Authorization: `token`
* Notes : sudah disort di backend
* Request Body : -
* Request Parameter : year & month
* Response Body (Success) : 
```
    "code" : 200,
    "status" : "OK",
    "data" : {
        "totalRevenue" : 100000,
        "totalCustomer" : 50000,
        "totalFnBOrdered" : 80000,
        "topSelling" : [
            {
                "menu" : {
                    "idMenu" : 1,
                    "name" : "Ayam Betutu",
                    "description" : "Ayam betutu paling enak",
                    "image" : "",
                    "price" : 120000
                },
                "quantity": 30,
                "month": "July",
                "year": 2021
            }
        ]
    }
```
* Response Body (Failure) : 
```
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error get summary"
    }
```


## Billing
* Endpoint : `/api/billing`
* HTTP Method : `POST`
* Request Header : 
    * Accept : `application/json`
    * Authorization: `token`
    * Content-type : `application/json`
* Notes : 
    * After sending request body, the billing will be send to user's email, sama habis itu masukin ke top-selling dan summary. Setelah itu, remove order yang bersangkutan dari OrderQueue dan ubah status di Order dari approved menjadi completed
* Request Body : 
```
{
    "idOrder" : 2,
    "email" : "adminbetutu@ayambetutubali.com"
}
```
* Request Parameter : -
* Response Body (Success) : 
```
    "code" : 200,
    "status" : "OK",
    "data" : {
        "message" : "We have sent billing to your email"
    }
```
* Response Body (Failure) : 
```
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error Sending Billing"
    }
```
* Email body:
```
Thank you for your order. This is your detailed order on Sunday, June 20, 2020.

Table ID: 4
Number of People: 4

3x 40.000 Ayam Betutu
2x 10.000 Es Teh

Total: IDR 150.000

We hope you have great experience with us. 
```

## Get Table Layout
* Endpoint : `/api/table`
* HTTP Method : `GET`
* Request Header : 
    * Accept : `application/json`
    * Authorization: `token`
    * Content-type : `application/json`
* Notes : 
* Request Body : -
* Request Parameter : datetime (long)
* Response Body (Success) : 
```
    "code" : 200,
    "status" : "OK",
    "data" : 
    [
            {
                "id": "60b340c949a34511e811df48",
                "idTable": 1,
                "capacity": 4,
                "active": true
                "layout": {
                    "x": 1,
                    "y": 1
                }
            },
            {
                "id": "60b340c949a34511e811df49",
                "idTable": 2,
                "capacity": 6,
                "active": false
                "layout": {
                    "x": 1,
                    "y": 2
                }
            }
        ]
```
* Response Body (Failure) : 
```
    "code" : 400,
    "status" : "Bad Request",
    "data" : {
        "message" : "Error Sending Billing"
    }
```


## Update Table Layout
* Endpoint : `/api/table`
* HTTP Method : `POST`
* Request Header : 
    * Accept : `application/json`
    * Authorization: `token`
    * Content-type : `application/json`
* Notes : `FE mengirimkan seluruh data table`
* Request Body : 
```
    "validFrom": 4937234831432,
    "tableLayouts": [
        {
            "idTable": 1,
            "capacity": 4,
            "active": true
            "layout": {
                "x": 1,
                "y": 1
            }
        },
        {
            "idTable": 2,
            "capacity": 6,
            "active": false
            "layout": {
                "x": 1,
                "y": 2
            }
        }
    ]
```
* Request Parameter : -
* Response Body (Success) : 
```
    "code" : 200,
    "status" : "OK",
    "data" : "Table updated successfully"
```
* Response Body (Failure) : 
```
    "code" : 400,
    "status" : "Bad Request",
    "data" : "Error update table"
```