Skip to content

Detailed API description

Mikhail edited this page May 29, 2022 · 1 revision

DAO API

Addresses, dao/address

Action Path Method Request object example Response object example
Create a new address dao/address POST { "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13", "flat": 23 } "result": { "addressId": 12, "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13", "flat": 23, "lat": 60.3453, "lon": 40.1234 }
Read address by id dao/address/read/:id GET "result": { "addressId": 13, "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13", "flat": 23, "lon": 24.931452, "lat": 60.17138 }
Read all addresses dao/address GET "result": [ { "addressId": 13, "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13", "flat": 23, "lon": 24.931452, "lat": 60.17138 } ]
Search for address dao/address/ search?city= Helsinki&street=Pohjoinen Rautatiekatu GET "result": [ { "addressId": 13, "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13", "flat": 23, "lon": 24.931452, "lat": 60.17138 } ]

Address request and response objects fields are described in DAO and database description section

Areas, dao/area

Action Path Method Request object example Response object example
Create a new area dao/area POST { "areaName": "SomeArea", "type": "Polygon", "coordinates": [ [ [25.654878616333004, 60.98514074901049], [25.671615600585938, 60.979353511636425], [25.668354034423825, 60.98426648575919], [25.654878616333004, 60.98514074901049] ] ] } "result": { "areaName": "SomeArea", "type": "Polygon", "coordinates": [ { "coordinateId": 40855, "areaName": "SomeArea", "polygonNumber": 0, "orderNumber": 0, "lon": 25.654878616333004, "lat": 60.98514074901049 }, …rest of the coordinates ] }
Create multiple new areas dao/area/multiple POST [ { "areaName": "SomeArea", "type": "Polygon", "coordinates": [ [ [25.654878616333004, 60.98514074901049], [25.671615600585938, 60.979353511636425], [25.668354034423825, 60.98426648575919], [25.654878616333004, 60.98514074901049] ] ] } ] "result": [ { "areaName": "SomeArea", "type": "Polygon" } ]
Read area by name dao/area/:areaName GET result:{ { "type": "Polygon", "coordinates": [ [ [25.654878616333004, 60.98514074901049], [25.671615600585938, 60.979353511636425], [25.668354034423825, 60.98426648575919], [25.654878616333004, 60.98514074901049] ] ] } }
Read all areas dao/area GET result:[ { "type": "Polygon", "coordinates": [ [ [25.654878616333004, 60.98514074901049], [25.671615600585938, 60.979353511636425], [25.668354034423825, 60.98426648575919], [25.654878616333004, 60.98514074901049] ] ] } ]
Update an area dao/area/:areaName PUT { "areaName": "SomeArea", "type": "Polygon", "coordinates": [ [ [20.654878616333004, 63.98514074901049], [20.671615600585938, 63.979353511636425], [20.668354034423825, 63.98426648575919], [20.654878616333004, 63.98514074901049] ] ] } { "isSuccess": true }
Delete area by name dao/area/:areaName DELETE { "isSuccess": true }

Area request and response objects fields are described in DAO and database description section

Clients, dao/client

Action Path Method Request object example Response object example
Create a new client dao/client POST { "clientUsername": "john", "name": "John Smith", "addressAdd": { "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13" } } "result": { "clientUsername": "john", "name": "John Smith", "addressAdd": { "addressId": 14, "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13", "lon": 24.931452, "lat": 60.17138 } }
Read a client by username dao/client/:clientUsername GET "result": { "clientUsername": "john", "name": "John Smith", "Addresses": [ { "addressId": 14, "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13", "flat": null, "lon": 24.931452, "lat": 60.17138, "AsDeliveryAddress": { "clientUsername": "john", "addressId": 14 } } ] }
Read all clients dao/client GET "result": [ "clientUsername": "john", "name": "John Smith", "Addresses": [ { "addressId": 14, "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13", "flat": null, "lon": 24.931452, "lat": 60.17138, "AsDeliveryAddress": { "clientUsername": "john", "addressId": 14 } } ] ]
Update client data dao/client PUT { "clientUsername": "john", "name": "John Smith", "addressAdd": { "city": "Helsinki", "street": "Kotkankatu", "building": "7" }, "addressDelete": { "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13" } } { "isSuccess": true }
Delete client by username dao/client/:clientUsername DELETE { "isSuccess": true }

