Test out Item table

Add to real API
Update air config
Fix bug in MenuItem
This commit is contained in:
Michał Gdula 2024-05-13 12:10:55 +01:00
parent 899867e72d
commit 1fdb6ed2f4
7 changed files with 87 additions and 58 deletions

36
front/src/lib/api.ts Normal file
View file

@ -0,0 +1,36 @@
import { type Item, type JSONResponse } from "./types";
import TestData from "./test-data";
const API_URL = "http://127.0.0.1:8080";
export async function getPopularToday(): Promise<Item[]> {
const response = await fetch(API_URL + "/api/items");
const {data, error}: JSONResponse = await response.json();
if (response.ok) {
if (data?.item) {
return data?.item;
} else {
return Promise.reject(new Error("Failed to fetch popular today"))
}
} else {
return Promise.reject(error)
}
}
export function getMenuItems() {
return [
{
name: "Main Menu",
items: TestData,
},
{
name: "Breakfast",
items: [],
},
{
name: "Seasonal",
items: TestData,
},
];
}