From 520c0a8280efddb470e0bab0e65baa4bde93d386 Mon Sep 17 00:00:00 2001 From: Kevin Puig Date: Wed, 22 Oct 2025 15:20:13 -0400 Subject: [PATCH] Create decent server skeleton --- alarm-server/index.ts | 50 ++++++++++++++++++++++++++----- alarm-server/prisma/schema.prisma | 7 +++-- alarm-snoozer/src/app/app.hpp | 4 +++ alarm-snoozer/src/main.cpp | 2 ++ 4 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 alarm-snoozer/src/app/app.hpp diff --git a/alarm-server/index.ts b/alarm-server/index.ts index 8d987ce..d5e262d 100644 --- a/alarm-server/index.ts +++ b/alarm-server/index.ts @@ -1,10 +1,19 @@ import { Server } from "socket.io"; +import { PrismaClient } from "./generated/prisma"; +/** + * Server interfaces + */ interface ServerToClientEvents { } interface ClientToServerEvents { - createAlarm: (cmd:CreateAlarmCommand) => void; + create: (cmd:CreateAlarmCommand) => void; + ls: (cmd:ListCommand) => void; + mkgrp: (cmd:MakeGroupCommand) => void; + rm: (cmd:RemoveCommand) => void; + snooze: (cmd:SnoozeCommand) => void; + shutoff: (cmd:ShutoffCommand) => void; } interface InterServerEvents { @@ -14,8 +23,12 @@ interface SocketData { token: string; } +/** + * Command interfaces + */ interface CreateAlarmCommand { - time:string + time:string // HH:MM or HH:MM:SS + groupId:number } interface ListCommand { @@ -28,7 +41,7 @@ interface MakeGroupCommand { interface RemoveCommand { groupId:number - alarmId:number + alarmId?:number } interface SnoozeCommand { @@ -39,24 +52,47 @@ interface ShutoffCommand { groupId:number } +// Start program const key = process.env.SECRET_KEY; if (!key) { throw new Error("Secret key not defined"); } const io = new Server< - ServerToClientEvents, ClientToServerEvents, + ServerToClientEvents, InterServerEvents, SocketData >(3300); -io.on("connection", (socket) => { +const prisma = new PrismaClient(); + +io.on("connection", async (socket) => { if (socket.data.token !== key) { + socket.disconnect(); return; } - socket.on("createAlarm", () => { + socket.on("create", async (cmd:CreateAlarmCommand) => { }); -}); \ No newline at end of file + socket.on("ls", async (cmd:ListCommand) => { + + }); + socket.on("mkgrp", async (cmd:MakeGroupCommand) => { + + }); + socket.on("rm", async (cmd:RemoveCommand) => { + + }); + socket.on("snooze", async (cmd:SnoozeCommand) => { + + }); + socket.on("shutoff", async (cmd:ShutoffCommand) => { + + }); +}); + +setInterval(async () => { + // Process alarms constantly to announce alarm state to "groupstate-alert" on a change or when the client reports a differing state +}, 1); \ No newline at end of file diff --git a/alarm-server/prisma/schema.prisma b/alarm-server/prisma/schema.prisma index 88bc855..2b7160b 100644 --- a/alarm-server/prisma/schema.prisma +++ b/alarm-server/prisma/schema.prisma @@ -39,11 +39,12 @@ enum AlarmGroupState { } model Alarm { - id Int @id @default(autoincrement()) - time String - nextRing DateTime + secondsSinceMidnight Int + nextRing DateTime // AlarmGroup FK AlarmGroupId Int AlarmGroup AlarmGroup @relation(fields: [AlarmGroupId], references: [id]) + + @@id([secondsSinceMidnight, AlarmGroupId]) } diff --git a/alarm-snoozer/src/app/app.hpp b/alarm-snoozer/src/app/app.hpp new file mode 100644 index 0000000..74cee19 --- /dev/null +++ b/alarm-snoozer/src/app/app.hpp @@ -0,0 +1,4 @@ +int admin(int argc, char** argv) +{ + +} \ No newline at end of file diff --git a/alarm-snoozer/src/main.cpp b/alarm-snoozer/src/main.cpp index bc8f460..4adc9a4 100644 --- a/alarm-snoozer/src/main.cpp +++ b/alarm-snoozer/src/main.cpp @@ -1,6 +1,8 @@ #include +#include "app/app.hpp" int main() { + std::cout << "Hello, World!" << std::endl; return 0; }