import { Application, Router } from '@oak/oak';
import { getRestaurants } from './endpoints/restaurants.ts';
import { getDeals } from './endpoints/deals.ts';
const router = new Router();
router.get('/restaurants', async (ctx) => {
const restaurants = await getRestaurants();
ctx.response.body = restaurants;
});
router.get('/deals', async (ctx) => {
const day = ctx.request.url.searchParams.get('day');
const city = ctx.request.url.searchParams.get('city');
if (!day || !city) {
ctx.response.status = 400;
ctx.response.body = {
error: `Both 'day' and 'city' parameters are required`,
};
return;
}
const deals = await getDeals(day, city);
ctx.response.body = deals;
});
const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());
await app.listen({});