diff --git a/app/api/work-items/[id]/route.ts b/app/api/work-items/[id]/route.ts new file mode 100644 index 0000000..9b50093 --- /dev/null +++ b/app/api/work-items/[id]/route.ts @@ -0,0 +1,120 @@ +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 } + ); + } +} \ No newline at end of file diff --git a/app/api/work-items/route.ts b/app/api/work-items/route.ts new file mode 100644 index 0000000..8b78f64 --- /dev/null +++ b/app/api/work-items/route.ts @@ -0,0 +1,58 @@ +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 - Get all work items +export async function GET() { + try { + const response = await fetch(`${API_BASE_URL}/api/WorkItem`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }); + + if (!response.ok) { + throw new Error(`Backend API error: ${response.status}`); + } + + const data = await response.json(); + return NextResponse.json(data); + } catch (error) { + console.error('Error fetching work items:', error); + return NextResponse.json( + { error: 'Failed to fetch work items' }, + { status: 500 } + ); + } +} + +// POST /api/work-items - Create a new work item +export async function POST(request: NextRequest) { + try { + const body = await request.json(); + debugger; + const response = await fetch(`${API_BASE_URL}/api/WorkItem`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(body), + }); + + if (!response.ok) { + throw new Error(`Backend API error: ${response.status}`); + } + + const data = await response.json(); + return NextResponse.json(data, { status: 201 }); + } catch (error) { + console.error('Error creating work item:', error); + return NextResponse.json( + { error: 'Failed to create work item' }, + { status: 500 } + ); + } +} \ No newline at end of file diff --git a/lib/api-client.ts b/lib/api-client.ts index 7e14c91..9510b0f 100644 --- a/lib/api-client.ts +++ b/lib/api-client.ts @@ -1,6 +1,6 @@ import { WorkItem, WorkItemFormData } from './types'; -const API_BASE_URL = 'http://localhost:5104'; +const API_BASE_URL = ''; export class WorkItemApiClient { private baseUrl: string; @@ -41,11 +41,11 @@ export class WorkItemApiClient { } async getWorkItems(): Promise { - return this.fetchApi('/api/WorkItem'); + return this.fetchApi('/api/work-items'); } async getWorkItem(id: number): Promise { - return this.fetchApi(`/api/WorkItem/${id}`); + return this.fetchApi(`/api/work-items/${id}`); } async createWorkItem(workItem: WorkItemFormData): Promise { @@ -55,21 +55,21 @@ export class WorkItemApiClient { status: 0, // Default to Pending }; - return this.fetchApi('/api/WorkItem', { + return this.fetchApi('/api/work-items', { method: 'POST', body: JSON.stringify(newWorkItem), }); } async updateWorkItem(id: number, workItem: WorkItem): Promise { - await this.fetchApi(`/api/WorkItem/${id}`, { + await this.fetchApi(`/api/work-items/${id}`, { method: 'PUT', body: JSON.stringify(workItem), }); } async deleteWorkItem(id: number): Promise { - await this.fetchApi(`/api/WorkItem/${id}`, { + await this.fetchApi(`/api/work-items/${id}`, { method: 'DELETE', }); } diff --git a/next.config.js b/next.config.js index b321514..b6f0d8b 100644 --- a/next.config.js +++ b/next.config.js @@ -1,6 +1,5 @@ /** @type {import('next').NextConfig} */ const nextConfig = { - output: 'export', eslint: { ignoreDuringBuilds: true, },