feat: mockup template CRUD API routes

This commit is contained in:
2026-06-22 12:10:26 +02:00
parent 01e2fcd5e5
commit 1ef69dc205
3 changed files with 55 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
import { NextRequest } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
import { listTemplates, saveTemplate } from '@/lib/mockupTemplates'
export async function GET() {
const session = await getServerSession(authOptions)
if (!session) return Response.json({ error: 'Non authentifié' }, { status: 401 })
const templates = await listTemplates()
return Response.json(templates)
}
export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions)
if (!session) return Response.json({ error: 'Non authentifié' }, { status: 401 })
const form = await req.formData()
const name = form.get('name') as string
const family = form.get('family') as string
const description = (form.get('description') as string) ?? ''
const imageFile = form.get('image') as File
if (!name || !family || !imageFile) {
return Response.json({ error: 'name, family et image requis' }, { status: 400 })
}
const buffer = Buffer.from(await imageFile.arrayBuffer())
const ext = imageFile.name.split('.').pop() ?? 'jpg'
const template = await saveTemplate({ name, family, description, filename: '' }, buffer, ext)
return Response.json(template)
}