diff --git a/app/api/sites/get_all/route.ts b/app/api/sites/get_all/route.ts
index 0b4cbe0..99bdd8d 100644
--- a/app/api/sites/get_all/route.ts
+++ b/app/api/sites/get_all/route.ts
@@ -1,15 +1,18 @@
import { NextRequest, NextResponse } from "next/server";
import prisma from "@/app/prisma";
+import Fuse from "fuse.js";
interface QueryParams {
currentPage: number;
itemPerPage: number;
+ search: string;
}
export async function GET(request: NextRequest) {
const { searchParams } = request.nextUrl;
const currentPage = Number(searchParams.get("currentPage")) || 1;
const itemPerPage = Number(searchParams.get("itemPerPage")) || 1;
+ const search = searchParams.get("search") || "";
const skip = (currentPage - 1) * itemPerPage;
const take = itemPerPage;
@@ -18,8 +21,29 @@ export async function GET(request: NextRequest) {
const sites = await prisma.site.findMany({
skip,
take,
+ where: {
+ name: {
+ contains: search,
+ mode: "insensitive",
+ },
+ description: {
+ contains: search,
+ mode: "insensitive",
+ },
+ },
+ });
+ const total = await prisma.site.count({
+ where: {
+ name: {
+ contains: search,
+ mode: "insensitive",
+ },
+ description: {
+ contains: search,
+ mode: "insensitive",
+ },
+ },
});
- const total = await prisma.site.count();
return NextResponse.json({ sites, total, currentPage, itemPerPage }, { status: 200 });
} catch (error: any) {
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
diff --git a/app/dashboard/sites/SitesPage.tsx b/app/dashboard/sites/SitesPage.tsx
index 7846683..9a73612 100644
--- a/app/dashboard/sites/SitesPage.tsx
+++ b/app/dashboard/sites/SitesPage.tsx
@@ -18,6 +18,7 @@ export default function SitesPage({ username, name }: SitesPageProps) {
const [currentPage, setCurrentPage] = useState(1);
const [itemPerPage, setItemPerPage] = useState(5);
const [total, setTotal] = useState(0);
+ const [search, setSearch] = useState("");
const handlePageChange = (page: number) => {
setCurrentPage(page);
@@ -27,12 +28,13 @@ export default function SitesPage({ username, name }: SitesPageProps) {
params: {
currentPage,
itemPerPage,
+ search,
},
}).then((response) => {
setSites(response.data.sites);
setTotal(response.data.total);
});
- }, [currentPage, itemPerPage]);
+ }, [currentPage, itemPerPage, search]);
return (