import { NextRequest, NextResponse } from 'next/server'; export const dynamic = 'force-dynamic'; const API_BASE_URL = process.env.NEXT_PUBLIC_BACKEND_API_URL || 'http://localhost:5104'; // GET /api/work-items/[id] - Get a single work item export async function GET( request: NextRequest, { params }: { params: { id: string } } ) { try { const id = parseInt(params.id); if (isNaN(id)) { return NextResponse.json( { error: 'Invalid ID format' }, { status: 400 } ); } const response = await fetch(`${API_BASE_URL}/api/WorkItem/${id}`, { method: 'GET', headers: { 'Content-Type': 'application/json', }, }); if (!response.ok) { if (response.status === 404) { return NextResponse.json( { error: 'Work item not found' }, { status: 404 } ); } throw new Error(`Backend API error: ${response.status}`); } const data = await response.json(); return NextResponse.json(data); } catch (error) { console.error('Error fetching work item:', error); return NextResponse.json( { error: 'Failed to fetch work item' }, { status: 500 } ); } } // PUT /api/work-items/[id] - Update a work item export async function PUT( request: NextRequest, { params }: { params: { id: string } } ) { try { const id = parseInt(params.id); if (isNaN(id)) { return NextResponse.json( { error: 'Invalid ID format' }, { status: 400 } ); } const body = await request.json(); const response = await fetch(`${API_BASE_URL}/api/WorkItem/${id}`, { method: 'PUT', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(body), }); if (!response.ok) { throw new Error(`Backend API error: ${response.status}`); } return NextResponse.json({ success: true }); } catch (error) { console.error('Error updating work item:', error); return NextResponse.json( { error: 'Failed to update work item' }, { status: 500 } ); } } // DELETE /api/work-items/[id] - Delete a work item export async function DELETE( request: NextRequest, { params }: { params: { id: string } } ) { try { const id = parseInt(params.id); if (isNaN(id)) { return NextResponse.json( { error: 'Invalid ID format' }, { status: 400 } ); } const response = await fetch(`${API_BASE_URL}/api/WorkItem/${id}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json', }, }); if (!response.ok) { throw new Error(`Backend API error: ${response.status}`); } return NextResponse.json({ success: true }); } catch (error) { console.error('Error deleting work item:', error); return NextResponse.json( { error: 'Failed to delete work item' }, { status: 500 } ); } }