First version
This commit is contained in:
10
frontend/app/api/meals/route.ts
Normal file
10
frontend/app/api/meals/route.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export async function GET() {
|
||||
const res = await fetch('http://backend:8000/api/meals', {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
return Response.json(data);
|
||||
}
|
42
frontend/app/api/orders/route.ts
Normal file
42
frontend/app/api/orders/route.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const searchParams = request.nextUrl.searchParams
|
||||
const query = searchParams.get('waiter')
|
||||
const res = await fetch(!!query ? `http://backend:8000/api/orders/?waiter=${query}` : 'http://backend:8000/api/orders/', {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
return Response.json(data);
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body = await request.json()
|
||||
const res = await fetch('http://backend:8000/api/orders/', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
return Response.json({ status: res.status });
|
||||
}
|
||||
|
||||
export async function PUT(request: NextRequest) {
|
||||
const searchParams = request.nextUrl.searchParams
|
||||
const query = searchParams.get('id')
|
||||
const body = await request.json()
|
||||
const res = await fetch(`http://backend:8000/api/orders/${query}/`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
return Response.json({ status: res.status });
|
||||
}
|
16
frontend/app/api/tools.ts
Normal file
16
frontend/app/api/tools.ts
Normal file
@ -0,0 +1,16 @@
|
||||
"use client"
|
||||
|
||||
import useSWR from 'swr'
|
||||
|
||||
export const fetcher = (...args) => fetch(...args).then(res => res.json()) // @ts-ignore
|
||||
|
||||
|
||||
export function useUser (id: number) {
|
||||
const { data, error, isLoading } = useSWR(`/api/waiters/${id}`, fetcher)
|
||||
|
||||
return {
|
||||
user: data,
|
||||
isLoading,
|
||||
isError: error
|
||||
}
|
||||
}
|
10
frontend/app/api/waiters/route.ts
Normal file
10
frontend/app/api/waiters/route.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export async function GET() {
|
||||
const res = await fetch('http://backend:8000/api/waiters', {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
return Response.json(data);
|
||||
}
|
Reference in New Issue
Block a user