From 19417a2158c11718230ad5713e9f67c147dcc366 Mon Sep 17 00:00:00 2001 From: Stefano Demichelis Date: Wed, 24 Nov 2021 23:47:15 +0900 Subject: [PATCH 1/3] Adjusting endpoints in README to match code. --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a1a023a..79e3d28 100644 --- a/README.md +++ b/README.md @@ -44,15 +44,15 @@ Returns an array with `{number}` quotes e.g. `GET /quotes/3`. } ] -### `GET /quote/{id}` +### `GET /quotes/id/{id}` Get the corresponding quote from its `id` in this format: -> [https://the-dune-api.herokuapp.com/quote/40](https://the-dune-api.herokuapp.com/quote/40) +> [https://the-dune-api.herokuapp.com/quotes/id/66](https://the-dune-api.herokuapp.com/quotes/id/66) [ { - id: "96", + id: "66", "quote": "A man's flesh is his own; the water belongs to the tribe.", } ] @@ -103,11 +103,11 @@ Returns an array with `{number}` books e.g. `GET /books/3`. } ] -### `GET /book/{id}` +### `GET /books/id/{id}` Get the corresponding book from its `id` in this format: -> [https://the-dune-api.herokuapp.com/book/1](https://the-dune-api.herokuapp.com/book/1) +> [https://the-dune-api.herokuapp.com/books/id/1](https://the-dune-api.herokuapp.com/books/id/1) [ { From 6c4731a7819ccf894845f6e9cf55f4970ed1f10e Mon Sep 17 00:00:00 2001 From: Stefano Demichelis Date: Wed, 24 Nov 2021 23:47:59 +0900 Subject: [PATCH 2/3] Deleting unnecessary double status method. --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index 950defb..ea2b516 100644 --- a/server.js +++ b/server.js @@ -23,7 +23,7 @@ app.get('/:type/id/:id?', function (req, res) { }); app.get('/', (req, res) => { - res.status(200).status(200).send("Welcome to the DUNE API") + res.status(200).send("Welcome to the DUNE API") }); app.listen(PORT, function () { From 9269411b6b0dd5b57840331f9fe165bea166194c Mon Sep 17 00:00:00 2001 From: Stefano Demichelis Date: Wed, 24 Nov 2021 23:49:22 +0900 Subject: [PATCH 3/3] Updating statement in condition for returning first array element. --- loaders/getArticle.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/loaders/getArticle.js b/loaders/getArticle.js index 1da949c..068826c 100644 --- a/loaders/getArticle.js +++ b/loaders/getArticle.js @@ -83,8 +83,8 @@ function getRandom(type, number) { function getArticle(type, id) { if (type == 'quotes') { - if (id < 0) { - return quotes[1] + if (id <= 0) { + return quotes[0] } else if (id > quotes.length) { return quotes[quotes.length - 1] @@ -94,8 +94,8 @@ function getArticle(type, id) { } } else if (type == 'books') { - if (id < 0) { - return books[1] + if (id <= 0) { + return books[0] } else if (id > books.length) { return books[books.length - 1] @@ -105,8 +105,8 @@ function getArticle(type, id) { } } else if (type == 'movies') { - if (id < 0) { - return movies[1] + if (id <= 0) { + return movies[0] } else if (id > movies.length) { return movies[movies.length - 1] @@ -116,8 +116,8 @@ function getArticle(type, id) { } } else if (type == 'series') { - if (id < 0) { - return series[1] + if (id <= 0) { + return series[0] } else if (id > series.length) { return series[series.length - 1] @@ -127,8 +127,8 @@ function getArticle(type, id) { } } else if (type == 'stories') { - if (id < 0) { - return shortStories[1] + if (id <= 0) { + return shortStories[0] } else if (id > stories.length) { return shortStories[shortStories.length - 1] @@ -138,8 +138,8 @@ function getArticle(type, id) { } } else if (type == 'comics') { - if (id < 0) { - return comics[1] + if (id <= 0) { + return comics[0] } else if (id > comics.length) { return comics[comics.length - 1]