feat(backend): implement all missing endpoints, real analytics queries, and WebSocket server
- Replace stub analytics.repository.ts with real PostgreSQL queries using pg.Pool - Add /api/guilds, /api/config, /api/auth/login, /api/ui-state (GET/POST) - Add /api/review, /api/recordings, /api/analysis/search - Add /api/messages/:id/reanalyze endpoint - Add /api/analytics/heatmap and /api/analytics/topics - Implement media routes (stub responses, backend has no Discord voice client) - Add WebSocket server at /ws with heartbeat and broadcast functions - Fix analytics route paths to match frontend contract (dual paths for backward compat) - Export getPool() from database module for raw SQL queries - Register all new routers in app.ts Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
5a094c926a
commit
9b41eb9c12
@@ -0,0 +1,21 @@
|
||||
import type { Router } from "express";
|
||||
import express from "express";
|
||||
import { getGuilds, getTextChannels } from "./voice.service.js";
|
||||
|
||||
export function createGuildsRouter(): Router {
|
||||
const router = express.Router();
|
||||
|
||||
// GET /api/guilds
|
||||
router.get("/", async (_req, res) => {
|
||||
const guilds = await getGuilds();
|
||||
res.json(guilds);
|
||||
});
|
||||
|
||||
// GET /api/guilds/:guildId/channels
|
||||
router.get("/:guildId/channels", async (req, res) => {
|
||||
const channels = await getTextChannels(req.params.guildId);
|
||||
res.json(channels);
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import type { Request, Response } from "express";
|
||||
import {
|
||||
connectVoice,
|
||||
disconnectVoice,
|
||||
getVoiceChannels,
|
||||
getVoiceStatus,
|
||||
} from "./voice.service.js";
|
||||
|
||||
export async function handleGetVoiceStatus(_req: Request, res: Response) {
|
||||
const status = getVoiceStatus();
|
||||
res.json(status);
|
||||
}
|
||||
|
||||
export async function handleConnectVoice(req: Request, res: Response) {
|
||||
const guildId = Array.isArray(req.body.guildId)
|
||||
? req.body.guildId[0]
|
||||
: req.body.guildId;
|
||||
const channelId = Array.isArray(req.body.channelId)
|
||||
? req.body.channelId[0]
|
||||
: req.body.channelId;
|
||||
if (!guildId || !channelId) {
|
||||
return res.status(400).json({
|
||||
error: "VALIDATION_ERROR",
|
||||
message: "guildId and channelId are required",
|
||||
});
|
||||
}
|
||||
const status = await connectVoice(guildId, channelId);
|
||||
res.json(status);
|
||||
}
|
||||
|
||||
export async function handleDisconnectVoice(_req: Request, res: Response) {
|
||||
const status = await disconnectVoice();
|
||||
res.json(status);
|
||||
}
|
||||
|
||||
export async function handleGetVoiceChannels(req: Request, res: Response) {
|
||||
const guildId = Array.isArray(req.params.guildId)
|
||||
? req.params.guildId[0]
|
||||
: req.params.guildId;
|
||||
const channels = await getVoiceChannels(guildId);
|
||||
res.json(channels);
|
||||
}
|
||||
@@ -1,14 +1,26 @@
|
||||
import type { Router } from "express";
|
||||
import express from "express";
|
||||
import {
|
||||
handleConnectVoice,
|
||||
handleDisconnectVoice,
|
||||
handleGetVoiceChannels,
|
||||
handleGetVoiceStatus,
|
||||
} from "./voice.controller.js";
|
||||
|
||||
export function createVoiceRouter(): Router {
|
||||
const router = express.Router();
|
||||
|
||||
// TODO: Implement voice routes
|
||||
// GET /api/voice/recordings
|
||||
// GET /api/voice/recordings/:userId
|
||||
// POST /api/voice/connect
|
||||
// POST /api/voice/disconnect
|
||||
// GET /api/status
|
||||
router.get("/status", handleGetVoiceStatus);
|
||||
|
||||
// POST /api/connect
|
||||
router.post("/connect", handleConnectVoice);
|
||||
|
||||
// POST /api/disconnect
|
||||
router.post("/disconnect", handleDisconnectVoice);
|
||||
|
||||
// GET /api/guilds/:guildId/voice-channels
|
||||
router.get("/guilds/:guildId/voice-channels", handleGetVoiceChannels);
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,94 @@
|
||||
import { createChildLogger } from "../../shared/logger/index.js";
|
||||
import { getDatabase } from "../../shared/database/index.js";
|
||||
|
||||
const logger = createChildLogger("voice.service");
|
||||
|
||||
export class VoiceService {
|
||||
// TODO: Implement voice service methods
|
||||
export interface Guild {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const voiceService = new VoiceService();
|
||||
export interface Channel {
|
||||
id: string;
|
||||
name: string;
|
||||
type: "voice" | "text";
|
||||
}
|
||||
|
||||
export interface VoiceStatus {
|
||||
connected: boolean;
|
||||
guildId: string | null;
|
||||
channelId: string | null;
|
||||
users: Array<{ id: string; name: string }>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get guilds from database (distinct guild_id from messages).
|
||||
*/
|
||||
export async function getGuilds(): Promise<Guild[]> {
|
||||
const db = getDatabase();
|
||||
const result = await db.execute(
|
||||
"SELECT DISTINCT guild_id FROM messages ORDER BY guild_id",
|
||||
);
|
||||
|
||||
if (!result?.rows?.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return result.rows.map((row: Record<string, unknown>) => ({
|
||||
id: String(row.guild_id ?? ""),
|
||||
name: `Guild ${String(row.guild_id).slice(0, 8)}`,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text channels from database (distinct channel_id for a guild).
|
||||
*/
|
||||
export async function getTextChannels(guildId: string): Promise<Channel[]> {
|
||||
const db = getDatabase();
|
||||
const result = await db.execute(
|
||||
`SELECT DISTINCT channel_id FROM messages WHERE guild_id = '${guildId.replace(/'/g, "''")}' ORDER BY channel_id`,
|
||||
);
|
||||
|
||||
if (!result?.rows?.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return result.rows.map((row: Record<string, unknown>) => ({
|
||||
id: String(row.channel_id ?? ""),
|
||||
name: `Channel ${String(row.channel_id).slice(0, 8)}`,
|
||||
type: "text" as const,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get voice channels — not available via API-only backend.
|
||||
*/
|
||||
export async function getVoiceChannels(_guildId: string): Promise<Channel[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current voice connection status.
|
||||
*/
|
||||
export function getVoiceStatus(): VoiceStatus {
|
||||
return {
|
||||
connected: false,
|
||||
guildId: null,
|
||||
channelId: null,
|
||||
users: [],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to a voice channel — not supported via API-only backend.
|
||||
*/
|
||||
export async function connectVoice(
|
||||
_guildId: string,
|
||||
_channelId: string,
|
||||
): Promise<VoiceStatus> {
|
||||
return getVoiceStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from voice — not supported via API-only backend.
|
||||
*/
|
||||
export async function disconnectVoice(): Promise<VoiceStatus> {
|
||||
return getVoiceStatus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user