Skip to content

Commit

Permalink
quick API endpoint to check if council has A4 schema set
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed May 20, 2024
1 parent 19570b9 commit 58cb7ce
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
2 changes: 2 additions & 0 deletions api.planx.uk/modules/gis/routes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Router } from "express";
import { locationSearch } from "./service";
import { hasArticle4Schema } from "./service/article4Schema";
import { classifiedRoadsSearch } from "./service/classifiedRoads";

const router = Router();

router.get("/gis/:localAuthority", locationSearch);
router.get("/gis/:localAuthority/article4-schema", hasArticle4Schema);
router.get("/roads", classifiedRoadsSearch);

export default router;
43 changes: 43 additions & 0 deletions api.planx.uk/modules/gis/service/article4Schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { NextFunction, Request, Response } from "express";

import { localAuthorityMetadata } from "./digitalLand";

/**
* @swagger
* /gis/{localAuthority}/article4-schema:
* get:
* summary: Returns whether Article 4 schema variables are configured for this local authority
* description: Returns whether Article 4 schema variables are configured for this local authority. A positive "status" from this endpoint is a proxy for marking this PlanX onboarding step "complete".
* tags:
* - gis
* parameters:
* - $ref: '#/components/parameters/localAuthority'
* description: Name of the Local Authority, usually the same as Planx `team`. Required until Planning Data is available for any council o article 4 variables are generalised based on permitted development rights removed rather than council
*/
export async function hasArticle4Schema(
req: Request,
res: Response,
next: NextFunction,
) {
try {
if (!req.params.localAuthority) {
return next({
status: 401,
message: "Missing param local authority",
});
}

const status = Object.keys(localAuthorityMetadata).includes(
req.params.localAuthority,
);
res.status(200).send({
message: `${status ? "Found" : "Did not find"} Article 4 schema for ${req.params.localAuthority}`,
status: status,
});
} catch (error) {
next({
status: 500,
message: `Error getting Article 4 schema for ${req.params.localAuthority}: ${error}`,
});
}
}
2 changes: 1 addition & 1 deletion api.planx.uk/modules/gis/service/digitalLand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface LocalAuthorityMetadata {
}

/** When a team publishes their granular Article 4 data, add them to this list. Key must match team slug */
const localAuthorityMetadata: Record<string, LocalAuthorityMetadata> = {
export const localAuthorityMetadata: Record<string, LocalAuthorityMetadata> = {
"barking-and-dagenham": require("./local_authorities/metadata/barkingAndDagenham"),
barnet: require("./local_authorities/metadata/barnet"),
birmingham: require("./local_authorities/metadata/birmingham"),
Expand Down
12 changes: 10 additions & 2 deletions editor.planx.uk/src/pages/PlatformAdminPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Typography from "@mui/material/Typography";
import { SummaryListTable } from "@planx/components/shared/Preview/SummaryList";
import { useStore } from "pages/FlowEditor/lib/store";
import React from "react";
import useSWR from "swr";
import { AdminPanelData } from "types";
import Caret from "ui/icons/Caret";

Expand Down Expand Up @@ -54,6 +55,13 @@ const NotConfigured: React.FC = () => <Close color="error" fontSize="small" />;
const Configured: React.FC = () => <Done color="success" fontSize="small" />;

const TeamData: React.FC<TeamData> = ({ data }) => {
const a4Endpoint = `${process.env.REACT_APP_API_URL}/gis/${data.slug}/article4-schema`;
const fetcher = (url: string) => fetch(url).then((r) => r.json());
const { data: a4Check, isValidating } = useSWR(
() => data.slug ? a4Endpoint : null,
fetcher,
);

return (
<StyledTeamAccordion primaryColour={data.primaryColour} elevation={0}>
<AccordionSummary
Expand Down Expand Up @@ -114,8 +122,8 @@ const TeamData: React.FC<TeamData> = ({ data }) => {
</Box>
</>
<>
<Box component="dt">{"Article 4s"}</Box>
<Box component="dd">{"?"}</Box>
<Box component="dt">{"Article 4s (API)"}</Box>
<Box component="dd">{!isValidating && a4Check?.status ? <Configured /> : <NotConfigured />}</Box>
</>
<>
<Box component="dt">{"Reference code"}</Box>
Expand Down

0 comments on commit 58cb7ce

Please sign in to comment.