mukaddamzaid's picture
init commit
5012205
import { NextResponse } from "next/server";
import { getChatById, deleteChat } from "@/lib/chat-store";
interface Params {
params: {
id: string;
};
}
export async function GET(request: Request, { params }: Params) {
try {
const userId = request.headers.get('x-user-id');
if (!userId) {
return NextResponse.json({ error: "User ID is required" }, { status: 400 });
}
const { id } = await params;
const chat = await getChatById(id, userId);
if (!chat) {
return NextResponse.json(
{ error: "Chat not found" },
{ status: 404 }
);
}
return NextResponse.json(chat);
} catch (error) {
console.error("Error fetching chat:", error);
return NextResponse.json(
{ error: "Failed to fetch chat" },
{ status: 500 }
);
}
}
export async function DELETE(request: Request, { params }: Params) {
try {
const userId = request.headers.get('x-user-id');
if (!userId) {
return NextResponse.json({ error: "User ID is required" }, { status: 400 });
}
const { id } = await params;
await deleteChat(id, userId);
return NextResponse.json({ success: true });
} catch (error) {
console.error("Error deleting chat:", error);
return NextResponse.json(
{ error: "Failed to delete chat" },
{ status: 500 }
);
}
}