diff --git a/app/api/products/getAll/route.ts b/app/api/products/getAll/route.ts new file mode 100644 index 0000000..db41610 --- /dev/null +++ b/app/api/products/getAll/route.ts @@ -0,0 +1,19 @@ +import { prisma } from '@/db/client' +import { NextResponse } from 'next/server' + +import type { NextRequest } from 'next/server' + + +export async function GET(request: NextRequest) { + try{ + + const products = await prisma.product.findMany() + // URL to redirect to after sign in process completes + return NextResponse.json({data:products}) + }catch(err){ + return NextResponse.error() + }finally{ + prisma.$disconnect() + } + +} \ No newline at end of file diff --git a/app/api/products/getSingle/route.ts b/app/api/products/getSingle/route.ts new file mode 100644 index 0000000..e8d280d --- /dev/null +++ b/app/api/products/getSingle/route.ts @@ -0,0 +1,26 @@ +import { prisma } from '@/db/client' +import { NextResponse } from 'next/server' + +import type { NextRequest } from 'next/server' + + +export async function POST(request: NextRequest) { + const {id} = await request.json() + console.log(id,'TARGET ID') + try{ + + const product = await prisma.product.findUnique({ + where: { + id:Number(id) + } + }) + console.log(product, 'TARGET PRODUCT') + // URL to redirect to after sign in process completes + return NextResponse.json({data:product}) + }catch(err){ + return NextResponse.error() + }finally{ + prisma.$disconnect() + } + +} \ No newline at end of file diff --git a/app/page.tsx b/app/page.tsx index 46085b3..b8a6b99 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -5,14 +5,21 @@ import InfoSection from '@/containers/home-page/info-section' import PopularProducts from '@/containers/home-page/popular-products-section' import ServicesSection from '@/containers/home-page/services-section' import TestimonialSection from '@/containers/home-page/testimonial-section' -import Image from 'next/image' +import { getAll } from '@/libs/endpoints' +import axios from 'axios' -export default function Home() { +const getItems = async() => { + const data = await axios(getAll) + return data.data +} + +export default async function Home() { + const items = await getItems() return (
- + diff --git a/app/product/[id]/page.tsx b/app/product/[id]/page.tsx index 82538d6..768d033 100644 --- a/app/product/[id]/page.tsx +++ b/app/product/[id]/page.tsx @@ -2,11 +2,12 @@ import React, { FC } from 'react' import type { Metadata, ResolvingMetadata } from 'next' import ItemSection from '@/containers/product-page/item-section' import RelatedSection from '@/containers/product-page/related-section' +import axios from 'axios' interface ProductProps { params: { id: string } searchParams: { [key: string]: string | string[] | undefined } } -/*export async function generateMetadata( +export async function generateMetadata( { params, searchParams }: ProductProps, parent?: ResolvingMetadata ): Promise { @@ -14,27 +15,28 @@ interface ProductProps { const id = params.id // fetch data - const product = new Promise((resolve) => { - return setTimeout(() => { - resolve('Test') - - }, 1000); - }) - + const product = await axios.post(process.env.NEXT_PUBLIC_SITE_URL ?? process?.env?.NEXT_PUBLIC_VERCEL_URL ?? 'http://localhost:3000/'+'api/products/getSingle',{id:id}) // optionally access and extend (rather than replace) parent metadata - const previousImages = (await parent).openGraph?.images || [] + //const previousImages = (await parent).openGraph?.images || [] return { //title: await product, - title:id, - openGraph: { - // images: ['/some-specific-page-image.jpg', ...previousImages], - }, + title:product?.data?.data?.name, + openGraph:{ + images:[product?.data?.data?.imgUrl] + } + } - }*/ -const Product: FC = ({ }) => { + } + + const getSingleProduct = async(id:string) => { + const product = await axios.post(process.env.NEXT_PUBLIC_SITE_URL ?? process?.env?.NEXT_PUBLIC_VERCEL_URL ?? 'http://localhost:3000/'+'api/products/getSingle',{id}) + return product.data + } +const Product: FC = async({ params }) => { + const product = await getSingleProduct(params.id) return (
- +
) diff --git a/app/products/page.tsx b/app/products/page.tsx index 7bccafe..6d3cb4e 100644 --- a/app/products/page.tsx +++ b/app/products/page.tsx @@ -2,19 +2,25 @@ import ProductsHero from '@/containers/products-page/products-hero'; import PromiseItems from '@/containers/products-page/items-section'; import ProductsSearch from '@/containers/products-page/search-section'; import React, { FC } from 'react' +import axios from 'axios'; +import { getAll } from '@/libs/endpoints'; interface ProductsProps { searchParams: { [key: string]: string | string[] | undefined } } - +const getItems = async() => { + const data = await axios(getAll) + return data.data +} const Products: FC = async({ searchParams }) => { const page = typeof searchParams.page === 'string' ? Number(searchParams.page) : 1 - console.log(page) + const items = await getItems() + return (
- +
) } diff --git a/components/Cards/ProductCard/index.tsx b/components/Cards/ProductCard/index.tsx index d37d7db..b8604f0 100644 --- a/components/Cards/ProductCard/index.tsx +++ b/components/Cards/ProductCard/index.tsx @@ -1,24 +1,27 @@ +import { TProduct } from "@/types/Product"; import Image from "next/image"; import Link from "next/link"; import React, { FC } from "react"; -interface ProductCardProps {} +interface ProductCardProps { + item:TProduct +} -const ProductCard: FC = ({}) => { +const ProductCard: FC = ({item}) => { return (
- - Product IMG + + Product IMG
-

Lamp

+

{item.category}

- Bardono Smart Lamp + {item.name}

- Easy to use with bluetooth connection + {item.title}

- $62.23 + ${item.price}
); diff --git a/containers/home-page/popular-products-section/index.tsx b/containers/home-page/popular-products-section/index.tsx index 0f318b3..676abef 100644 --- a/containers/home-page/popular-products-section/index.tsx +++ b/containers/home-page/popular-products-section/index.tsx @@ -1,10 +1,13 @@ import ProductCard from "@/components/Cards/ProductCard"; import React, { FC } from "react"; import PopularProductsSlide from "./popular-products-slide"; +import { TProduct } from "@/types/Product"; -interface PopularProductsProps {} +interface PopularProductsProps { + products: TProduct[] +} -const PopularProducts: FC = ({}) => { +const PopularProducts: FC = ({products}) => { return (
@@ -22,7 +25,7 @@ const PopularProducts: FC = ({}) => {

- +
); diff --git a/containers/home-page/popular-products-section/popular-products-slide/index.tsx b/containers/home-page/popular-products-section/popular-products-slide/index.tsx index 9756c75..4d50ec0 100644 --- a/containers/home-page/popular-products-section/popular-products-slide/index.tsx +++ b/containers/home-page/popular-products-section/popular-products-slide/index.tsx @@ -8,10 +8,13 @@ import "swiper/css/navigation"; import React, { FC, useRef } from "react"; import ProductCard from "@/components/Cards/ProductCard"; import { SlideArrow } from "@/components/Icons/SlideArrow"; +import { TProduct } from "@/types/Product"; -interface PopularProductsSlideProps {} +interface PopularProductsSlideProps { + items:TProduct[] +} -const PopularProductsSlide: FC = ({}) => { +const PopularProductsSlide: FC = ({items}) => { const swiperRef = useRef(null); return ( = ({}) => { centeredSlides onSwiper={(swiper) => (swiperRef.current = swiper)} > - - + {items.map((el,_i) => ( + + - - - - - - - - - - - - - - - - - - - - - - - + ))} + {items.map((el,_i) => ( + + + ))} +