From 35e2dcb8da6ffff0861a9c3dfb7ffa37cef63041 Mon Sep 17 00:00:00 2001 From: rui hildt Date: Sat, 8 Feb 2020 20:50:22 +0100 Subject: [PATCH] Add Readme --- README.md | 122 ++++++++++++++++++++++++++++++++++++++++ data/seeds/02-cities.js | 8 +-- index.js | 2 +- 3 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..aa01398 --- /dev/null +++ b/README.md @@ -0,0 +1,122 @@ +# dijkstra-backend + +Dijkstra is an app thas uses Dijkstra algorithm to display the shortest path between different cities in Belgium. + +Deployed backend: https://dijkstra-rui.herokuapp.com/ + +## API Documentation +___ +> Values required in **`bold`**. + +### COUNTRIES | **`countries`** +| field | data type | metadata | +| :--------| :---------------- | :-------------------------------------------------- | +| id | unsigned integer | primary key, auto-increments, generated by database | +| name | string | | + +#### Get countries list +**`GET /api/countries`** + +##### Response +A json object with the `name` and `id`. + +``` +{ + "id": 1, + "name": "Belgium" +} +``` + +### CITIES | **`cities`** +| field | data type | metadata | +| :--------| :--------------------- | :-------------------------------------------------- | +| id | unsigned integer | primary key, auto-increments, generated by database | +| name | string | | +| integer | unsigned integer | foreign key referencing `countries.id` | + +#### Get cities list +**`GET /api/cities`** + +##### Response +A json object with `id`, `name` and `country_id`. + +``` +{ + "id": 1, + "name": 'bruges', + "country_id": 1 +} +``` + +### ROADS| **`roads`** +| field | data type | metadata | +| :-------------| :--------------- | :-------------------------------------------------- | +| id | unsigned integer | primary key, auto-increments, generated by database | +| start_city_id | string | required | +| end_city_id | string | required | +| distance | unsigned integer | | + +#### Get roads list +**`GET /api/roads`** + +##### Response +A json object with `id`, `start_city_id`, 'end_city_id` and `distance`. + +``` +{ + "id": 1, + "start_city_id": 1, + "end_city_id": 3, + "distance": 50 +} +``` + +### Shortest Path | **`cities`** + +#### Get the shortest path between two cities and the total distance +**`GET /api/path`** + +##### Request +A json object with **`start_city_id`** and **`end_city_id`**. + +``` +{ + "start_city_id": 2, + "end_city_id": 9 +} +``` + +##### Response +A json object composed of the `path` (in the correct order) and the total `distance`. + +``` +{ + "path": [ + { + "id": 2, + "name": "antwerp" + }, + { + "id": 4, + "name": "mechelen" + }, + { + "id": 5, + "name": "brussels" + }, + { + "id": 8, + "name": "liege" + }, + { + "id": 7, + "name": "namur" + }, + { + "id": 9, + "name": "arlon" + } + ], + "distance": 337 +} +``` \ No newline at end of file diff --git a/data/seeds/02-cities.js b/data/seeds/02-cities.js index 3b4af50..0532481 100644 --- a/data/seeds/02-cities.js +++ b/data/seeds/02-cities.js @@ -3,10 +3,10 @@ exports.seed = function(knex) { return knex('cities').truncate() .then(function () { return knex('cities').insert([ - { - "id": 1, - "name": 'bruges', - "country_id": 1 + { + "id": 1, + "name": 'bruges', + "country_id": 1 }, { "id": 2, diff --git a/index.js b/index.js index ca3cb87..8ea6315 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const server = require("./api/server"); server.get("/", (req, res) => { res.json({ message: `API server for Dijkstra. :)`, - documentation: `Coming` + documentation: `Check out: https://github.com/ruihildt/dijkstra/tree/completed-backend` }); });