import Router from "koa-router";
import { validateMillis } from "src/mws/millis";
import { getHit, postHit } from "src/systems/hit";

const router = new Router();

router.get("/", async (ctx) => {
  ctx.body = await getHit();
  ctx.status = 200;
});

router.post("/", validateMillis, async (ctx) => {
  const {
    request: { ip },
  } = ctx;

  await postHit(ip);
  ctx.status = 201;
});

export default router;
