|
1 | | -import { Hono } from 'hono' |
2 | | -import { redis } from '../services/redisService' |
| 1 | +import { Hono } from "hono"; |
| 2 | +import { RedisService } from "../services/redisService.ts"; |
3 | 3 |
|
4 | | -export const messageRoutes = new Hono() |
| 4 | +export const messageRoutes = new Hono(); |
5 | 5 |
|
6 | | -messageRoutes.post('/', async (c) => { |
7 | | - try { |
8 | | - const body = await c.req.json().catch(() => null) |
| 6 | +messageRoutes.post("/", async (c) => { |
| 7 | + try { |
| 8 | + const body = await c.req.json().catch(() => null); |
9 | 9 |
|
10 | | - if (!body?.text || typeof body.text !== 'string') { |
11 | | - console.warn('[HTTP] Invalid payload received') |
12 | | - return c.json({ error: 'Invalid body: expected { text: string }' }, 400) |
13 | | - } |
| 10 | + if (!body?.text || typeof body.text !== "string") { |
| 11 | + console.warn("[HTTP] Invalid payload received"); |
| 12 | + return c.json({ error: "Invalid body: expected { text: string }" }, 400); |
| 13 | + } |
14 | 14 |
|
15 | | - await redis.lpush('messages', body.text) |
| 15 | + await RedisService.lpush("messages", body.text); |
16 | 16 |
|
17 | | - console.log('[HTTP] Message stored successfully') |
18 | | - return c.json({ ok: true }) |
19 | | - } catch (err) { |
20 | | - console.error('[HTTP] Error in POST /messages:', err) |
21 | | - return c.json({ error: 'Internal server error' }, 500) |
22 | | - } |
23 | | -}) |
| 17 | + console.log("[HTTP] Message stored successfully"); |
| 18 | + return c.json({ ok: true }); |
| 19 | + } catch (err) { |
| 20 | + console.error("[HTTP] Error in POST /messages:", err); |
| 21 | + return c.json({ error: "Internal server error" }, 500); |
| 22 | + } |
| 23 | +}); |
24 | 24 |
|
25 | | -messageRoutes.get('/', async (c) => { |
26 | | - try { |
27 | | - const messages = await redis.lrange('messages', 0, 9) |
28 | | - return c.json({ count: messages.length, messages }) |
29 | | - } catch (err) { |
30 | | - console.error('[HTTP] Error in GET /messages:', err) |
31 | | - return c.json({ error: 'Internal server error' }, 500) |
32 | | - } |
33 | | -}) |
| 25 | +messageRoutes.get("/", async (c) => { |
| 26 | + try { |
| 27 | + const messages = await RedisService.lrange("messages", 0, 9); |
| 28 | + return c.json({ count: messages.length, messages }); |
| 29 | + } catch (err) { |
| 30 | + console.error("[HTTP] Error in GET /messages:", err); |
| 31 | + return c.json({ error: "Internal server error" }, 500); |
| 32 | + } |
| 33 | +}); |
0 commit comments