Grapevine_Disease_Detection/vineye-admin/app/api/guides/route.ts
Yanis 720dd34fdd add MyPlantsScreen + ScanDetailScreen + enriched admin + API mobile + project summary
Mobile:
- Replace LibraryScreen with MyPlantsScreen (date-grouped scan list, swipe actions, search, pull-to-refresh)
- Add ScanDetailScreen (immersive hero, confidence bar, cepage card, share/delete)
- Add DiseaseDetailScreen + GuideDetailScreen (hero pattern, animated entry)
- Add useScanDetail, useHistory (useCallback fix), dateGrouping utility
- Connect diseases/guides to admin API with cache + offline fallback
- Add NetworkContext, ToastContext, Skeleton loading components
- Extend ScanRecord type (isFavorite, location)
- Full i18n FR/EN for all new screens

Admin (vineye-admin):
- Enrich Disease/Guide Prisma schema (timeline, conditions, actions, sections)
- Enriched disease-form (7 sections) + guide-form (structured sections editor)
- Add mobile public API endpoints (diseases, guides by slug)
- Add Prisma migration + enriched seed data
- UI polish: sidebar, login, layout updates

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 03:19:39 +02:00

66 lines
1.8 KiB
TypeScript

import { NextRequest } from "next/server";
import { prisma } from "@/lib/prisma";
import { requireAdmin } from "@/lib/auth-guard";
import { guideSchema } from "@/lib/validations";
import { slugify } from "@/lib/utils";
export async function GET(request: NextRequest) {
const { searchParams } = request.nextUrl;
const published = searchParams.get("published");
const where: Record<string, unknown> = {};
if (published !== null) where.published = published === "true";
const guides = await prisma.guide.findMany({
where,
include: { sections: { orderBy: { order: "asc" } } },
orderBy: { order: "asc" },
});
return Response.json({ data: guides });
}
export async function POST(request: NextRequest) {
const auth = await requireAdmin();
if ("error" in auth) {
return Response.json({ error: auth.error }, { status: auth.status });
}
const body = await request.json();
const result = guideSchema.safeParse(body);
if (!result.success) {
return Response.json(
{ error: "Validation failed", details: result.error.flatten() },
{ status: 400 },
);
}
const { sections, ...guideData } = result.data;
const slug = guideData.slug || slugify(guideData.title);
const existing = await prisma.guide.findUnique({ where: { slug } });
if (existing) {
return Response.json({ error: "Ce slug existe deja" }, { status: 409 });
}
const guide = await prisma.guide.create({
data: { ...guideData, slug },
});
if (sections && sections.length > 0) {
await Promise.all(
sections.map((s) =>
prisma.guideSection.create({ data: { ...s, guideId: guide.id } }),
),
);
}
const created = await prisma.guide.findUnique({
where: { id: guide.id },
include: { sections: { orderBy: { order: "asc" } } },
});
return Response.json({ data: created }, { status: 201 });
}