addressAdd field in the request object means address to add to the client addressDelete field in the request object means address to delete from the client Other Client request and response objects fields are described in DAO and database description section

Manufacturer, dao/manufacturer

Action Path Method Request object example Response object example
Create a new manufacturer dao/manufacturer POST { "manufacturerUsername": "john", "name": "John Smith", "addressAdd": { "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13" } } "result": { "manufacturerUsername": "john", "name": "John Smith", "addressAdd": { "addressId": 14, "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13", "lon": 24.931452, "lat": 60.17138 } }
Read a manufacturer by username dao/manufacturer/:manufacturerUsername GET "result": { "manufacturerUsername": "john", "name": "John Smith", "Addresses": [ { "addressId": 14, "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13", "flat": null, "lon": 24.931452, "lat": 60.17138, "AsShipmentAddress": { "manufacturerUsername": "john", "addressId": 14 } } ] }
Read all manufacturer dao/manufacturer GET "result": [ "manufacturerUsername": "john", "name": "John Smith", "Addresses": [ { "addressId": 14, "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13", "flat": null, "lon": 24.931452, "lat": 60.17138, "AsShipmentAddress": { "manufacturerUsername": "john", "addressId": 14 } } ] ]
Update manufacturer data dao/manufacturer PUT { "manufacturerUsername": "john", "name": "John Smith", "addressAdd": { "city": "Helsinki", "street": "Kotkankatu", "building": "7" }, "addressDelete": { "city": "Helsinki", "street": "Pohjoinen Rautatiekatu", "building": "13" } } { "isSuccess": true }
Delete manufacturer by username dao/manufacturer/:manufacturerUsername DELETE { "isSuccess": true }

addressAdd field in the request object means address to add to the manufacturer addressDelete field in the request object means address to delete from the manufacturer Other Manufacturer request and response objects fields are described in DAO and database description section.

Data, dao/data

Action Path Method Request object example Response object example
Create a new data dao/data POST { "name": "electricityPrice", "value": "3" } "result": { "name": "electricityPrice", "value": "3" }
Read a data by name dao/data/:name GET "result": { "name": "electricityPrice", "value": "3", "lastUpdated": "2022-05-27T13:58:56.000Z" }
Read all data dao/data GET "result": [ "name": "electricityPrice", "value": "3", "lastUpdated": "2022-05-27T13:58:56.000Z" ]
Update data dao/data PUT { "name": "electricityPrice", "value": "5" } { "isSuccess": true }
Delete data by name dao/data/:name DELETE { "isSuccess": true }

Data request and response objects fields are described in DAO and database description section

Order, dao/order

Action Path Method Request object example Response object example
Create a new order dao/order POST { "manufacturerUsername": "ruoka", "clientUsername": "janne", "shipmentAddressId": 3, "deliveryAddressId": 10 } "result": { "orderId": 9, "manufacturerUsername": "ruoka", "clientUsername": "janne", "shipmentAddressId": 3, "deliveryAddressId": 10 }
Read order by order id dao/order/:orderId GET "result": { "orderId": 9, "manufacturerUsername": "ruoka", "clientUsername": "janne", "shipmentAddressId": 3, "deliveryAddressId": 10, "Manufacturer": { "manufacturerUsername": "ruoka", "name": "Ruoka Läheltä Oy" }, "Client": { "clientUsername": "janne", "name": "Janne Metsänen" }, "shipmentAddress": { "addressId": 3, "city": "Helsinki", "street": "Alakiventie", "building": "1", "flat": null, "lon": 25.075149, "lat": 60.222781 }, "deliveryAddress": { "addressId": 10, "city": "Helsinki", "street": "Saarankatu ", "building": "2", "flat": null, "lon": 24.922761, "lat": 60.199726 } }
Read all orders dao/order GET "result": [{ "orderId": 9, "manufacturerUsername": "ruoka", "clientUsername": "janne", "shipmentAddressId": 3, "deliveryAddressId": 10, "Manufacturer": { "manufacturerUsername": "ruoka", "name": "Ruoka Läheltä Oy" }, "Client": { "clientUsername": "janne", "name": "Janne Metsänen" }, "shipmentAddress": { "addressId": 3, "city": "Helsinki", "street": "Alakiventie", "building": "1", "flat": null, "lon": 25.075149, "lat": 60.222781 }, "deliveryAddress": { "addressId": 10, "city": "Helsinki", "street": "Saarankatu ", "building": "2", "flat": null, "lon": 24.922761, "lat": 60.199726 } } ]
Update an order dao/order PUT { "orderId": 9, "manufacturerUsername": "lahden_ruoka", "clientUsername": "janne", "shipmentAddressId": 7, "deliveryAddressId": 10 } { "isSuccess": true }
Delete order by id dao/order/:orderId DELETE { "isSuccess": true }

