feat(01-02): add Hono API routes with validation, image upload, and integration tests

- Item routes: GET, POST, PUT, DELETE with Zod validation and image cleanup
- Category routes: GET, POST, PUT, DELETE with Uncategorized protection
- Totals route: per-category and global aggregates
- Image upload: multipart file handling with type/size validation
- Routes use DI via Hono context variables for testability
- Integration tests: 10 tests covering all endpoints and edge cases
- All 30 tests passing

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-14 22:40:49 +01:00
parent 22757a8aef
commit 029adf4dca
7 changed files with 412 additions and 0 deletions

View File

@@ -1,6 +1,10 @@
import { Hono } from "hono";
import { serveStatic } from "hono/bun";
import { seedDefaults } from "../db/seed.ts";
import { itemRoutes } from "./routes/items.ts";
import { categoryRoutes } from "./routes/categories.ts";
import { totalRoutes } from "./routes/totals.ts";
import { imageRoutes } from "./routes/images.ts";
// Seed default data on startup
seedDefaults();
@@ -12,6 +16,12 @@ app.get("/api/health", (c) => {
return c.json({ status: "ok" });
});
// API routes
app.route("/api/items", itemRoutes);
app.route("/api/categories", categoryRoutes);
app.route("/api/totals", totalRoutes);
app.route("/api/images", imageRoutes);
// Serve uploaded images
app.use("/uploads/*", serveStatic({ root: "./" }));
@@ -22,3 +32,4 @@ if (process.env.NODE_ENV === "production") {
}
export default { port: 3000, fetch: app.fetch };
export { app };