All language subtitles for 014 Adding a Nested GET Endpoint_Downloadly.ir_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

So, in the last two videos,

we created a nested POST endpoint

in order to create new reviews on a certain tour.

So, let's now build upon that,

and also create a nested GET endpoint.

So we already have our getAllReviews

handler function implemented, right?

But right now, all it does is to basically get an array

of all the reviews in the review collection.

Now, a common use case for your API

might be to get an array of all the reviews

of one particular tour, so very similar

to the createReview, right?

So basically similar to this route here,

but except with GET.

So, basically something like this, okay?

And so, all we need to do in order to implement this

is to do some simple changes

to our getAllReviews handler function, right?

Because right now, thanks to the merge params,

and this kind of redirecting that we implemented here

in the last video, so thanks to all that,

this getAllReviews handler function will now automatically

get called whenever there is a GET request

for a URL that looks like this,

and will also get access to the tourId,

and again, thanks to mergeParams set to true.

All right?

So let's just do some very simple changes here, all right?

And what we're going to do here is to check

if there is a tourId, and if there is one, well,

then we're only going to search for reviews

where the tour is equal to that tourId, okay?

So, that's something that's very simple

to implement using find, right?

So basically, what we're doing is something like this.

So, if there is request.params.tourId,

then we want to create a filter object,

which we will then later use right here.

Let's actually put it here right away,

and we also need to kind of initialize it.

So, let filter, because we want to then mutate this, okay?

So, if there is a tourId, then this filter

should be equal to

tour: req.params.tourId.

Okay, and so, again, if there is a tourId,

then basically, this object here is what will be here.

And so then only the reviews where the tour

matches the ID are going to be found.

So if it's all regular API call without nested route,

well then that filter will simply be this empty object,

and so then we're gonna find all the reviews, okay?

And, so, let's actually test this,

because this is all we need to change here, all right?

So, let's save this one,

this one as well, all right?

And so, to start, let's test if our getAllReviews,

so the regular one, still works as intended, okay?

So we get all the four reviews that are in our collection.

Let's just verify that,

and indeed there are four documents, okay?

But now, let's actually create

our nested getAllReviews route, okay?

So, what I'm going to do is to copy this one.

Okay, and then simply add reviews, okay?

And so this tour is the City Wanderer,

and it actually has one review.

And so, we expect now to get an array

with one object in there, okay?

So, it just had one review.

And indeed, that is exactly what we get.

So these are all the reviews that are present on this tour,

so, the tour with this ID.

And, actually, that's pretty correct, right?

Let's try another one, and I remember that this one,

so the Forest Hiker, actually had I think two reviews.

So let's see if that works as well.

And so yeah, indeed.

Here there are.

All right?

So let's save that, still in that tours/review folder,

and so getAllReviews on tour.

Okay, great.

That's actually all I had to show you about nested routes.

So next up, let's continue filling up our review controller,

because right now we really only have getAllReviews

and createReview.

And so we also want to update,

to delete, and all that stuff,

and so let's take care of that in the next lecture.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.