|
| 1 | +import { NextRequest, NextResponse } from 'next/server'; |
| 2 | +import { serverStorage } from '@/lib/serverStorage'; |
| 3 | + |
| 4 | +/** |
| 5 | + * GET /api/designs/:id - Get a single design |
| 6 | + */ |
| 7 | +export async function GET( |
| 8 | + request: NextRequest, |
| 9 | + { params }: { params: Promise<{ id: string }> } |
| 10 | +) { |
| 11 | + try { |
| 12 | + const { id } = await params; |
| 13 | + const design = serverStorage.getDesign(id); |
| 14 | + |
| 15 | + if (!design) { |
| 16 | + return NextResponse.json( |
| 17 | + { error: 'Design not found' }, |
| 18 | + { status: 404 } |
| 19 | + ); |
| 20 | + } |
| 21 | + |
| 22 | + return NextResponse.json(design); |
| 23 | + } catch (error) { |
| 24 | + console.error('Error fetching design:', error); |
| 25 | + return NextResponse.json( |
| 26 | + { error: 'Failed to fetch design' }, |
| 27 | + { status: 500 } |
| 28 | + ); |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * PUT /api/designs/:id - Update a design |
| 34 | + */ |
| 35 | +export async function PUT( |
| 36 | + request: NextRequest, |
| 37 | + { params }: { params: Promise<{ id: string }> } |
| 38 | +) { |
| 39 | + try { |
| 40 | + const { id } = await params; |
| 41 | + const body = await request.json(); |
| 42 | + |
| 43 | + const updatedDesign = serverStorage.updateDesign(id, body); |
| 44 | + |
| 45 | + if (!updatedDesign) { |
| 46 | + return NextResponse.json( |
| 47 | + { error: 'Design not found' }, |
| 48 | + { status: 404 } |
| 49 | + ); |
| 50 | + } |
| 51 | + |
| 52 | + return NextResponse.json(updatedDesign); |
| 53 | + } catch (error) { |
| 54 | + console.error('Error updating design:', error); |
| 55 | + return NextResponse.json( |
| 56 | + { error: 'Failed to update design' }, |
| 57 | + { status: 500 } |
| 58 | + ); |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +/** |
| 63 | + * DELETE /api/designs/:id - Delete a design |
| 64 | + */ |
| 65 | +export async function DELETE( |
| 66 | + request: NextRequest, |
| 67 | + { params }: { params: Promise<{ id: string }> } |
| 68 | +) { |
| 69 | + try { |
| 70 | + const { id } = await params; |
| 71 | + const deleted = serverStorage.deleteDesign(id); |
| 72 | + |
| 73 | + if (!deleted) { |
| 74 | + return NextResponse.json( |
| 75 | + { error: 'Design not found' }, |
| 76 | + { status: 404 } |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + return NextResponse.json({ success: true }); |
| 81 | + } catch (error) { |
| 82 | + console.error('Error deleting design:', error); |
| 83 | + return NextResponse.json( |
| 84 | + { error: 'Failed to delete design' }, |
| 85 | + { status: 500 } |
| 86 | + ); |
| 87 | + } |
| 88 | +} |
0 commit comments