From ac7d61154e6c1d31b57652bd7af9eb515451c6aa Mon Sep 17 00:00:00 2001
From: Caner <s86215@bht-berlin.de>
Date: Wed, 31 May 2023 17:34:09 +0200
Subject: [PATCH] UserProfile

---
 app/(auth)/login/page.tsx  |  2 +-
 app/(auth)/signup/page.tsx |  2 +-
 app/(content)/layout.tsx   |  1 +
 app/api/user/[userid].ts   | 28 ++++++++++++++++++++++++++++
 app/api/user/index.ts      | 22 ++++++++++++++++++++++
 prisma/schema.prisma       |  3 ++-
 6 files changed, 55 insertions(+), 3 deletions(-)
 create mode 100644 app/api/user/[userid].ts
 create mode 100644 app/api/user/index.ts

diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx
index f3ceae7..f499915 100644
--- a/app/(auth)/login/page.tsx
+++ b/app/(auth)/login/page.tsx
@@ -4,7 +4,7 @@ import Link from 'next/link'
 export default function LoginPage() {
     return (
         <div className="h-screen w-screen flex justify-center items-center bg-slate-100">
-            <div className="sm:shadow-xl px-8 pb-8 pt-12 sm:bg-white rounded-xl space-y-12">
+            <div className="sm:shadow-xl px-8 pb-8 pt-12 sm:bg-black rounded-xl space-y-12">
                 <h1 className="font-semibold text-2xl">Login</h1>
                 <LoginForm />
                 <p className="text-center">
diff --git a/app/(auth)/signup/page.tsx b/app/(auth)/signup/page.tsx
index 8f2d6d9..ea1b9f6 100644
--- a/app/(auth)/signup/page.tsx
+++ b/app/(auth)/signup/page.tsx
@@ -4,7 +4,7 @@ import Link from 'next/link'
 export default function SignupPage() {
     return (
         <div className="h-screen w-screen flex justify-center items-center bg-slate-100">
-            <div className="sm:shadow-xl px-8 pb-8 pt-12 sm:bg-white rounded-xl space-y-12">
+            <div className="sm:shadow-xl px-8 pb-8 pt-12 sm:bg-black rounded-xl space-y-12">
                 <h1 className="font-semibold text-2xl">Create your Account</h1>
                 <SignupForm />
                 <p className="text-center">
diff --git a/app/(content)/layout.tsx b/app/(content)/layout.tsx
index 0e27a5e..b960adc 100644
--- a/app/(content)/layout.tsx
+++ b/app/(content)/layout.tsx
@@ -15,6 +15,7 @@ export default async function ContentLayout({
                 <aside className="hidden w-[200px] flex-col md:flex">
                     <div className="sticky top-0">
                         <DashboardNav items={dashboardConfig.sidebarNav} />
+                        <button>Logout</button>
                     </div>
                 </aside>
                 <main className="flex w-full flex-1 flex-col overflow-hidden">
diff --git a/app/api/user/[userid].ts b/app/api/user/[userid].ts
new file mode 100644
index 0000000..5fa1e7c
--- /dev/null
+++ b/app/api/user/[userid].ts
@@ -0,0 +1,28 @@
+import { NextApiRequest, NextApiResponse } from "next";
+
+import { prisma } from "@/lib/db";
+
+export default async function handler(req: NextApiRequest, res: NextApiResponse) {
+  if (req.method !== 'GET') {
+    return res.status(405).end();
+  }
+
+  try {
+    const { userId } = req.query;
+
+    if (!userId || typeof userId !== 'string') {
+      throw new Error('Invalid ID');
+    }
+
+    const existingUser = await prisma.user.findUnique({
+      where: {
+        id : +userId
+      }
+    });
+
+    return res.status(200).json({ ...existingUser});
+  } catch (error) {
+    console.log(error);
+    return res.status(400).end();
+  }
+};
\ No newline at end of file
diff --git a/app/api/user/index.ts b/app/api/user/index.ts
new file mode 100644
index 0000000..abb35ff
--- /dev/null
+++ b/app/api/user/index.ts
@@ -0,0 +1,22 @@
+import { NextApiRequest, NextApiResponse } from "next";
+
+import { prisma } from "@/lib/db";
+
+export default async function handler(req: NextApiRequest, res: NextApiResponse) {
+  if (req.method !== 'GET') {
+    return res.status(405).end();
+  }
+
+  try {
+    const users = await prisma.user.findMany({
+      orderBy: {
+        createdAt: 'desc'
+      }
+    });
+
+    return res.status(200).json(users);
+  } catch(error) {
+    console.log(error);
+    return res.status(400).end();
+  }
+}
\ No newline at end of file
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index a6b261a..782106c 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -17,7 +17,8 @@ model User {
   email         String?   @unique
   password      String
   emailVerified DateTime?
-  image         String?
+  image         String?   
+  createdAt     DateTime @default(now())
 
   Post    Post[]
   Comment Comment[]
-- 
GitLab