Check out a free preview of the full Complete Intro to SQL & PostgreSQL course:
The "Recipes Exercise" Lesson is part of the full, Complete Intro to SQL & PostgreSQL course featured in this preview video. Here's what you'd learn in this lesson:

Students are instructed to implement the search and get recipe by ID APIs. Instructions are located in the code comments in /recipes/API.js.

Get Unlimited Access Now

Transcript from the "Recipes Exercise" Lesson

[00:00:00]
>> Okay, so let's walk through our second, Project here. So you've already done the ingredients portion of this. Now, we're gonna go do the recipe portion of this. So go into your recipes. Same sort of thing here. We have a client, I mean, the detail-client. They're two different pages, but you only have to worry about api.js, okay?

[00:00:23] You're gonna have to connect to postgres again here. You can literally copy and paste the one from the other one, that's fine. Here, you're gonna have to return the recipe ID title and the first photo as a URL, you can use that distinct magic that I was showing you.

[00:00:39] And then for the recipes without photos, return the URL as defaults.jpg which I showed you how to do with coalesce. Okay, that's the first one, that's for the search page. Which, let me just go ahead and show you that first. I'm gonna have to run npm dev again.

[00:01:01] It's already running, localhost:3000, that's here. We're gonna go into recipes, actually, kind of just do this here, yeah, I can. This is just gonna be a list of all the recipes, it's not paginated or anything fancy like that. And then here, you're going to click on one of the recipes and that'll take you to one of these pages.

[00:01:27] It'll show you all the ingredients, the instructions, and then a rotational picture of all the ingredients as well as the images. So looking back at our code, So the search page, you should just have to do this one, the recipe ID, the title, and the first photo. Again, that's gonna take probably two joins to get that.

[00:01:58] This one you're gonna return all ingredients. This is gonna be a top level item that you return. So instead of having status data implemented here, you're gonna have ingredients be an array of the ingredients from the API, right? Make sure that you can use as, right, remember as to rename things.

[00:02:25] Return the ingredient image as ingredient image, ingredient types as ingredient type and ingredient titles as ingredient title. Probably gonna be your first query, I would imagine. Okay, then you're gonna have a photos in a row that you're going to return this in an array. Return the title, body and URL as named by the same, right?

[00:02:50] So you don't have to rename those things, title, body and URL, that's totally fine. And then finally, return the title of the entire recipe as, Whatever and the body as whatever the body is. So actually, you can actually just return this as URL, cuz I don't think it actually uses the other stuff.

[00:03:21] So I'm kind of clueing you in on how I did it, but you're welcome to do it however you want. All right, any questions? Make sense?
>> For search, what are the query params?
>> There are no query params.
>> So this is more like a list?
>> Yeah, it could have been called list, yeah.

[00:03:51] I don't think I even have a search box up there, do I? I don't, yeah, there's no search, it'ss just listing all the recipes.