fix: CQRS
parent
223a1af6c9
commit
5e571d00ed
|
|
@ -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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<WorkItem[]> {
|
||||
return this.fetchApi<WorkItem[]>('/api/WorkItem');
|
||||
return this.fetchApi<WorkItem[]>('/api/work-items');
|
||||
}
|
||||
|
||||
async getWorkItem(id: number): Promise<WorkItem> {
|
||||
return this.fetchApi<WorkItem>(`/api/WorkItem/${id}`);
|
||||
return this.fetchApi<WorkItem>(`/api/work-items/${id}`);
|
||||
}
|
||||
|
||||
async createWorkItem(workItem: WorkItemFormData): Promise<WorkItem> {
|
||||
|
|
@ -55,21 +55,21 @@ export class WorkItemApiClient {
|
|||
status: 0, // Default to Pending
|
||||
};
|
||||
|
||||
return this.fetchApi<WorkItem>('/api/WorkItem', {
|
||||
return this.fetchApi<WorkItem>('/api/work-items', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(newWorkItem),
|
||||
});
|
||||
}
|
||||
|
||||
async updateWorkItem(id: number, workItem: WorkItem): Promise<void> {
|
||||
await this.fetchApi(`/api/WorkItem/${id}`, {
|
||||
await this.fetchApi(`/api/work-items/${id}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(workItem),
|
||||
});
|
||||
}
|
||||
|
||||
async deleteWorkItem(id: number): Promise<void> {
|
||||
await this.fetchApi(`/api/WorkItem/${id}`, {
|
||||
await this.fetchApi(`/api/work-items/${id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
output: 'export',
|
||||
eslint: {
|
||||
ignoreDuringBuilds: true,
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue