Skip to content
Merged
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
2 changes: 2 additions & 0 deletions backend/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const eventHistoryMocks = vi.hoisted(() => ({
getGlobalEvents: vi.fn(),
countAllEvents: vi.fn(),
recordEvent: vi.fn(),
getStreamEventSummary: vi.fn(),
}));

vi.mock("./services/streamStore", () => streamStoreMocks);
Expand Down Expand Up @@ -214,6 +215,7 @@ beforeEach(() => {
eventHistoryMocks.getGlobalEvents.mockReset();
eventHistoryMocks.countAllEvents.mockReset();
eventHistoryMocks.getStreamHistory.mockReset();
eventHistoryMocks.getStreamEventSummary.mockReset();
});

describe("GET /api/streams", () => {
Expand Down
16 changes: 16 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,22 @@ app.get("/api/streams/:id/history", (req: Request, res: Response) => {
res.json({ data, total, limit, offset });
});

app.get("/api/streams/:id/history/summary", (req: Request, res: Response) => {
const parsedId = parseStreamId(req.params.id);
if (!parsedId.ok) {
sendValidationError(req, res, parsedId.issues);
return;
}

const stream = getStream(parsedId.value);
if (!stream) {
sendApiError(req, res, 404, "Stream not found.", { code: "NOT_FOUND" });
return;
}

res.json({ data: getStreamEventSummary(parsedId.value) });
});

app.get("/api/streams/:id/snapshot", (req: Request, res: Response) => {
const parsedId = parseStreamId(req.params.id);
if (!parsedId.ok) {
Expand Down
47 changes: 47 additions & 0 deletions backend/src/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,53 @@ export const swaggerDocument = {
},
},
},
"/api/streams/{id}/history/summary": {
get: {
summary: "Get stream event count summary",
description: "Returns aggregated event counts per type for a stream. Useful for dashboard badges. Uses a single GROUP BY query; missing event types return 0.",
parameters: [
{
name: "id",
in: "path",
required: true,
description: "The unique ID of the stream.",
schema: { type: "string" },
},
],
responses: {
"200": {
description: "Event count summary.",
content: {
"application/json": {
schema: {
type: "object",
properties: {
data: {
type: "object",
required: ["created", "claimed", "canceled", "start_time_updated"],
properties: {
created: { type: "integer", example: 1 },
claimed: { type: "integer", example: 3 },
canceled: { type: "integer", example: 0 },
start_time_updated: { type: "integer", example: 1 },
},
},
},
},
},
},
},
"404": {
description: "Stream not found.",
content: {
"application/json": {
schema: { $ref: "#/components/schemas/Error" },
},
},
},
},
},
},
"/api/streams/{id}/snapshot": {
get: {
summary: "Get Stream Snapshot",
Expand Down