Move shift-time into top-level //zoo

I'm still unsure whether or not this is a good idea, but experimenting is a good
way to find out!
This commit is contained in:
William Carroll 2020-08-13 22:22:39 +01:00
parent 3fdfa14355
commit f895cb417a
5 changed files with 30 additions and 23 deletions

View file

@ -2,3 +2,4 @@
:set -Wall :set -Wall
:set -XOverloadedStrings :set -XOverloadedStrings
:set -XRecordWildCards :set -XRecordWildCards
:set -XTypeApplications

View file

@ -1,16 +1,35 @@
{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
module Main where module Main where
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import RIO import RIO hiding (Handler)
import RIO.Text import RIO.Text
import RIO.Time import RIO.Time
import Data.String.Conversions (cs) import Servant
import Data.Time.Clock.POSIX import Data.Time.Clock.POSIX
import Prelude (putStrLn, putStr, print, getLine, read) import Prelude (read)
import Text.ParserCombinators.ReadP import Text.ParserCombinators.ReadP
import qualified Network.Wai.Handler.Warp as Warp
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
type Api = "run"
:> QueryParam' '[Required] "offset" Text
:> Get '[JSON] UTCTime
server :: Server Api
server = compute
where
compute :: Text -> Handler UTCTime
compute x = do
case parseInput x of
Nothing -> throwError err401
Just req -> do
res <- liftIO $ shiftTime req
pure res
data ShiftTimeRequest = ShiftTimeRequest data ShiftTimeRequest = ShiftTimeRequest
{ shiftSeconds :: Int { shiftSeconds :: Int
, shiftMinutes :: Int , shiftMinutes :: Int
@ -130,11 +149,4 @@ parseInput x =
_ -> Nothing _ -> Nothing
main :: IO () main :: IO ()
main = do main = Warp.run 8000 $ serve (Proxy @ Api) server
putStr "Enter an offset (e.g. -10d-30s): "
x <- getLine
case parseInput (cs x) of
Nothing -> putStrLn "Try again!" >> main
Just req -> do
t <- shiftTime req
putStrLn $ show t

View file

@ -1,10 +1,10 @@
let { briefcase, ... }:
briefcase = import /home/wpcarro/briefcase {};
in briefcase.buildHaskell.program { briefcase.buildHaskell.program {
name = "shift-time"; name = "zoo";
srcs = builtins.path { srcs = builtins.path {
path = ./.; path = ./.;
name = "shift-time-src"; name = "zoo-src";
}; };
ghcExtensions = [ ghcExtensions = [
"OverloadedStrings" "OverloadedStrings"
@ -15,14 +15,7 @@ in briefcase.buildHaskell.program {
deps = hpkgs: with hpkgs; [ deps = hpkgs: with hpkgs; [
servant-server servant-server
aeson aeson
wai-cors
warp warp
jwt
unordered-containers
base64
http-conduit
rio rio
envy
req
]; ];
} }

View file

@ -5,5 +5,6 @@ in briefcase.buildHaskell.shell {
hspec hspec
rio rio
string-conversions string-conversions
servant-server
]; ];
} }