Grapevine_Disease_Detection/vineye-admin/app/api/diseases/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

69 lines
1.9 KiB
TypeScript

import { NextRequest } from "next/server";
import { prisma } from "@/lib/prisma";
import { requireAdmin } from "@/lib/auth-guard";
import { diseaseSchema } from "@/lib/validations";
import { slugify } from "@/lib/utils";
export async function GET(request: NextRequest) {
const { searchParams } = request.nextUrl;
const type = searchParams.get("type");
const published = searchParams.get("published");
const where: Record<string, unknown> = {};
if (type) where.type = type;
if (published !== null) where.published = published === "true";
const diseases = await prisma.disease.findMany({
where,
orderBy: { createdAt: "desc" },
});
return Response.json({ data: diseases });
}
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 = diseaseSchema.safeParse(body);
if (!result.success) {
return Response.json(
{ error: "Validation failed", details: result.error.flatten() },
{ status: 400 }
);
}
const data = result.data;
const slug = data.slug || slugify(data.name);
const existing = await prisma.disease.findUnique({ where: { slug } });
if (existing) {
return Response.json({ error: "Ce slug existe deja" }, { status: 409 });
}
const { images, ...diseaseData } = data;
const disease = await prisma.disease.create({
data: { ...diseaseData, slug },
});
if (images && images.length > 0) {
await Promise.all(
images.map((img) =>
prisma.diseaseImage.create({ data: { ...img, diseaseId: disease.id } })
)
);
}
const created = await prisma.disease.findUnique({
where: { id: disease.id },
include: { images: { orderBy: { order: "asc" } } },
});
return Response.json({ data: created }, { status: 201 });
}