mirror of
https://github.com/yusufipk/RepoHub.git
synced 2026-09-11 18:46:07 +00:00
fix: address code review feedback
- Add validation for categories and experienceLevel in GET endpoint - Fix type safety: remove 'any' types, use proper Platform type - Fix hardcoded translations in Header component - Refactor platform loading to use centralized platform list - Remove duplicate getPackageManagerForOS logic - Improve architectural consistency and DRY principles Resolves Gemini Code Assist review comments
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { RecommendationService } from "@/services/recommendationService";
|
||||
import { RecommendationRequest } from "@/types/recommendations";
|
||||
import { RecommendationRequest, UserCategory, ExperienceLevel } from "@/types/recommendations";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
@@ -151,18 +151,52 @@ export async function GET(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
// Validate categories
|
||||
const validCategories: UserCategory[] = [
|
||||
"development",
|
||||
"design",
|
||||
"multimedia",
|
||||
"system-tools",
|
||||
"gaming",
|
||||
"productivity",
|
||||
"education",
|
||||
];
|
||||
const invalidCategories = categories.filter(
|
||||
(cat) => !validCategories.includes(cat as UserCategory)
|
||||
);
|
||||
if (invalidCategories.length > 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: `Invalid categories: ${invalidCategories.join(", ")}`,
|
||||
validCategories,
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Validate experience level if provided
|
||||
const validExperienceLevels: ExperienceLevel[] = ["beginner", "intermediate", "advanced"];
|
||||
if (experienceLevel && !validExperienceLevels.includes(experienceLevel as ExperienceLevel)) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: `Invalid experience_level. Must be one of: ${validExperienceLevels.join(", ")}`,
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Set default limit
|
||||
const parsedLimit =
|
||||
limit && parseInt(limit) > 0 && parseInt(limit) <= 50
|
||||
? parseInt(limit)
|
||||
: 20;
|
||||
|
||||
// Generate recommendations
|
||||
// Generate recommendations with validated types
|
||||
const recommendations = await RecommendationService.generateRecommendations(
|
||||
{
|
||||
platform_id: platformId,
|
||||
categories: categories as any,
|
||||
experienceLevel: experienceLevel as any,
|
||||
categories: categories as UserCategory[],
|
||||
experienceLevel: experienceLevel as ExperienceLevel | undefined,
|
||||
limit: parsedLimit,
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user