🎉 initial commit
Some checks failed
CI / Lint (push) Failing after 39s
CI / Build (push) Has been skipped
CI / Test (push) Has been skipped
CI / Helm Lint (push) Successful in 13s

This commit is contained in:
Christian van Dijk
2026-02-23 09:47:16 +01:00
commit 94b4f31102
53 changed files with 3220 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
local db = require("db")
local log = require("log")
local DeviceHandler = {}
function DeviceHandler.handle(event)
local conn, err = db.get_connection()
if not conn then
error("Database connection failed: " .. tostring(err))
end
local ok, handler_err = pcall(function()
conn:query([[
CREATE TABLE IF NOT EXISTS device_events (
id SERIAL PRIMARY KEY,
device_id INTEGER,
device_name VARCHAR(255),
event_type VARCHAR(100),
processed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
]])
conn:query(
"INSERT INTO device_events (device_id, device_name, event_type) VALUES ($1, $2, $3)",
tonumber(event.device_id) or 0,
event.device_name or "",
event.event_type
)
end)
conn:disconnect()
if not ok then
error(handler_err)
end
log.info("Device event logged", {
component = "device_handler",
device_name = event.device_name,
request_id = event.request_id,
})
end
return DeviceHandler

View File

@@ -0,0 +1,45 @@
local db = require("db")
local log = require("log")
local RatingHandler = {}
function RatingHandler.handle(event)
local conn, err = db.get_connection()
if not conn then
error("Database connection failed: " .. tostring(err))
end
local ok, handler_err = pcall(function()
conn:query([[
CREATE TABLE IF NOT EXISTS rating_events (
id SERIAL PRIMARY KEY,
device_id INTEGER,
user_id VARCHAR(255),
score INTEGER,
processed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
]])
conn:query(
"INSERT INTO rating_events (device_id, user_id, score) VALUES ($1, $2, $3)",
tonumber(event.device_id) or 0,
event.user_id or "",
tonumber(event.score) or 0
)
end)
conn:disconnect()
if not ok then
error(handler_err)
end
log.info("Rating event logged", {
component = "rating_handler",
device_id = event.device_id,
score = event.score,
request_id = event.request_id,
})
end
return RatingHandler

View File

@@ -0,0 +1,42 @@
local db = require("db")
local log = require("log")
local ReviewHandler = {}
function ReviewHandler.handle(event)
local conn, err = db.get_connection()
if not conn then
error("Database connection failed: " .. tostring(err))
end
local ok, handler_err = pcall(function()
conn:query([[
CREATE TABLE IF NOT EXISTS review_events (
id SERIAL PRIMARY KEY,
device_id INTEGER,
user_id VARCHAR(255),
processed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
]])
conn:query(
"INSERT INTO review_events (device_id, user_id) VALUES ($1, $2)",
tonumber(event.device_id) or 0,
event.user_id or ""
)
end)
conn:disconnect()
if not ok then
error(handler_err)
end
log.info("Review event logged", {
component = "review_handler",
device_id = event.device_id,
request_id = event.request_id,
})
end
return ReviewHandler