import logIP from "@/app/www/media/logIP";
import { getEssays } from "@/app/www/logic/forum";

export const GET = logIP(async (req, { params: { forumID } }) => {
  const page = req.nextUrl.searchParams.get("page");
  const language = req.nextUrl.searchParams.get("language");

  if (!page || !language) {
    return Response.json(undefined, { status: 400 });
  }

  const essays = await getEssays(forumID, language, Number(page));
  if (essays) {
    return Response.json(essays);
  } else {
    return Response.json(undefined, { status: 404 });
  }
});
