From b659af9cb4bae2c14cd449f02b5eee4855f2bcb4 Mon Sep 17 00:00:00 2001 From: rui hildt Date: Sun, 9 Feb 2020 18:06:33 +0100 Subject: [PATCH] Update doc --- README.md | 17 +++++++---------- api/routes/pathRouter.js | 11 ++++------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 26574de..5be4179 100644 --- a/README.md +++ b/README.md @@ -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`. ``` { diff --git a/api/routes/pathRouter.js b/api/routes/pathRouter.js index 7ab37d9..74342cc 100644 --- a/api/routes/pathRouter.js +++ b/api/routes/pathRouter.js @@ -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) {