Files
gridpilot.gg/apps/website/app/api/sponsors/route.ts
2025-12-10 12:38:55 +01:00

50 lines
1.2 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
// Alpha: In-memory sponsor storage
const sponsors: Map<string, {
id: string;
name: string;
contactEmail: string;
websiteUrl?: string;
logoUrl?: string;
createdAt: Date;
}> = new Map();
export async function GET() {
const allSponsors = Array.from(sponsors.values());
return NextResponse.json({ sponsors: allSponsors });
}
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { name, contactEmail, websiteUrl, logoUrl } = body;
if (!name || !contactEmail) {
return NextResponse.json(
{ error: 'Name and contact email are required' },
{ status: 400 }
);
}
const id = `sponsor-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
const sponsor = {
id,
name,
contactEmail,
websiteUrl: websiteUrl || undefined,
logoUrl: logoUrl || undefined,
createdAt: new Date(),
};
sponsors.set(id, sponsor);
return NextResponse.json({ sponsor }, { status: 201 });
} catch (err) {
console.error('Sponsor creation failed:', err);
return NextResponse.json(
{ error: 'Failed to create sponsor' },
{ status: 500 }
);
}
}