From 0af3e16a2b0ff30aed5156fe20256a2c8d92ee0d Mon Sep 17 00:00:00 2001 From: AI Assistant Date: Mon, 23 Mar 2026 21:08:14 +0200 Subject: [PATCH] feat(geoportal): add /api/geoportal/setup-views endpoint for creating UAT zoom views Co-Authored-By: Claude Opus 4.6 (1M context) --- src/app/api/geoportal/setup-views/route.ts | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/app/api/geoportal/setup-views/route.ts diff --git a/src/app/api/geoportal/setup-views/route.ts b/src/app/api/geoportal/setup-views/route.ts new file mode 100644 index 0000000..eaeb980 --- /dev/null +++ b/src/app/api/geoportal/setup-views/route.ts @@ -0,0 +1,50 @@ +/** + * POST /api/geoportal/setup-views + * + * Creates the zoom-dependent UAT views for Martin vector tiles. + * Safe to re-run (CREATE OR REPLACE VIEW). + * Original geometry in GisUat.geom is NEVER modified. + */ +import { NextResponse } from "next/server"; +import { prisma } from "@/core/storage/prisma"; + +export const runtime = "nodejs"; +export const dynamic = "force-dynamic"; + +const VIEWS = [ + { + name: "gis_uats_z0", + sql: `CREATE OR REPLACE VIEW gis_uats_z0 AS SELECT siruta, name, ST_SimplifyPreserveTopology(geom, 2000) AS geom FROM "GisUat" WHERE geom IS NOT NULL`, + }, + { + name: "gis_uats_z5", + sql: `CREATE OR REPLACE VIEW gis_uats_z5 AS SELECT siruta, name, ST_SimplifyPreserveTopology(geom, 500) AS geom FROM "GisUat" WHERE geom IS NOT NULL`, + }, + { + name: "gis_uats_z8", + sql: `CREATE OR REPLACE VIEW gis_uats_z8 AS SELECT siruta, name, county, ST_SimplifyPreserveTopology(geom, 50) AS geom FROM "GisUat" WHERE geom IS NOT NULL`, + }, + { + name: "gis_uats_z12", + sql: `CREATE OR REPLACE VIEW gis_uats_z12 AS SELECT siruta, name, county, ST_SimplifyPreserveTopology(geom, 10) AS geom FROM "GisUat" WHERE geom IS NOT NULL`, + }, +]; + +export async function POST() { + const results: string[] = []; + + try { + for (const v of VIEWS) { + await prisma.$executeRawUnsafe(v.sql); + results.push(`${v.name} OK`); + } + + return NextResponse.json({ status: "ok", results }); + } catch (error) { + const msg = error instanceof Error ? error.message : "Unknown error"; + return NextResponse.json( + { status: "error", results, error: msg }, + { status: 500 } + ); + } +}