Update doc

This commit is contained in:
rui hildt 2020-02-09 18:06:33 +01:00
parent 24b4fe72bb
commit b659af9cb4
2 changed files with 11 additions and 17 deletions

View File

@ -8,7 +8,7 @@ Deployed backend: https://dijkstra-backend.herokuapp.com/
___
> Values required in **`bold`**.
### COUNTRIES | **`countries`**
### COUNTRIES **`countries`**
| field | data type | metadata |
| :--------| :---------------- | :-------------------------------------------------- |
| id | unsigned integer | primary key, auto-increments, generated by database |
@ -40,7 +40,7 @@ A json object with a list of cities in the selected country `name` and `id` and
]
```
### CITIES | **`cities`**
### CITIES **`cities`**
| field | data type | metadata |
| :----------| :--------------------- | :-------------------------------------------------- |
| id | unsigned integer | primary key, auto-increments, generated by database |
@ -61,7 +61,7 @@ A json object with `id`, `name` and `country_id`.
}
```
### ROADS| **`roads`**
### ROADS **`roads`**
| field | data type | metadata |
| :-------------| :--------------- | :-------------------------------------------------- |
| id | unsigned integer | primary key, auto-increments, generated by database |
@ -84,23 +84,20 @@ A json object with `id`, `start_city_id`, 'end_city_id` and `distance`.
}
```
### Shortest Path | **`cities`**
### 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`**.
Add the **`start_city_id`** and **`end_city_id`** as query strings to the url.
```
{
"start_city_id": 2,
"end_city_id": 9
}
/api/path?start_city_id=2?end_city_id=9
```
##### Response
A json object composed of the `path` (in the correct order) and the total `distance`.
A json object composed of the `path` correctly ordered and the total `distance`.
```
{

View File

@ -3,25 +3,22 @@ const router = require('express').Router();
const Roads = require('../models/roadsModel');
const Cities = require('../models/citiesModel');
const searchPath = require('../../helpers/dijkstra_algo');
const findShortestPath = require('../../helpers/dijkstra_algo');
router.get('', async (req, res) => {
const { start_city_id, end_city_id } = req.query;
console.log(typeof start_city_id)
start = Math.floor(start_city_id);
end = Math.floor(end_city_id);
console.log(start, end)
try {
const cities = await Cities.getCities();
const roads = await Roads.getRoads();
let { path, distance } = searchPath(cities, roads, start, end);
const formatedPath = formatPath(path, cities)
console.log(path)
let { path, distance } = findShortestPath(cities, roads, start, end);
const shortestPath = formatPath(path, cities)
let response = { path: formatedPath, distance }
let response = { path: shortestPath, distance }
res.status(200).json(response);
} catch (e) {