summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-01-23 18:07:19 -0500
committerLLLL Colonq <llll@colonq>2024-01-23 18:07:19 -0500
commita8036ceb91c1e1f5ea74f8cf23666e892f9cd051 (patch)
tree14d21f3fd10b21979f44684ee1e87c2c9ed6cb79
parent4a7ab38bf416fc5eb6f7602cc97146f9b06ec627 (diff)
Add get song notes endpoint
-rw-r--r--fig-frontend/src/Fig/Frontend.hs5
-rw-r--r--fig-frontend/src/Fig/Frontend/DB.hs7
2 files changed, 11 insertions, 1 deletions
diff --git a/fig-frontend/src/Fig/Frontend.hs b/fig-frontend/src/Fig/Frontend.hs
index 95ab28b..3cab953 100644
--- a/fig-frontend/src/Fig/Frontend.hs
+++ b/fig-frontend/src/Fig/Frontend.hs
@@ -60,4 +60,9 @@ app cfg = do
DB.hvals db "songnames" >>= \case
Nothing -> Tw.send . Tw.status Tw.status404 $ Tw.text "no sounds found :("
Just songs -> Tw.send . Tw.text . pretty . SExprList @Void $ SExprString . decodeUtf8 <$> songs
+ , Tw.get "/api/song/:hash" do
+ hash <- Tw.param "hash"
+ DB.hget db "songnotes" hash >>= \case
+ Nothing -> Tw.send . Tw.status Tw.status404 $ Tw.text "song not found"
+ Just val -> Tw.send . Tw.text $ decodeUtf8 val
]
diff --git a/fig-frontend/src/Fig/Frontend/DB.hs b/fig-frontend/src/Fig/Frontend/DB.hs
index 0ae8058..d0641de 100644
--- a/fig-frontend/src/Fig/Frontend/DB.hs
+++ b/fig-frontend/src/Fig/Frontend/DB.hs
@@ -14,7 +14,12 @@ connect = liftIO $ Redis.checkedConnect Redis.defaultConnectInfo
get :: MonadIO m => Redis.Connection -> ByteString -> m (Maybe ByteString)
get c key = liftIO $ Redis.runRedis c do
v <- Redis.get key
- pure $ join $ hush v
+ pure . join $ hush v
+
+hget :: MonadIO m => Redis.Connection -> ByteString -> ByteString -> m (Maybe ByteString)
+hget c key hkey = liftIO $ Redis.runRedis c do
+ v <- Redis.hget key hkey
+ pure . join $ hush v
hvals :: MonadIO m => Redis.Connection -> ByteString -> m (Maybe [ByteString])
hvals c key = liftIO $ Redis.runRedis c do