First version
This commit is contained in:
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 });
|
||||
}
|
Reference in New Issue
Block a user