{-# LANGUAGE OverloadedLabels #-} module WikiMusic.SSR.Servant.SongRoutes ( songsRoute, songRoute, songCreateRoute, ) where import Data.UUID (UUID) import Free.AlaCarte import Optics import Relude import Text.Blaze.Html as Html import WikiMusic.Model.Other import WikiMusic.SSR.Backend.Rest () import WikiMusic.SSR.Free.Backend import WikiMusic.SSR.Free.View import WikiMusic.SSR.Model.Api import WikiMusic.SSR.Model.Env import WikiMusic.SSR.Servant.Utilities import WikiMusic.SSR.View.Html () songsRoute :: (MonadIO m) => Env -> Maybe Text -> Maybe Text -> Maybe Int -> Maybe Int -> m Html songsRoute env cookie givenSortOrder limit offset = do maybeSongs <- liftIO $ exec @Backend ( getSongs env (viewVars ^. #authToken) (maybe (Limit 50) Limit limit) (maybe (Offset 0) Offset offset) sortOrder (Include {value = "artworks,comments,opinions"}) ) eitherView env (viewVars ^. #uiMode) (viewVars ^. #locale) (viewVars ^. #palette) maybeSongs (exec @View . songListPage env (viewVars ^. #uiMode) (viewVars ^. #locale) (viewVars ^. #palette) sortOrder) where viewVars = viewVarsFromCookies cookie sortOrder = maybe (viewVars ^. #songSorting) SortOrder givenSortOrder songRoute :: (MonadIO m) => Env -> Maybe Text -> UUID -> m Html songRoute env cookie identifier = do maybeSongs <- liftIO $ exec @Backend ( getSong env (viewVars ^. #authToken) identifier (Include {value = "artworks,comments,opinions,contents"}) ) eitherView env (viewVars ^. #uiMode) (viewVars ^. #locale) (viewVars ^. #palette) maybeSongs (exec @View . songDetailPage env (viewVars ^. #uiMode) (viewVars ^. #locale) (viewVars ^. #palette) (viewVars ^. #songAsciiSize)) where viewVars = viewVarsFromCookies cookie songCreateRoute :: (MonadIO m) => Env -> Maybe Text -> m Html songCreateRoute env cookie = do liftIO $ exec @View (songCreatePage env (viewVars ^. #uiMode) (viewVars ^. #locale) (viewVars ^. #palette)) where viewVars = viewVarsFromCookies cookie