Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions agents/eng-bot/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import express, { Request, Response, NextFunction } from "express";
import productsRouter from "./routes/products";

export function createApp(): express.Application {
const app = express();

app.use(express.json());

app.get("/health", (_req: Request, res: Response) => {
res.json({ status: "ok" });
});

app.use("/products", productsRouter);

app.use((_req: Request, res: Response, _next: NextFunction) => {
res.status(404).json({ error: "Not found" });
});

return app;
}
44 changes: 44 additions & 0 deletions agents/eng-bot/src/routes/products.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Router, Request, Response } from "express";

const router = Router();

interface Product {
id: number;
name: string;
price_cents: number;
description: string;
stock_qty: number;
}

const STUB_PRODUCTS: Product[] = [
{
id: 1,
name: "Classic T-Shirt",
price_cents: 2999,
description: "A comfortable everyday t-shirt.",
stock_qty: 100,
},
{
id: 2,
name: "Canvas Tote Bag",
price_cents: 1499,
description: "Durable canvas bag for daily use.",
stock_qty: 50,
},
];

router.get("/", (_req: Request, res: Response) => {
res.json(STUB_PRODUCTS);
});

router.get("/:id", (req: Request, res: Response) => {
const id = parseInt(req.params.id, 10);
const product = STUB_PRODUCTS.find((p) => p.id === id);
if (!product) {
res.status(404).json({ error: "not found" });
return;
}
res.json(product);
});

export default router;
8 changes: 8 additions & 0 deletions agents/eng-bot/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createApp } from "./app";

const port = parseInt(process.env.PORT ?? "3000", 10);
const app = createApp();

app.listen(port, () => {
console.log(`Server listening on http://localhost:${port}`);
});