From a8036ceb91c1e1f5ea74f8cf23666e892f9cd051 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Tue, 23 Jan 2024 18:07:19 -0500 Subject: Add get song notes endpoint --- fig-frontend/src/Fig/Frontend.hs | 5 +++++ fig-frontend/src/Fig/Frontend/DB.hs | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'fig-frontend/src') 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 -- cgit v1.2.3