Files
peakskills/app/api/skills/route.ts
Julien Froidefond 72b653de19 feat: refactor skills API and database schema
- 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.
2025-08-21 09:55:35 +02:00

41 lines
1.2 KiB
TypeScript

import { NextResponse } from "next/server";
import { SkillsService } from "@/services";
import { SkillCategory } from "@/lib/types";
export async function GET() {
try {
const skillCategories = await SkillsService.getSkillCategories();
return NextResponse.json(skillCategories);
} catch (error) {
console.error("Error loading skills:", error);
return NextResponse.json(
{ error: "Failed to load skills" },
{ status: 500 }
);
}
}
export async function POST(request: Request) {
try {
const categoryData: { id: string; name: string; icon: string } =
await request.json();
// Validate required fields
if (!categoryData.id || !categoryData.name || !categoryData.icon) {
return NextResponse.json(
{ error: "Missing required fields: id, name, icon" },
{ status: 400 }
);
}
await SkillsService.createSkillCategory(categoryData);
return NextResponse.json({ success: true }, { status: 201 });
} catch (error) {
console.error("Error creating skill category:", error);
return NextResponse.json(
{ error: "Failed to create skill category" },
{ status: 500 }
);
}
}