Routing API

Addresses search, api/v1/address

Action Path examples Method Request object example Response object example
Search addresses by street address api/v1/address/search?text=rantatie GET [ { "name": "Rantatie", "street": "Rantatie", "county": "Vakka-Suomi", "country": "Finland", "macroregion": "Southwest Finland", "region": "Southwest Finland", "label": "Rantatie, Vehmaa, Finland", "coordinates": { "lon": 21.698199, "lat": 60.618656 } } ]
Addresses autocomplete api/v1/address/autocomplete?text=ranta GET [ { "name": "Rantasalmi", "county": "Savonlinna", "country": "Finland", "macroregion": "Eastern Finland", "region": "Southern Savonia", "label": "Rantasalmi, Finland", "coordinates": { "lon": 28.30421, "lat": 62.063429 } }, …max 25 other addresses ]
Search addresses by street address (GeoJSON output) api/v1/address/geojson?text=rantatie GET GeoJSON object with found addresses
Reverse geocode api/v1/address/geocode?lon=24.94341806541326&lat=60.19201503975161 GET { "type": "address", "streetAddress": "Kotkankatu 7", "city": "Helsinki", "coordinates": [ 24.943366, 60.192058 ] }

All of the requests are made by GET-method. Most of the requests are made straight via Openroute service and more information about response objects fields can be found from Openroute service documentation. Below is a description of path query parameters:

  1. text search text, string
  2. lat latitude coordinate, double
  3. lon longitude coordinate, double

Routing, api/v1/routing

Action Path Method Request object example Response object example
Calculate route by coordinates api/v1/routing POST { "coordinates":[ [25.075149, 60.222781], [24.943523, 60.199091] ], "fuelusage": 8.9 } Route in GeoJSON format
Calculate route by order ids api/v1/routing/orders POST {"orderIds": [2,3], "start" : 2, "end" : 3, "fuelusage": 5.7, "isCenterAvoided": true, "isTrafficSituation": true} Route in GeoJSON format

Routing requests can be made by coordinates or by order id numbers. The difference between these methods is that requesting by order id numbers contains more options and solves the travel salesman problem. In both methods routing is optimized using the VRoom project. Response objects are in GeoJSON standard form and description of the standard can be found from GeoJSON documentation. Below is a description of request objects fields:

  1. coordinates coordinates of places to be visited, array with arrays in form [longitude, latitude]
  2. fuelUsage average fuel usage of the vehicle per 100 km, float
  3. orderIds OrderData SQL table id numbers of the orders to be performed, integer
  4. start/end route start/end point, can be order id number(integer) or coordinate array([longitude, latitude]])
  5. isCenterAvoided flag, which determines should city centers be avoided in the routing or not. If there is a place to be visited in the city center, then the route will go via this city center, i.e. this center will be ignored. Cities center areas can be added by user and instructions for that can be found in the Detailed instructions section. True for to be avoided, false for not
  6. isTrafficSituation flag, which determines should traffic situation be taken into account or not. In other words if traffic on a road is slow, this road will be avoided in the routing calculation. True for to be taken into account, false for not.