wip
This commit is contained in:
50
apps/website/app/api/sponsors/route.ts
Normal file
50
apps/website/app/api/sponsors/route.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user