working ish version one with rooms, thx to claude

This commit is contained in:
2026-01-27 20:52:10 -06:00
parent 10cd0b2416
commit e06087e19f
14 changed files with 383 additions and 107 deletions

View File

@@ -0,0 +1,41 @@
import { NextResponse } from 'next/server';
import { getRoom, closeRoom, leaveRoom } from '@/lib/rooms';
export async function GET(
req: Request,
{ params }: { params: Promise<{ code: string }> }
) {
const { code } = await params;
const room = getRoom(code);
if (!room) {
return NextResponse.json({ error: 'Room not found' }, { status: 404 });
}
return NextResponse.json({
code: room.code,
playerCount: room.players.size,
players: Array.from(room.players.values()),
isActive: room.isActive,
});
}
export async function POST(
req: Request,
{ params }: { params: Promise<{ code: string }> }
) {
const { code } = await params;
const body = await req.json();
if (body.action === 'close') {
const success = closeRoom(code, body.moderatorId);
return NextResponse.json({ success });
}
if (body.action === 'leave') {
const success = leaveRoom(code, body.playerId);
return NextResponse.json({ success });
}
return NextResponse.json({ error: 'Invalid action' }, { status: 400 });
}

View File

@@ -0,0 +1,7 @@
import { NextResponse } from 'next/server';
import { createRoom } from '@/lib/rooms';
export async function POST() {
const { code, moderatorId } = createRoom();
return NextResponse.json({ code, moderatorId });
}

View File

@@ -0,0 +1,13 @@
import { NextResponse } from 'next/server';
import { joinRoom } from '@/lib/rooms';
export async function POST(req: Request) {
const { code, playerName } = await req.json();
const result = joinRoom(code, playerName);
if (!result) {
return NextResponse.json({ error: 'Room not found' }, { status: 404 });
}
return NextResponse.json(result);
}