import multer from "multer";
import { Router } from "express";

import { journalsController } from "../controllers/journalsController.js";
import { asyncHandler } from "../utils/asyncHandler.js";

const router = Router();
const upload = multer({
  storage: multer.memoryStorage(),
  limits: {
    fileSize: 8 * 1024 * 1024,
  },
});

router.get("/", asyncHandler(journalsController.list));
router.get("/template", asyncHandler(journalsController.downloadTemplate));
router.post(
  "/import",
  upload.single("file"),
  asyncHandler(journalsController.importItems),
);
router.post("/", asyncHandler(journalsController.create));
router.put("/:id", asyncHandler(journalsController.update));
router.delete("/:id", asyncHandler(journalsController.remove));

export default router;
