diff --git a/app/(content)/(community)/communities/page.tsx b/app/(content)/(community)/communities/page.tsx deleted file mode 100644 index 7a1e2cfa04c7c5585326afa281e80d9b89cc765d..0000000000000000000000000000000000000000 --- a/app/(content)/(community)/communities/page.tsx +++ /dev/null @@ -1,7 +0,0 @@ -export default function CommunitiesPage() { - return ( - <div> - <h1>Community WIP</h1> - </div> - ) -} \ No newline at end of file diff --git a/app/(content)/(search)/search/page.tsx b/app/(content)/(search)/search/page.tsx new file mode 100644 index 0000000000000000000000000000000000000000..cb8d68edd738d54202a2ea8066adcaf25b04772a --- /dev/null +++ b/app/(content)/(search)/search/page.tsx @@ -0,0 +1,19 @@ +import { GlobalLayout } from "@/components/global-layout" + +export default async function SearchPage() { + return ( + <GlobalLayout + mainContent={ + <> + Search Page + </> + } + + sideContent={ + <> + + </> + } + /> + ) +} \ No newline at end of file diff --git a/app/api/games/route.ts b/app/api/games/route.ts index 04d0ee92cb77c31e5331e1d5a346d4e8d440e681..8af8dfb2cf1203f6092531762fdc32620b6532aa 100644 --- a/app/api/games/route.ts +++ b/app/api/games/route.ts @@ -37,7 +37,7 @@ export async function GET(req: NextRequest) { sortby ? sortby : undefined, order ? order : undefined ) - return NextResponse.json(games) + return NextResponse.json(games, { status: 200 }) } catch (error) { return NextResponse.json(error, { status: 500 }) } diff --git a/app/api/gweets/[id]/route.ts b/app/api/gweets/[id]/route.ts index a9c706539844ac3becd0dc6549fb977d1e65391d..13408317200201894c5654d6d433ed0068268005 100644 --- a/app/api/gweets/[id]/route.ts +++ b/app/api/gweets/[id]/route.ts @@ -3,7 +3,6 @@ import { z } from "zod" import { db } from "@/lib/db" -// get a single gweet export async function GET(request: Request, { params }: { params: { id: string } }) { const { id } = params @@ -12,12 +11,10 @@ export async function GET(request: Request, { params }: { params: { id: string } const zod = gweetIdSchema.safeParse(id) if (!zod.success) { - return NextResponse.json( - { - message: "Invalid request body", - error: zod.error.formErrors, - }, { status: 400 }, - ) + return NextResponse.json({ + message: "Invalid request body", + error: zod.error.formErrors, + }, { status: 400 }) } try { @@ -96,20 +93,16 @@ export async function GET(request: Request, { params }: { params: { id: string } }) if (!gweet) { - return NextResponse.json( - { - message: "Gweet not found", - }, { status: 404 }, - ) + return NextResponse.json({ + message: "Gweet not found", + }, { status: 404 }) } return NextResponse.json(gweet, { status: 200 }) } catch (error) { - return NextResponse.json( - { - message: "Something went wrong", - error, - }, { status: 500 }, - ) + return NextResponse.json({ + message: "Something went wrong", + error, + }, { status: 500 }) } } \ No newline at end of file diff --git a/app/api/gweets/likes/route.ts b/app/api/gweets/likes/route.ts index 6c298fed796a99885baa5826724286a7097b2550..f560fe5e44116dc9eea9244939c704be0534ef07 100644 --- a/app/api/gweets/likes/route.ts +++ b/app/api/gweets/likes/route.ts @@ -3,7 +3,6 @@ import { z } from "zod" import { db } from "@/lib/db" -// get likes from user export async function GET(request: Request) { const { searchParams } = new URL(request.url) const user_id = searchParams.get("user_id") || undefined @@ -41,16 +40,13 @@ export async function GET(request: Request) { return NextResponse.json(gweets, { status: 200 }) } catch (error: any) { - return NextResponse.json( - { - message: "Something went wrong", - error: error.message, - }, { status: error.errorCode || 500 }, - ) + return NextResponse.json({ + message: "Something went wrong", + error: error.message, + }, { status: error.errorCode || 500 }) } } -// like and dislike export async function POST(request: Request) { const { gweet_id, user_id } = await request.json() @@ -64,12 +60,10 @@ export async function POST(request: Request) { const zod = likeSchema.safeParse({ gweet_id, user_id }) if (!zod.success) { - return NextResponse.json( - { - message: "Invalid request body", - error: zod.error.formErrors, - }, { status: 400 }, - ) + return NextResponse.json({ + message: "Invalid request body", + error: zod.error.formErrors, + }, { status: 400 }) } try { @@ -87,7 +81,7 @@ export async function POST(request: Request) { }, }) - return NextResponse.json({ message: "Gweet unliked" }) + return NextResponse.json({ message: "Gweet unliked" }, { status: 200 }) } else { await db.like.create({ data: { @@ -96,12 +90,12 @@ export async function POST(request: Request) { }, }) - return NextResponse.json({ message: "Gweet liked" }) + return NextResponse.json({ message: "Gweet liked" }, { status: 201 }) } } catch (error: any) { return NextResponse.json({ message: "Something went wrong", error: error.message, - }) + }, { status: 500 }) } } \ No newline at end of file diff --git a/app/api/gweets/regweets/route.ts b/app/api/gweets/regweets/route.ts index 1cc824193d6af5d418bb82692d660f6a01f709f8..00a446ef38a0c9d8c1c309c4bc75fc2027e96783 100644 --- a/app/api/gweets/regweets/route.ts +++ b/app/api/gweets/regweets/route.ts @@ -16,12 +16,10 @@ export async function POST(request: Request) { const zod = regweetSchema.safeParse({ gweet_id, user_id }) if (!zod.success) { - return NextResponse.json( - { - message: "Invalid request body", - error: zod.error.formErrors, - }, { status: 400 }, - ) + return NextResponse.json({ + message: "Invalid request body", + error: zod.error.formErrors, + }, { status: 400 }) } try { @@ -39,7 +37,7 @@ export async function POST(request: Request) { }, }) - return NextResponse.json({ message: "Deleted gweet regweet" }) + return NextResponse.json({ message: "Deleted gweet regweet" }, { status: 200 }) } else { await db.regweet.create({ data: { @@ -48,7 +46,7 @@ export async function POST(request: Request) { }, }) - return NextResponse.json({ message: "Gweet regweeted" }) + return NextResponse.json({ message: "Gweet regweeted" }, { status: 201 }) } } catch (error: any) { return NextResponse.json({ error: error.message }, { status: 500 }) diff --git a/app/api/gweets/route.ts b/app/api/gweets/route.ts index 9cdd2abc94973da1f1d8c1cb457781a867845cc2..4f5903d9bf64f21bf738dc71399fe9f920160cc0 100644 --- a/app/api/gweets/route.ts +++ b/app/api/gweets/route.ts @@ -4,7 +4,6 @@ import { z } from "zod" import { db } from "@/lib/db" import { utapi } from "uploadthing/server" -// get gweets export async function GET(request: Request) { const { searchParams } = new URL(request.url) @@ -32,7 +31,7 @@ export async function GET(request: Request) { // // logic correct TODO get all gweets above comment // const prevId = thread.length < 4 ? undefined : thread[thread.length - 1].id - // return NextResponse.json({ gweets: thread, prevId }) + // return NextResponse.json({ gweets: thread, prevId }, { status: 200 }) // } const gweets = await db.gweet.findMany({ @@ -128,13 +127,12 @@ export async function GET(request: Request) { const nextId = gweets.length < take ? undefined : gweets[gweets.length - 1].id - return NextResponse.json({ gweets, nextId }) + return NextResponse.json({ gweets, nextId }, { status: 200 }) } catch (error) { - return NextResponse.error() + return NextResponse.json(error, { status: 500 }) } } -// create gweet export async function POST(request: Request) { const { gweet, fileprops } = await request.json() @@ -159,12 +157,10 @@ export async function POST(request: Request) { ) if (!zodGweet.success) { - return NextResponse.json( - { - message: "Invalid request body", - error: zodGweet.error.formErrors, - }, { status: 400 }, - ) + return NextResponse.json({ + message: "Invalid request body", + error: zodGweet.error.formErrors, + }, { status: 400 }) } try { @@ -189,12 +185,10 @@ export async function POST(request: Request) { const zodMedia = mediaSchema.safeParse(mediaArray) if (!zodMedia.success) { - return NextResponse.json( - { - message: "Invalid media body", - error: zodMedia.error.formErrors, - }, { status: 400 }, - ) + return NextResponse.json({ + message: "Invalid media body", + error: zodMedia.error.formErrors, + }, { status: 400 }) } await db.media.createMany({ @@ -202,18 +196,15 @@ export async function POST(request: Request) { }) } - return NextResponse.json(created_gweet, { status: 200 }) + return NextResponse.json(created_gweet, { status: 201 }) } catch (error: any) { - return NextResponse.json( - { - message: "Something went wrong", - error: error.message, - }, { status: error.errorCode || 500 }, - ) + return NextResponse.json({ + message: "Something went wrong", + error: error.message, + }, { status: error.errorCode || 500 }) } } -// delete gweet export async function DELETE(request: Request) { const { searchParams } = new URL(request.url) const id = searchParams.get("id") as string @@ -247,14 +238,12 @@ export async function DELETE(request: Request) { }, }) - return NextResponse.json({ message: "Gweet deleted successfully", }) + return NextResponse.json({ message: "Gweet deleted" }, { status: 200 }) } catch (error: any) { - return NextResponse.json( - { - message: "Something went wrong", - error: error.message, - }, { status: error.errorCode || 500 }, - ) + return NextResponse.json({ + message: "Something went wrong", + error: error.message, + }, { status: error.errorCode || 500 }) } } diff --git a/app/api/hashtags/route.ts b/app/api/hashtags/route.ts index b4ffb8ef97ebee57128b889e83ab2264d6c5aefe..58ee86ebdecd344bc86dd8d6a5d028eb0c72438b 100644 --- a/app/api/hashtags/route.ts +++ b/app/api/hashtags/route.ts @@ -57,18 +57,8 @@ export async function POST(request: Request) { } } - return NextResponse.json( - { - message: "Hashtag(s) created", - }, - { status: 200 }, - ) + return NextResponse.json({ message: "Hashtag(s) created", }, { status: 201 }) } catch (error: any) { - return NextResponse.json( - { - error: error.message, - }, - { status: 500 }, - ) + return NextResponse.json({ error: error.message, }, { status: 500 },) } } \ No newline at end of file diff --git a/app/api/route.ts b/app/api/route.ts index ae6ece829b02260a63fbd9add4bcd171f9e5a215..8672d2778c10343280dc3f6d89d28c530136c270 100644 --- a/app/api/route.ts +++ b/app/api/route.ts @@ -9,5 +9,5 @@ export async function GET() { return new NextResponse(JSON.stringify({ error: 'unauthorized' }), { status: 401 }) } - return NextResponse.json({ authenticated: !!session }) + return NextResponse.json({ authenticated: !!session }, { status: 200 }) } \ No newline at end of file diff --git a/app/api/signup/route.ts b/app/api/signup/route.ts index ffb9dbaa646337cc621f18ecf6cd6a80ce49d71b..d754d92b38ce52c4fbd73c70a34a6baa07b9d891 100644 --- a/app/api/signup/route.ts +++ b/app/api/signup/route.ts @@ -19,7 +19,7 @@ export async function POST(req: Request) { }) if (existingUser) { - throw new Error('email already exists') + return NextResponse.json({ error: 'Email already exists' }, { status: 422 }) } let isUnique = false @@ -46,21 +46,11 @@ export async function POST(req: Request) { } }) + return NextResponse.json({ usernameOrEmail: user.email }) + } catch (error) { return NextResponse.json({ - usernameOrEmail: user.email - }) - } catch (err: any) { - if (err.message === 'email already exists') { - return new NextResponse(JSON.stringify({ - error: err.message - }), { status: 422 } - ) - } - - return new NextResponse( - JSON.stringify({ - error: err.message - }), { status: 500 } - ) + message: "Something went wrong", + error, + }, { status: 500 }) } } \ No newline at end of file diff --git a/app/api/users/favgameslist/route.ts b/app/api/users/favgameslist/route.ts index 967f901545abfd58534d1ed046c04023319a6afb..67bd79f2c75a37bc649488a92df2e41cefd8d826 100644 --- a/app/api/users/favgameslist/route.ts +++ b/app/api/users/favgameslist/route.ts @@ -51,9 +51,9 @@ export async function PUT(req: NextRequest) { const path = req.nextUrl.searchParams.get('path') || '/' revalidatePath(path) - return NextResponse.json({ status: 201, message: 'Game Hinzugefügt' }) + return NextResponse.json({ message: 'Game added' }, { status: 201 }) } catch (error: any) { - return NextResponse.json({ status: 500, message: error.message }) + return NextResponse.json({ message: error.message }, { status: 500 }) } } \ No newline at end of file diff --git a/app/api/gamelists/route.ts b/app/api/users/gamelists/route.ts similarity index 79% rename from app/api/gamelists/route.ts rename to app/api/users/gamelists/route.ts index 7c578b3ef8e25ba5431237bbfe24b459b46b5dd6..629f995d73d5ada83642ee9c5079cb9e421aed31 100644 --- a/app/api/gamelists/route.ts +++ b/app/api/users/gamelists/route.ts @@ -8,11 +8,11 @@ export async function PUT(req: NextRequest) { const sessionUser = await getCurrentUser() const data: User = await req.json() - console.log("userid", sessionUser!.id, "formdataid", data.id) + if (!sessionUser || sessionUser.id != data.id) { - return NextResponse.json({ status: 401, message: 'Unauthorized' }) + return NextResponse.json({ message: 'Unauthorized' }, { status: 401 }) } - console.log("put list") + try { const dbUser = await db.user.findFirst({ where: { @@ -41,11 +41,12 @@ export async function PUT(req: NextRequest) { } }) } - } catch (error) { - } - const path = req.nextUrl.searchParams.get('path') || '/' - revalidatePath(path) + const path = req.nextUrl.searchParams.get('path') || '/' + revalidatePath(path) - return NextResponse.json({ status: 201, message: 'Game Hinzugefügt' }) + return NextResponse.json({ message: 'Game added' }, { status: 201 }) + } catch (error: any) { + return NextResponse.json({ message: error.message }, { status: 500 }) + } } \ No newline at end of file diff --git a/app/api/users/route.ts b/app/api/users/route.ts index e0611fd2ca092f2ec42df17c1c6a0205df646740..7f3814a20547512e139f8877290c2d958691fed8 100644 --- a/app/api/users/route.ts +++ b/app/api/users/route.ts @@ -2,7 +2,6 @@ import { db } from "@/lib/db" import { NextResponse } from "next/server" import { z } from "zod" -// get all other users export async function GET(request: Request) { const { searchParams } = new URL(request.url) const id = searchParams.get("id") || undefined diff --git a/components/add-game-to-finished-list.tsx b/components/add-game-to-finished-list.tsx index bc37572a92fb214c02fa29e9ac094296782b856e..6f8ec4fec6592b7d0ef72a7b9c7fb5e990d99822 100644 --- a/components/add-game-to-finished-list.tsx +++ b/components/add-game-to-finished-list.tsx @@ -33,7 +33,7 @@ export default function AddGameToFinishedList(props: { gameId: string, user: Use formData.id = user.id formData.finishedGameList = props.user.finishedGameList.filter((id) => id !== gameId) console.log(formData.finishedGameList) - const response = await fetch('/api/gamelists', { + const response = await fetch('/api/users/gamelists', { method: 'PUT', body: JSON.stringify(formData) }) @@ -52,7 +52,7 @@ export default function AddGameToFinishedList(props: { gameId: string, user: Use formData.id = user.id props.user.finishedGameList.push(gameId) formData.finishedGameList = props.user.finishedGameList - const response = await fetch('/api/gamelists', { + const response = await fetch('/api/users/gamelists', { method: 'PUT', body: JSON.stringify(formData) }) diff --git a/components/add-game-to-plan-list.tsx b/components/add-game-to-plan-list.tsx index 61f62e85fa0c4ad352a0b7b680769904b34c91d4..9de2099cfc9a791adeeb582fa51f2951246130ea 100644 --- a/components/add-game-to-plan-list.tsx +++ b/components/add-game-to-plan-list.tsx @@ -33,7 +33,7 @@ export default function AddGameToPlanList(props: { gameId: string, user: User }) formData.id = user.id formData.planningGameList = props.user.planningGameList.filter((id) => id !== gameId) console.log(formData.planningGameList) - const response = await fetch('/api/gamelists', { + const response = await fetch('/api/users/gamelists', { method: 'PUT', body: JSON.stringify(formData) }) @@ -52,7 +52,7 @@ export default function AddGameToPlanList(props: { gameId: string, user: User }) formData.id = user.id props.user.planningGameList.push(gameId) formData.planningGameList = props.user.planningGameList - const response = await fetch('/api/gamelists', { + const response = await fetch('/api/users/gamelists', { method: 'PUT', body: JSON.stringify(formData) }) diff --git a/components/add-game-to-playing-list.tsx b/components/add-game-to-playing-list.tsx index 73e8067728687051a7b63e67640a5a5c014238d7..81232c6e72774bc9e86d07f90d7970f1fc070fd0 100644 --- a/components/add-game-to-playing-list.tsx +++ b/components/add-game-to-playing-list.tsx @@ -33,7 +33,7 @@ export default function AddGameToPlayingList(props: { gameId: string, user: User formData.id = user.id formData.playingGameList = props.user.playingGameList.filter((id) => id !== gameId) console.log(formData.playingGameList) - const response = await fetch('/api/gamelists', { + const response = await fetch('/api/users/gamelists', { method: 'PUT', body: JSON.stringify(formData) }) @@ -52,7 +52,7 @@ export default function AddGameToPlayingList(props: { gameId: string, user: User formData.id = user.id props.user.playingGameList.push(gameId) formData.playingGameList = props.user.playingGameList - const response = await fetch('/api/gamelists', { + const response = await fetch('/api/users/gamelists', { method: 'PUT', body: JSON.stringify(formData) }) diff --git a/components/user-auth-form.tsx b/components/user-auth-form.tsx index 21a0d035f98ffca9d1a140cb8837476d7fd1fb98..9ce00468bcd0ab0f760f86e1a5ae7a477e35e16a 100644 --- a/components/user-auth-form.tsx +++ b/components/user-auth-form.tsx @@ -55,6 +55,8 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) { if (!res.ok) { if (res.status === 422) { setError('email', { type: 'manual', message: 'This email is already in use. Please choose another one.' }) + setIsLoading(false) + return } setIsLoading(false)