43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import {NextRequest, NextResponse} from "next/server";
|
|
import {RouteContext} from "@/types/common";
|
|
import {createContactApi} from "@/lib/http-server";
|
|
import {errorToResponse} from "@kri/common/http";
|
|
import type {ListReserve} from "@/types/list";
|
|
|
|
export const GET = async (req: NextRequest, context: RouteContext) => {
|
|
try {
|
|
const { slug = [] } = await context.params;
|
|
const [action] = slug;
|
|
const contactApi = await createContactApi();
|
|
|
|
if (action === "sid" && slug.length === 3) {
|
|
const result = await contactApi.get<ListReserve[]>(`/reserve/${slug[1]}/sid/${slug[2]}`);
|
|
return NextResponse.json(result, { status: 200 });
|
|
}
|
|
|
|
if (action === "user" && slug.length === 3) {
|
|
const result = await contactApi.get<ListReserve[]>(`/reserve/${slug[1]}/user/${slug[2]}`);
|
|
return NextResponse.json(result, { status: 200 });
|
|
}
|
|
|
|
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
|
} catch (error: unknown) {
|
|
return errorToResponse(error);
|
|
}
|
|
};
|
|
|
|
export const PUT = async (req: NextRequest, context: RouteContext) => {
|
|
try {
|
|
const body = await req.json().catch(() => null);
|
|
if (!body) {
|
|
return NextResponse.json({ message: "요청 바디가 없습니다." }, { status: 400 });
|
|
}
|
|
|
|
const contactApi = await createContactApi();
|
|
const result = await contactApi.put<ListReserve>(`/reserve`, body);
|
|
return NextResponse.json(result, { status: 200 });
|
|
} catch (error: unknown) {
|
|
return errorToResponse(error);
|
|
}
|
|
};
|