---
# System prepended metadata

title: User-Mobile

---

# User-Mobile
# Retrieves all unavailable slot for a facility for a date sorted by the earliest to latest unavailable slot


## Request format:
```
GET /api/facility/{facilityID}/date/{date}/unavailableslots

Authorization: Bearer {jwt_token}
```

## Response format

### With data found
```
HTTP 200 OK

Content-Type: application/json
{
  "data":{
    "bookings":[
      {
          "type":"BOOKING",
          "booking_id":"{bookingID}",
          "start_datetime": "{bookingStartTime}",
          "end_datetime":"{bookingEndTime}",
          "booking_name":"{bookingName}",
          "booking_contact": "{bookingContact}",
          "booker_name":"{bookerName}",
          "booking_status":"{bookingStatus}",
          "facility":{
            "facility_id":"{facilityID}",
            "facility_name":"{facilityName}"
          }
        },
        {
          "type":"BOOKING",
          "booking_id":"{bookingID}",
          "start_datetime": "{bookingStartTime}",
          "end_datetime":"{bookingEndTime}",
          "booking_name":"{bookingName}",
          "booking_contact": "{bookingContact}",
          "booker_name":"{bookerName}",
          "booking_status":"{bookingStatus}",
          "facility":{
            "facility_id":"{facilityID}",
            "facility_name":"{facilityName}"
          }
        },
        {
          "type":"MAINTENANCE",
          "maintenance_id":"{maintainanceid}",
          "start_datetime": "{startDatetime}",
          "end_datetime":"{bookingEndTime}",
          "facility":{
            "facility_id":"{facilityID}",
            "facility_name":"{facilityName}"
          }
        },
        {
          "type":"MAINTENANCE",
          "maintenance_id":"{maintainanceid}",
          "start_datetime": "{startDatetime}",
          "end_datetime":"{bookingEndTime}",
          "facility":{
            "facility_id":"{facilityID}",
            "facility_name":"{facilityName}"
          }
        } 
      ],
  }
}
```

### With no data found
```
HTTP 404 Not Found

Content-Type: application/json
{
  "error":{
    "message":"No unavailable event slots"
  }
}
```

# Retrieve all pending bookings for facility and date
```
GET /api/facility/{facilityID}/date/{date}/bookings/pending

Content-Type: application/json
{
  "data":{
    "pending_bookings":[
        {
          "booking_id":"{bookingID}",
          "start_datetime": "{bookingStartTime}",
          "end_datetime":"{bookingEndTime}",
          "booking_name":"{bookingName}",
          "booking_contact": "{bookingContact}",
          "booker_name":"{bookerName}",
          "booking_status":"{bookingStatus}",
          "facility":{
            "facility_id":"{facilityID}",
            "facility_name":"{facilityName}"
          }
        },
        {
          "booking_id":"{bookingID}",
          "start_datetime": "{bookingStartTime}",
          "end_datetime":"{bookingEndTime}",
          "booking_name":"{bookingName}",
          "booking_contact": "{bookingContact}",
          "booker_name":"{bookerName}",
          "booking_status":"{bookingStatus}",
          "facility":{
            "facility_id":"{facilityID}",
            "facility_name":"{facilityName}"
          }
        }
    ]
  }
}
```


# Retrieves all bookings of a user.

## Request format
```
GET /api/bookings

Authorization: Bearer {jwt_token}
```

## Response format 

### With bookings found
```
HTTP 200 OK

Content-Type: application/json
{
  "data":{
    "bookings":[
        {
          "booking_id":"{bookingID}",
          "start_datetime": "{bookingStartTime}",
          "end_datetime":"{bookingEndTime}",
          "booking_name":"{bookingName}",
          "booking_contact": "{bookingContact}",
          "booker_name":"{bookerName}",
          "booking_status":"{bookingStatus}",
          "facility":{
            "facility_id":"{facilityID}",
            "facility_name":"{facilityName}"
          }
        },
        {
          "booking_id":"{bookingID}",
          "start_datetime": "{bookingStartTime}",
          "end_datetime":"{bookingEndTime}",
          "booking_name":"{bookingName}",
          "booking_contact": "{bookingContact}",
          "booker_name":"{bookerName}",
          "booking_status":"{bookingStatus}",
          "facility":{
            "facility_id":"{facilityID}",
            "facility_name":"{facilityName}"
          }
        },
      ]
  }
}
```

### No Data found

```
HTTP 404 Not Found

{
  "error":{
    "message":"No bookings found"
  }
}
```

# Retrieves a particular booking information

