Skip to content

Commit

Permalink
add: data.json and featured products route
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniobiasotti committed Apr 20, 2024
1 parent 1c92cb9 commit e4c13b8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/app/api/products/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"products": [
{
"id": 1,
"title": "Moletom Never Stop Learning",
"slug": "moletom-never-stop-learning",
"price": 129,
"image": "/moletom-never-stop-learning.png",
"description": "Moletom fabricado com 88% de algodão e 12% de poliéster.",
"featured": true
},
{
"id": 2,
"title": "Moletom AI Side",
"slug": "moletom-ai-side",
"price": 99,
"image": "/moletom-ai-side.png",
"description": "Moletom fabricado com 88% de algodão e 12% de poliéster.",
"featured": true
},
{
"id": 3,
"title": "Camiseta DoWhile 2022",
"slug": "camiseta-dowhile-2022",
"price": 69,
"image": "/camiseta-dowhile-2022.png",
"description": "Camiseta fabricada com 100% de algodão.",
"featured": true
},
{
"id": 4,
"title": "Moletom Java 2023",
"slug": "moletom-java-2023",
"price": 99,
"image": "/moletom-java.png",
"description": "Moletom fabricado com 88% de algodão e 12% de poliéster.",
"featured": false
},
{
"id": 5,
"title": "Moletom IA p/ devs",
"slug": "moletom-ia-p-devs",
"price": 99,
"image": "/moletom-ia-p-devs.png",
"description": "Moletom fabricado com 88% de algodão e 12% de poliéster.",
"featured": false
}
]
}
8 changes: 8 additions & 0 deletions src/app/api/products/featured/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import data from '../data.json'

export async function GET() {

const featuredProducts = data.products.filter((product) => product.featured)

return Response.json(featuredProducts)
}
4 changes: 3 additions & 1 deletion src/app/api/products/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import data from './data.json'

export async function GET() {
return Response.json({ message: 'Hello World' })
return Response.json(data.products)
}

0 comments on commit e4c13b8

Please sign in to comment.