import Router from "koa-router";
import { getEssays } from "src/systems/forum";

const router = new Router();

router.get("/:forumID", async (ctx) => {
  const {
    params: { forumID },
    query: { page, viewUnit, language },
  } = ctx;

  const essays = await getEssays(
    forumID,
    language as string,
    Number(page),
    Number(viewUnit),
  );
  if (essays) {
    ctx.body = essays;
    ctx.status = 200;
  } else {
    ctx.status = 404;
  }
});

export default router;