## Request
```
GET /api/booking/{bookingID}
Authorization: Bearer {jwt_token}
```
## Response
### Data found
```
Authorization: Bearer {jwt_token}
Content-Type: application/json
{
  "data":{
    "booking":{
          "booking_id":"{bookingID}",
          "start_datetime": "{bookingStartTime}",
          "end_datetime":"{bookingEndTime}",
          "booking_name":"{bookingName}",
          "booking_contact": "{bookingContact}",
          "booker_name":"{bookerName}",
          "booking_status":"{bookingStatus}",
          "facility":{
            "facility_id":"{facilityID}",
            "facility_name":"{facilityName}"
          }
        },
    }
}
```

### Data not found
```
HTTP 404 Not Found

Content-Type: application/json
{
  "error":{
    "message":"Booking not found"
  }
}
```

# Retrieves all facilities
## Request Format
```
GET /api/facilities
```

## Response Format

### With data found
```
HTTP 200 OK

{
  "data":{
    "facilities":[
    {
      "facility_id":"1",
      "facility_name":"Sports Hall"
    },
    {
      "facility_id":"2",
      "facility_name":"Sports Hall 2"
    },
    {
      "facility_id":"3",
      "facility_name":"Sports Hall 3"
    }
  ]
  }
}
```

### with no data found

```
HTTP 404 Not Found

Content-Type: application/json
{
  "error":{
    "message":"No facilities found"
  }
}
```

# First factor Login
## Request format
```
POST /api/login

{
  "username":"{username}",
  "password":"{password}"
  
}
```

## Response format
`phone_number` registered phone number.

### Username and password found
```
HTTP 200 OK

{
  "data":{
    "phone_number":"82738213",
    "user_id": "3"
  }
}
```

### Username or password not found

```
HTTP 404 Not Found

Content-Type: application/json
{
  "error":{
    "message": "Account Not Found"
  }
}
```

# Request JWT
This api should return a jwt after validating  the input verificationid with firebase server.

## Request
```
POST /api/jwt
Content-Type: application/json

{
  "verification_id":"{verification_id}",
  "user_id": "3"
}
```

## Response
### Success

```
HTTP 200 OK
Content-Type: application/json

{
  "data":{
    "token":"token",
    "default_password":false,
    "user":{
      "user_id": 6,
      "full_name": {fullName},
      "username": {userName},
      "phone_number": {phoneNumber},
      "number_of_booking_cancellation": {numberOfCancellation}
    }
  }
}
```
### User still using default password

```
HTTP 200 OK
Content-Type: application/json

{
  "data":{
    "token":"token",
    "default_password":true,
    "user":{
      "user_id": 6,
      "fullName": {fullName},
      "userName": {userName},
      "phoneNumber": {phoneNumber},
      "numberOfConfirmedBookingCancellation": {numberOfCancellation}
    }
  }
}
```
### Cannot be verified on firebase
```
HTTP 404 Not Found
Content-Type: application/json

{
  "error":{
    "message":"User not authenticated"
  }
}
```

### User not did not perform first factor login
```
HTTP 401 Unauthorized
Content-Type: application/json

{
  "error":{
    "message":"Requires login first"
  }
}
```


# Delete a booking
## Request format
```
DELETE /api/bookings/{bookingID}
```

## Response format

### Booking found and deleted
```
HTTP 200 OK

Content-Type: application/json
{
  "data":{
    "status":"deleted"
  }
}
```

### Booking not found
```
HTTP 404 Not Found

Content-Type: application/json
{
  "error":{
    "message":"Booking not found"
  }
}
```
# Update Password

## Request
```
POST /password

{
  userID: {userID}
  userName: {userName},
  password: {password}
}
```

## Response success
```
HTTP 200 OK
Content-Type: application/json

{
  "data":{
    "token":"token"
  }
}

```

## Response fail password in wrong format

```
HTTP 422 Unprocessable Entity
{
    "password": [
        "Password does not meet the criteria of minimum length of 8 and minimum 1 lower cased, 1 upper case and must contain at least a number."
    ]
}
```
## Response fail
```
HTTP 404 Not Found
{
    "error": {
        "message": "Update password not required"
    }
}
```
# Register FCM token

## Request
```
POST /fcm/token
Authorization: Bearer {jwttoken}
{
  "token":"{fcmtoken}"
}
```

## Response
```
HTTP 200 OK
```

# Make booking

## Request
```
POST /api/bookings
Authorization: Bearer {jwttoken}

{
  "booking_name":"booking name",
  "facility_id": 4,
  "start_datetime": "2019-08-13 00:59:00",
  "end_datetime": "2019-08-14 00:59:00"
}
```

