Update doc
This commit is contained in:
parent
24b4fe72bb
commit
b659af9cb4
17
README.md
17
README.md
@ -8,7 +8,7 @@ Deployed backend: https://dijkstra-backend.herokuapp.com/
|
|||||||
___
|
___
|
||||||
> Values required in **`bold`**.
|
> Values required in **`bold`**.
|
||||||
|
|
||||||
### COUNTRIES | **`countries`**
|
### COUNTRIES **`countries`**
|
||||||
| field | data type | metadata |
|
| field | data type | metadata |
|
||||||
| :--------| :---------------- | :-------------------------------------------------- |
|
| :--------| :---------------- | :-------------------------------------------------- |
|
||||||
| id | unsigned integer | primary key, auto-increments, generated by database |
|
| 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 |
|
| field | data type | metadata |
|
||||||
| :----------| :--------------------- | :-------------------------------------------------- |
|
| :----------| :--------------------- | :-------------------------------------------------- |
|
||||||
| id | unsigned integer | primary key, auto-increments, generated by database |
|
| 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 |
|
| field | data type | metadata |
|
||||||
| :-------------| :--------------- | :-------------------------------------------------- |
|
| :-------------| :--------------- | :-------------------------------------------------- |
|
||||||
| id | unsigned integer | primary key, auto-increments, generated by database |
|
| 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 the shortest path between two cities and the total distance
|
||||||
**`GET /api/path`**
|
**`GET /api/path`**
|
||||||
|
|
||||||
##### Request
|
##### 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.
|
||||||
|
|
||||||
```
|
```
|
||||||
{
|
/api/path?start_city_id=2?end_city_id=9
|
||||||
"start_city_id": 2,
|
|
||||||
"end_city_id": 9
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Response
|
##### 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`.
|
||||||
|
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
|
@ -3,25 +3,22 @@ const router = require('express').Router();
|
|||||||
const Roads = require('../models/roadsModel');
|
const Roads = require('../models/roadsModel');
|
||||||
const Cities = require('../models/citiesModel');
|
const Cities = require('../models/citiesModel');
|
||||||
|
|
||||||
const searchPath = require('../../helpers/dijkstra_algo');
|
const findShortestPath = require('../../helpers/dijkstra_algo');
|
||||||
|
|
||||||
router.get('', async (req, res) => {
|
router.get('', async (req, res) => {
|
||||||
const { start_city_id, end_city_id } = req.query;
|
const { start_city_id, end_city_id } = req.query;
|
||||||
console.log(typeof start_city_id)
|
|
||||||
|
|
||||||
start = Math.floor(start_city_id);
|
start = Math.floor(start_city_id);
|
||||||
end = Math.floor(end_city_id);
|
end = Math.floor(end_city_id);
|
||||||
console.log(start, end)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const cities = await Cities.getCities();
|
const cities = await Cities.getCities();
|
||||||
const roads = await Roads.getRoads();
|
const roads = await Roads.getRoads();
|
||||||
|
|
||||||
let { path, distance } = searchPath(cities, roads, start, end);
|
let { path, distance } = findShortestPath(cities, roads, start, end);
|
||||||
const formatedPath = formatPath(path, cities)
|
const shortestPath = formatPath(path, cities)
|
||||||
console.log(path)
|
|
||||||
|
|
||||||
let response = { path: formatedPath, distance }
|
let response = { path: shortestPath, distance }
|
||||||
|
|
||||||
res.status(200).json(response);
|
res.status(200).json(response);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user