-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from Cheplusplus/Productdetail
Productdetail
- Loading branch information
Showing
11 changed files
with
1,428 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,14 +1,26 @@ | ||
const fetchSingleRecipe = async (id) => { | ||
try { | ||
const res = await fetch(`https://dummyjson.com/recipes/${id}`, {cache : 'force-cache'}); | ||
if (!res.ok) { | ||
throw new Error("Fetch Product Failed"); | ||
} | ||
const data = await res.json(); | ||
return data; | ||
} catch (error) { | ||
console.error("Failed to Fetch Data:", error) | ||
} | ||
}; | ||
|
||
export default fetchSingleRecipe; | ||
import connectToDatabase from "../../../../lib/connectMongoose"; | ||
import Recipe from "../../../../models/Recipe"; | ||
import { NextResponse } from "next/server"; | ||
import mongoose from "mongoose"; | ||
|
||
/** | ||
* | ||
* @param {*} req | ||
* @param {id} param1 - This Will get the exact recipe id from database | ||
* @returns - The recipe object by its Id | ||
*/ | ||
|
||
export async function GET(req, { params }) { | ||
try { | ||
let { id } = params; | ||
console.log(id) | ||
// id = new mongoose.Types.ObjectId(); | ||
console.log(id) | ||
await connectToDatabase(); | ||
const recipe = await Recipe.findOne({_id: id}).lean(); | ||
console.log(recipe,'123456789df') | ||
return NextResponse.json({ recipe }, { status: 200 }); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,14 +1,16 @@ | ||
const fetchRecipes = async () => { | ||
import connectToDatabase from "../../../lib/connectMongoose"; | ||
import Recipe from "../../../models/Recipe"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function GET(req) { | ||
console.log('cjsd csdcdsc') | ||
try { | ||
const res = await fetch("https://dummyjson.com/recipes", {cache : 'force-cache'}); | ||
if (!res.ok) { | ||
throw new Error("Fetch Products Failed"); | ||
} | ||
const data = await res.json(); | ||
return data; | ||
let db = await connectToDatabase(); | ||
console.log('mdcakmdcma') | ||
const recipes = await Recipe.find({}, { _id: 1, title: 1, description: 1, prep: 1, cook: 1, images: 1, ingredients: 1, instructions: 1, nutrition: 1, servings: 1 }).limit(50).lean(); | ||
//console.log(recipes[0]) | ||
return NextResponse.json({ recipes }); | ||
} catch (error) { | ||
console.error("Failed to Fetch Data:", error) | ||
console.error(error); | ||
} | ||
}; | ||
|
||
export default fetchRecipes; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.