summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-05-03 14:47:45 -0400
committerLLLL Colonq <llll@colonq>2026-05-03 14:47:45 -0400
commitcaa98b19119cf393cbc6a4aba1b46812c893cdec (patch)
tree47c5e6229d4b4887ae02b8c9c0d8874cb8084265
parent91cf14c9dabecf5e07b310c5d12ad702d570b14f (diff)
Add endpoint to query all users
-rw-r--r--fig-utils/src/Fig/Utils/DB.hs3
-rw-r--r--fig-web/src/Fig/Web/Module/User.hs5
2 files changed, 8 insertions, 0 deletions
diff --git a/fig-utils/src/Fig/Utils/DB.hs b/fig-utils/src/Fig/Utils/DB.hs
index 88a2f37..e8d4955 100644
--- a/fig-utils/src/Fig/Utils/DB.hs
+++ b/fig-utils/src/Fig/Utils/DB.hs
@@ -18,6 +18,9 @@ connect host = liftIO $ DB <$> Redis.checkedConnect Redis.defaultConnectInfo
run :: MonadIO m => DB -> Redis.Redis a -> m a
run (DB c) f = liftIO $ Redis.runRedis c f
+keys :: ByteString -> Redis.Redis [ByteString]
+keys pat = fromMaybe [] . hush <$> Redis.keys pat
+
get :: ByteString -> Redis.Redis (Maybe ByteString)
get key = do
v <- Redis.get key
diff --git a/fig-web/src/Fig/Web/Module/User.hs b/fig-web/src/Fig/Web/Module/User.hs
index 550130c..5d473ff 100644
--- a/fig-web/src/Fig/Web/Module/User.hs
+++ b/fig-web/src/Fig/Web/Module/User.hs
@@ -128,6 +128,11 @@ public a = do
respondText "username not found"
Just val -> respondText val
-- users
+ onGet "/api/users" do
+ let pfx = "user:stats:"
+ users <- DB.run a.db . DB.keys . encodeUtf8 $ pfx <> "*"
+ let strip x = fromMaybe x $ Text.stripPrefix pfx x
+ respondText . Text.unlines $ strip . decodeUtf8 <$> users
onGet "/api/user/info/:uid" do -- get everything bundled together
uid <- pathParam "uid"
info <- getUserInfo a.db uid