From: sabadev Date: Sun, 21 Mar 2021 04:31:11 +0000 (-0400) Subject: Moved API definition out into ApiTypes.hs X-Git-Url: http://sabadev.xyz:4321/?a=commitdiff_plain;h=7ef81a50afa2eeea6ec5f4dbef5adc7fe98962b2;p=website.git Moved API definition out into ApiTypes.hs --- diff --git a/src/ApiTypes.hs b/src/ApiTypes.hs new file mode 100644 index 0000000..e0a68c6 --- /dev/null +++ b/src/ApiTypes.hs @@ -0,0 +1,17 @@ +module ApiTypes where + +import CssContentType +import Html +import Lucid +import Servant +import Servant.HTML.Lucid (HTML(..)) +import qualified Clay as C + +type Api = Page :<|> Themes +type Page = MainPage :<|> BlogPost +type MainPage = ThemeParam :> Get '[HTML] (Html ()) +type BlogPost = ThemeParam :> Capture "id" BlogId :> Get '[HTML] (Html ()) +type Themes = "style" :> (DarkTheme :<|> LightTheme) +type DarkTheme = "dark" :> QueryParam "red" Integer :> QueryParam "green" Integer :> QueryParam "blue" Integer :> Get '[CSS] C.Css +type LightTheme = "light" :> QueryParam "red" Integer :> QueryParam "green" Integer :> QueryParam "blue" Integer :> Get '[CSS] C.Css +type ThemeParam = QueryParam "theme" Theme diff --git a/src/Server.hs b/src/Server.hs index f1b7fff..c3d0fbe 100644 --- a/src/Server.hs +++ b/src/Server.hs @@ -1,14 +1,13 @@ module Server where +import ApiTypes import Control.Monad ((<=<)) import Control.Monad.IO.Class (liftIO) -import CssContentType import Data.Maybe (fromMaybe) import Html import Lucid import RenderBlog (renderBlog) import Servant -import Servant.HTML.Lucid (HTML(..)) import StyleSheet import qualified Clay as C import qualified Data.Text as T @@ -20,15 +19,6 @@ app = serve apiProxy api apiProxy :: Proxy Api apiProxy = Proxy -type Api = Page :<|> Themes -type Page = MainPage :<|> BlogPost -type MainPage = ThemeParam :> Get '[HTML] (Html ()) -type BlogPost = ThemeParam :> Capture "id" BlogId :> Get '[HTML] (Html ()) -type Themes = "style" :> (DarkTheme :<|> LightTheme) -type DarkTheme = "dark" :> QueryParam "red" Integer :> QueryParam "green" Integer :> QueryParam "blue" Integer :> Get '[CSS] C.Css -type LightTheme = "light" :> QueryParam "red" Integer :> QueryParam "green" Integer :> QueryParam "blue" Integer :> Get '[CSS] C.Css -type ThemeParam = QueryParam "theme" Theme - api :: Server Api api = page :<|> themes