Move prisma calls to server side

This commit is contained in:
MartinBraquet
2025-07-29 01:42:39 +02:00
parent 65be06620e
commit 149a86214d
3 changed files with 44 additions and 27 deletions

View File

@@ -11,8 +11,9 @@ To contribute, please submit a pull request or issue, or fill out this [form](ht
## To Do
- [x] Authentication (user/password and Google Sign In)
- [ ] Set up PostgreSQL in Production with supabase (can stick with SQLite in dev / local)
- [ ] Set up domain name and hosting (vercel?)
- [x] Set up PostgreSQL in Production with supabase (can stick with SQLite in dev / local)
- [ ] Set up hosting (vercel)
- [ ] Set up domain name and
- [ ] Ask for detailed info per profile upon registration (intellectual interests, location, cause areas, personality type, conflict style, desired type of connection, prompt answers, gender, etc.)
- [ ] Set up page listing all the profiles
- [ ] Search through all the profile variables
@@ -26,6 +27,7 @@ Any action item is open to anyone for collaboration, but the following ones are
- [ ] Clean up privacy notice
- [ ] Clean up learn more page
- [ ] Add dark theme
- [ ] Cover with tests
## Implementation

View File

@@ -4,7 +4,7 @@ import { NextResponse } from "next/server";
export async function GET(request: Request) {
const url = new URL(request.url);
const page = parseInt(url.searchParams.get("page") || "1");
const profilesPerPage = 5;
const profilesPerPage = 20;
const offset = (page - 1) * profilesPerPage;
// Fetch paginated posts
@@ -18,5 +18,6 @@ export async function GET(request: Request) {
const totalProfiles = await prisma.user.count();
const totalPages = Math.ceil(totalProfiles / profilesPerPage);
return NextResponse.json({ posts: profiles, totalPages });
console.log({ profiles, totalPages });
return NextResponse.json({ profiles, totalPages });
}

View File

@@ -1,35 +1,49 @@
import {redirect} from "next/navigation";
'use client';
import Link from "next/link";
import { prisma }from "@/lib/prisma";
import {checkUserTableExists} from "@/lib/db-utils";
import {useEffect, useState} from "react";
import {notFound} from "next/navigation";
// Disable static generation
export const dynamic = "force-dynamic";
type Profile = {
id: string;
name: string;
createdAt: string;
};
export default async function PostsPage() {
// Check if the post table exists
const tableExists = await checkUserTableExists();
// If the post table doesn't exist, redirect to setup page
if (!tableExists) {
redirect("/setup");
}
export default function ProfilePage() {
const profiles = await prisma.user.findMany({
orderBy: {
createdAt: "desc",
},
// take: 20,
// include: {
// author: {
// select: {
// name: true,
// },
// },
// },
});
const [profiles, setProfiles] = useState<Profile[]>([]);
useEffect(() => {
const fetchProfile = async () => {
try {
const response = await fetch('/api/profiles');
console.log(response)
const data = await response.json();
console.log(data)
if (!response.ok) {
throw new Error(data.error || 'Failure');
}
const p = data['profiles'];
setProfiles(p);
} catch (error) {
console.error('Upload error:', error);
}
};
fetchProfile();
}, []);
if (!profiles) return <p>Loading...</p>;
return (
<div className="min-h-screen bg-gray-50 flex flex-col items-center py-24 px-8">