Locations - Proj-P/project-p-api GitHub Wiki

Get all locations

GET /locations

Response
Status: 200 OK
Content-Type: application/json
[
  {
    "average_duration": 146.2941176470588,
    "changed_at": "Thu, 12 Sep 2019 17:10:57 GMT",
    "id": 1,
    "name": "office toilet upstairs",
    "occupied": false
  },
  {
    "average_duration": 126.2941176470588,
    "changed_at": "Thu, 12 Sep 2019 17:10:57 GMT",
    "id": 1,
    "name": "office toilet downstairs",
    "occupied": false
  }
]

Get a location

GET /locations/:location_id

Response
Status: 200 OK
Content-Type: application/json
{
  "data": {
    "average_duration": 246.14285714285714,
    "changed_at": "Fri, 17 Jun 2016 03:39:59 GMT",
    "id": 1,
    "name": "Toilet downstairs",
    "occupied": false
  }
}

Get all visits by location

GET /locations/:location_id/visits

Response
Status: 200 OK
Content-Type: application/json
[
  {
    "duration": 10,
    "end_time": "Mon, 09 Sep 2019 11:45:32 GMT",
    "id": 1,
    "location_id": 1,
    "start_time": "Mon, 09 Sep 2019 11:45:22 GMT"
  },
  {
    "duration": 40,
    "end_time": "Mon, 09 Sep 2019 11:46:32 GMT",
    "id": 2,
    "location_id": 1,
    "start_time": "Mon, 09 Sep 2019 11:45:52 GMT"
  }
]

Get all visits by location id in a certain period

GET /locations/:location_id/visits/:from/:to

Response
Status: 200 OK
Content-Type: application/json
[
  {
    "duration": 10,
    "end_time": "Mon, 09 Sep 2019 11:45:32 GMT",
    "id": 1,
    "location_id": 1,
    "start_time": "Mon, 09 Sep 2019 11:45:22 GMT"
  },
  {
    "duration": 40,
    "end_time": "Mon, 09 Sep 2019 11:46:32 GMT",
    "id": 2,
    "location_id": 1,
    "start_time": "Mon, 09 Sep 2019 11:45:52 GMT"
  }
]

Set the status of a location

PUT /status

Response
Status: 200 Success
Content-Type: application/json
{
    "code": 200,
    "location": {
        "average_duration": 36.857142857142854,
        "changed_at": "Tue, 10 Sep 2019 15:42:44 GMT",
        "id": 1,
        "name": "office",
        "occupied": false
    },
    "message": "Location 1 updated succesfully."
}