From 4633b364749b99ff2b88f4f9d0d5d77c36cebc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Thu, 8 Feb 2024 13:22:19 +0100 Subject: [PATCH] added API routers for locations --- app/api/all-locations/route.ts | 14 ++++++++++++++ app/api/available-years/route.ts | 9 +++++++++ 2 files changed, 23 insertions(+) create mode 100644 app/api/all-locations/route.ts create mode 100644 app/api/available-years/route.ts diff --git a/app/api/all-locations/route.ts b/app/api/all-locations/route.ts new file mode 100644 index 0000000..21179d9 --- /dev/null +++ b/app/api/all-locations/route.ts @@ -0,0 +1,14 @@ +import { fetchAllLocations } from '@/app/lib/actions/locationActions'; +import type { NextApiRequest } from 'next' +import { NextResponse } from 'next/server'; + +export const GET = async ( + req: NextApiRequest, +) => { + // get year from query params + const url = new URL(req.url as string); + const year = parseInt(url.searchParams.get('year') as string, 10); + const locations = await fetchAllLocations(year); + + return NextResponse.json({ locations }); +} diff --git a/app/api/available-years/route.ts b/app/api/available-years/route.ts new file mode 100644 index 0000000..310dfed --- /dev/null +++ b/app/api/available-years/route.ts @@ -0,0 +1,9 @@ +import { fetchAvailableYears } from '@/app/lib/actions/monthActions'; +import { NextResponse } from 'next/server'; + +export async function GET(request: Request) { + + const availableYears = await fetchAvailableYears(); + + return NextResponse.json({ availableYears }); +} \ No newline at end of file