From e4c13b8e34d7692b40363c99df3f7466fa6b0887 Mon Sep 17 00:00:00 2001 From: antoniobiasotti Date: Sat, 20 Apr 2024 14:42:44 -0300 Subject: [PATCH] add: data.json and featured products route --- src/app/api/products/data.json | 49 ++++++++++++++++++++++++++ src/app/api/products/featured/route.ts | 8 +++++ src/app/api/products/route.ts | 4 ++- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/app/api/products/data.json create mode 100644 src/app/api/products/featured/route.ts diff --git a/src/app/api/products/data.json b/src/app/api/products/data.json new file mode 100644 index 0000000..f1c7829 --- /dev/null +++ b/src/app/api/products/data.json @@ -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 + } + ] + } \ No newline at end of file diff --git a/src/app/api/products/featured/route.ts b/src/app/api/products/featured/route.ts new file mode 100644 index 0000000..c81dc89 --- /dev/null +++ b/src/app/api/products/featured/route.ts @@ -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) +} \ No newline at end of file diff --git a/src/app/api/products/route.ts b/src/app/api/products/route.ts index d387144..86dcaaa 100644 --- a/src/app/api/products/route.ts +++ b/src/app/api/products/route.ts @@ -1,3 +1,5 @@ +import data from './data.json' + export async function GET() { - return Response.json({ message: 'Hello World' }) + return Response.json(data.products) } \ No newline at end of file