- Replaced file-based skill category loading with API calls in the GET and POST methods of the skills route. - Added new `SkillsService` for handling skill category operations. - Updated SQL initialization script to create `skill_categories`, `skills`, and `skill_links` tables with appropriate relationships. - Enhanced `ApiClient` with methods for loading skill categories and creating new skills, improving API interaction. - Introduced error handling for skill category creation and loading processes.
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { SkillsService } from "@/services";
|
|
|
|
interface RouteParams {
|
|
params: {
|
|
categoryId: string;
|
|
};
|
|
}
|
|
|
|
export async function GET(request: Request, { params }: RouteParams) {
|
|
try {
|
|
const skills = await SkillsService.getSkillsByCategory(params.categoryId);
|
|
return NextResponse.json(skills);
|
|
} catch (error) {
|
|
console.error("Error loading skills by category:", error);
|
|
return NextResponse.json(
|
|
{ error: "Failed to load skills by category" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|
|
export async function POST(request: Request, { params }: RouteParams) {
|
|
try {
|
|
const skillData: {
|
|
id: string;
|
|
name: string;
|
|
description: string;
|
|
icon?: string;
|
|
links: string[];
|
|
} = await request.json();
|
|
|
|
// Validate required fields
|
|
if (!skillData.id || !skillData.name || !skillData.description) {
|
|
return NextResponse.json(
|
|
{ error: "Missing required fields: id, name, description" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
await SkillsService.createSkill({
|
|
...skillData,
|
|
categoryId: params.categoryId,
|
|
links: skillData.links || [],
|
|
});
|
|
|
|
return NextResponse.json({ success: true }, { status: 201 });
|
|
} catch (error) {
|
|
console.error("Error creating skill:", error);
|
|
return NextResponse.json(
|
|
{ error: "Failed to create skill" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|