## Response
Returns the created record if success
```
HTTP 201 Created
Content-Type: application/json

{
  "data":{
    "booking":{
          "booking_id":"{bookingID}",
          "start_datetime": "{bookingStartTime}",
          "end_datetime":"{bookingEndTime}",
          "booking_name":"{bookingName}",
          "booking_contact": "{bookingContact}",
          "booker_name":"{bookerName}",
          "booking_status":"PENDING",
          "facility":{
            "facility_id":"{facilityID}",
            "facility_name":"{facilityName}"
          }
        },
    }
  }
}
```

# Get all full booking dates
Returns the unavailable dates for a month

## Request
```
GET /facility/{facilityID}/startdate/{startdate}/enddate/{enddate}/unavailabledays
```

## Response
### With Data found
```
HTTP 200 OK
{
  "data":{
    "unavailable_days":[
      "datestring",
      "datestring",
      "datestring",
      "datestring"
    ]
  }
}
```

### With no data found
```
HTTP 404 Not Found

{
  "error":{
    "message":"No unavailable dates"s
  }
}
```
# Update Username
Update username of user. New username can be the same as old one.

## Request
```
PUT /username
Content-Type: application/json
{
  "user_name":"new_username"
}
```

## Response
### Success
```
HTTP 200 OK

Content-Type: application/json
{
  "data":{
    "user":{
      "user_id": 6,
      "full_name": {fullName},
      "user_name": {new user name},
      "phone_number": {phoneNumber},
      "number_of_booking_cancellation": {numberOfCancellation}
    }
  }
}
```

### Failure
#### Username not found

```
HTTP 404 Not Found
Content-Type: application/json
{
  "error":{
    "message": "username not found"
  }
}
```

#### Username alr exist 
```
HTTP 409 Conflict
Content-Type: application/json

{
  "error":{
    "message":"Username already exists"
  }
}
```

# Change Password
This is different from Update Password where change password requires user to provide the current password to authenticate himself before changing to a new password. Success of this operation should immediately invalidate the old jwt.
## Request
```
PUT /password

{
  "old_password":"oldpassword"
  "new_password":"new password"
}
```

## Response

### Success 
```
HTTP 200 OK
Content-Type: application/json
{
  "data":{
    "token":"token",
    "default_password":false,
    "user":{
      "user_id": 6,
      "full_name": {fullName},
      "username": {userName},
      "phone_number": {phoneNumber},
      "number_of_booking_cancellation": {numberOfCancellation}
    }
  }
}
```

### Failure
#### Wrong Password
```
HTTP 404 Not Found
Content-Type: application/json
{
  "error":{
    "message": "Wrong password"
  }
}
```

# Logout

## Request
```
DELETE /logout
```

## Response
### Success
```
{
  "data":{
    "message":"Successfully logged out"
  }
}
```

# Forget password


## Request
```
POST /passwordreset

{
  "user_name":"username"
}
```

## Response

```
HTTP 200 OK

{
  "data":{
    "status":"Resetted",
    "message":"Password reset request has been submitted"
  }
}
```




# FCM PAYLOAD STRUCTURE
## Approved notification
```
{
 "to":"fRyERNOIOfA:APA91bFbLFjSdd7i876AZN1xJDF6Mm-CywyCTAjsaA2SRy_Py8KOvlwdI1ZY8Ugk915hBA9JO6O3T-ZZ6wx0vdqduhoefWJETZYI-NuLjOe3A9mredoqYN4SGZ-y7IdniLts4Mv8OAGz",
  "priority" : "normal",
  "notification" : {
    "body" : "Your Booking has been accepted!",
    "title": "Booking status for {facilityname} on {date}"
 },
  "data" : {
    "click_action":"FLUTTER_CLICK_NOTIFICATION",
    "booking_id":3,
    "subject": "BOOKING_STATUS_UPDATE",
    "status" : "APPROVED",
 }
}
```

## REJECTED NOTIFICATION
```
{
 "to":"fRyERNOIOfA:APA91bFbLFjSdd7i876AZN1xJDF6Mm-CywyCTAjsaA2SRy_Py8KOvlwdI1ZY8Ugk915hBA9JO6O3T-ZZ6wx0vdqduhoefWJETZYI-NuLjOe3A9mredoqYN4SGZ-y7IdniLts4Mv8OAGz",
  "priority" : "normal",
  "notification" : {
    "body" : "Your Booking has been accepted!",
    "title": "Booking status for {facilityname} on {date}"
 },
  "data" : {
    "click_action":"FLUTTER_CLICK_NOTIFICATION",
    "booking_id":3,
    "subject": "BOOKING_STATUS_UPDATE",
    "status" : "REJECTED",
    "booking_facility_name":"Facility Name",
    "booking_start_date":"123",
    "booking_end_date":"456"
 }
}
```