This repository was archived by the owner on Oct 2, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 507
London_10-Saliha_Popal/Node-Module/quote-server #320
Open
SalihaPopal
wants to merge
7
commits into
CodeYourFuture:master
Choose a base branch
from
SalihaPopal:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
04d82f2
Level 1, 2
SalihaPopal 49dabc3
Added cors()
SalihaPopal 8ba74e9
Changed S to s in Saliha
SalihaPopal 2aaaf9a
Undo the last change
SalihaPopal 3fc315d
Changed the s to S in package.json
SalihaPopal 77508e2
Added lodash to the file
SalihaPopal bb5ef31
Added saliha to the package.json workplace
SalihaPopal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| const express = require("express"); | ||
| const app = express(); | ||
|
|
||
|
|
||
| //load the quotes JSON | ||
| const quotes = require("./quotes.json"); | ||
|
|
||
|
|
@@ -13,11 +14,50 @@ const quotes = require("./quotes.json"); | |
| // /quotes - Should return all quotes (json) | ||
| // /quotes/random - Should return ONE quote (json) | ||
| app.get("/", function (request, response) { | ||
| response.send("Neill's Quote Server! Ask me for /quotes/random, or /quotes"); | ||
| response.send("Saliha's Quote Server! Ask me for /quotes/random, or /quotes"); | ||
| }); | ||
|
|
||
| //START OF YOUR CODE... | ||
|
|
||
| app.get("/quotes", function (request, response) { | ||
| response.send({quotes}); | ||
| }); | ||
|
|
||
| app.get("/quotes/random", function (request, response) { | ||
|
|
||
| // Pick a random quote from the array using the pickFromArray function | ||
| const randomQuote = pickFromArray(quotes); | ||
|
|
||
| // Send the random quote as the response | ||
| response.send(randomQuote); | ||
| }); | ||
|
|
||
| // http://localhost:62297/quotes/search?term=life/success/miss | ||
| // app.get("/quotes/search", function (request, response) { | ||
| // // let term = request.query.term | ||
| // // response.send(term); | ||
| // }); | ||
|
|
||
| // advance | ||
| app.get("/quotes/search", function (request, response) { | ||
| const term = request.query.term; | ||
| const searchResults = searchQuotes(term); | ||
| response.send({searchResults}); | ||
| }); | ||
|
|
||
|
|
||
| // ## Level 2 Challenge - allow quote _searches_! | ||
| function searchQuotes(term) { | ||
| const results = quotes.filter( | ||
| (quote) => | ||
|
||
| quote.quote.toLowerCase().includes(term.toLowerCase()) || | ||
| quote.author.toLowerCase().includes(term.toLowerCase()) || | ||
| quote === "" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you filitering empty quotes here? |
||
| ); | ||
| return results; | ||
| } | ||
|
|
||
|
|
||
| //...END OF YOUR CODE | ||
|
|
||
| //You can use this function to pick one element at random from a given array | ||
|
|
@@ -32,3 +72,5 @@ function pickFromArray(arr) { | |
| const listener = app.listen(process.env.PORT, function () { | ||
| console.log("Your app is listening on port " + listener.address().port); | ||
| }); | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend using
.jsonwhen you're sending JSON data though, because it makes it obvious to other developers that you are aiming to send JSON data back.Would be great if you study this => https://expressjs.com/en/api.html#res.send and see the difference between
.sendand.json