From 2cb9af8d2bf26eb8643d48a8127b5675c259332e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=B6rdle=20Bot?= Date: Wed, 3 Dec 2025 14:06:32 +0100 Subject: [PATCH] =?UTF-8?q?Game:=20=C3=B6ffentliche=20Song-Liste=20f=C3=BC?= =?UTF-8?q?r=20GuessInput=20statt=20gesch=C3=BCtztem=20/api/songs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/public-songs/route.ts | 21 +++++++++++++++++++++ components/GuessInput.tsx | 22 +++++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 app/api/public-songs/route.ts diff --git a/app/api/public-songs/route.ts b/app/api/public-songs/route.ts new file mode 100644 index 0000000..e1410b0 --- /dev/null +++ b/app/api/public-songs/route.ts @@ -0,0 +1,21 @@ +import { NextResponse } from 'next/server'; +import { PrismaClient } from '@prisma/client'; + +const prisma = new PrismaClient(); + +// Öffentliche, schreibgeschützte Song-Liste für das Spiel (GuessInput etc.). +// Kein Auth, nur Lesen der nötigsten Felder. +export async function GET() { + const songs = await prisma.song.findMany({ + orderBy: { createdAt: 'desc' }, + select: { + id: true, + title: true, + artist: true, + }, + }); + + return NextResponse.json(songs); +} + + diff --git a/components/GuessInput.tsx b/components/GuessInput.tsx index 1e0c4b0..608cae8 100644 --- a/components/GuessInput.tsx +++ b/components/GuessInput.tsx @@ -22,9 +22,25 @@ export default function GuessInput({ onGuess, disabled }: GuessInputProps) { const [isOpen, setIsOpen] = useState(false); useEffect(() => { - fetch('/api/songs') - .then(res => res.json()) - .then(data => setSongs(data)); + fetch('/api/public-songs') + .then(res => { + if (!res.ok) { + throw new Error(`Failed to load songs: ${res.status}`); + } + return res.json(); + }) + .then(data => { + if (Array.isArray(data)) { + setSongs(data); + } else { + console.error('Unexpected songs payload in GuessInput:', data); + setSongs([]); + } + }) + .catch(err => { + console.error('Error loading songs for GuessInput:', err); + setSongs([]); + }); }, []); useEffect(() => {