create database connection

This commit is contained in:
2024-09-18 18:38:35 -04:00
parent dab127aed7
commit 0e019e3c30
15 changed files with 557 additions and 607 deletions

View File

@@ -0,0 +1,31 @@
import { db } from "~/server/db";
import { studies } from "~/server/db/schema";
import { NextResponse } from "next/server";
import { eq } from "drizzle-orm";
export async function GET() {
const allStudies = await db.select().from(studies);
return NextResponse.json(allStudies);
}
export async function POST(request: Request) {
const { title, description } = await request.json();
const newStudy = await db.insert(studies).values({ title, description }).returning();
return NextResponse.json(newStudy[0]);
}
export async function PUT(request: Request) {
const { id, title, description } = await request.json();
const updatedStudy = await db
.update(studies)
.set({ title, description })
.where(eq(studies.id, id))
.returning();
return NextResponse.json(updatedStudy[0]);
}
export async function DELETE(request: Request) {
const { id } = await request.json();
await db.delete(studies).where(eq(studies.id, id));
return NextResponse.json({ message: "Study deleted" });
}

View File

@@ -1,9 +1,15 @@
import { type PropsWithChildren } from "react"
import { Sidebar } from "~/components/sidebar"
import { inter } from "../layout"
import { Inter } from "next/font/google"
import "~/styles/globals.css"
const inter = Inter({
subsets: ["latin"],
display: "swap",
variable: "--font-sans",
})
export default function RootLayout({ children }: PropsWithChildren) {
return (
<html lang="en">

View File

@@ -1,5 +1,6 @@
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '~/components/ui/card';
import { Button } from '~/components/ui/button';
import { Studies } from "~/components/Studies";
const HomePage: React.FC = () => {
return (
@@ -11,41 +12,7 @@ const HomePage: React.FC = () => {
Manage your Human-Robot Interaction projects and experiments
</p>
</header>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<Card className="bg-white shadow-lg">
<CardHeader>
<CardTitle className="text-2xl font-semibold text-blue-700">Projects</CardTitle>
<CardDescription>Manage your HRI projects</CardDescription>
</CardHeader>
<CardContent>
<p className="mb-4">Create, edit, and analyze your HRI projects.</p>
<Button className="bg-blue-600 hover:bg-blue-700 text-white">View Projects</Button>
</CardContent>
</Card>
<Card className="bg-white shadow-lg">
<CardHeader>
<CardTitle className="text-2xl font-semibold text-blue-700">Experiments</CardTitle>
<CardDescription>Design and run experiments</CardDescription>
</CardHeader>
<CardContent>
<p className="mb-4">Set up, conduct, and analyze HRI experiments.</p>
<Button className="bg-green-600 hover:bg-green-700 text-white">New Experiment</Button>
</CardContent>
</Card>
<Card className="bg-white shadow-lg">
<CardHeader>
<CardTitle className="text-2xl font-semibold text-blue-700">Data Analysis</CardTitle>
<CardDescription>Analyze your research data</CardDescription>
</CardHeader>
<CardContent>
<p className="mb-4">Visualize and interpret your HRI research data.</p>
<Button className="bg-purple-600 hover:bg-purple-700 text-white">Analyze Data</Button>
</CardContent>
</Card>
</div>
<Studies />
</div>
</div>
);

View File

@@ -1,10 +1,9 @@
import { ClerkProvider } from '@clerk/nextjs'
import { Inter } from "next/font/google"
import { ThemeProvider } from "next-themes"
import "~/styles/globals.css"
export const inter = Inter({
const inter = Inter({
subsets: ["latin"],
display: "swap",
variable: "--font-sans",

View File

@@ -52,7 +52,7 @@ export default function HomePage() {
<div className="text-center mb-12">
<h2 className="text-3xl font-semibold mb-4 text-blue-700">Join the HRI Revolution</h2>
<p className="text-lg text-gray-700 mb-6">
Whether you're a seasoned researcher or just starting in the field of Human-Robot Interaction,
Whether you&apos;re a seasoned researcher or just starting in the field of Human-Robot Interaction,
HRIStudio provides the tools and support you need to succeed.
</p>
<div className="space-x-4">

View File

@@ -31,8 +31,9 @@ export default function SignInPage() {
await setActive({ session: result.createdSessionId })
router.push("/dash")
}
} catch (err: any) {
console.error("Error:", err.errors[0].message)
} catch (err) {
const error = err as { errors?: { message: string }[] };
console.error("Error:", error.errors?.[0]?.message ?? "Unknown error")
}
}
@@ -42,6 +43,8 @@ export default function SignInPage() {
strategy,
redirectUrl: "/sso-callback",
redirectUrlComplete: "/dash",
}).catch((error) => {
console.error("Authentication error:", error); // Handle any potential errors
})
}
@@ -90,7 +93,7 @@ export default function SignInPage() {
</CardContent>
<CardFooter className="flex flex-col">
<p className="mt-4 text-sm text-center">
Don't have an account?{" "}
Don&apos;t have an account?{" "}
<Link href="/sign-up" className="text-blue-600 hover:underline">
Sign up
</Link>

View File

@@ -31,8 +31,9 @@ export default function SignUpPage() {
await setActive({ session: result.createdSessionId })
router.push("/dash")
}
} catch (err: any) {
console.error("Error:", err.errors[0].message)
} catch (err) {
const error = err as { errors?: { message: string }[] }; // Specify type
console.error("Error:", error.errors?.[0]?.message ?? "Unknown error") // Use optional chaining
}
}
@@ -42,6 +43,8 @@ export default function SignUpPage() {
strategy,
redirectUrl: "/sso-callback",
redirectUrlComplete: "/dash",
}).catch((error) => {
console.error("Authentication error:", error); // Handle any potential errors
})
}