@@ -6,7 +6,7 @@
6module Server.API (
6module Server.API (
8 serverProxy,
8 serverProxy,
9− serverAPI
9+ mkServerAPI
12import Data.Proxy
12import Data.Proxy
@@ -26,14 +26,16 @@ import Server.App
26import Control.Monad.Error
26import Control.Monad.Error
27import Server.API.Draft
27import Server.API.Draft
28import Server.API.Posts
28import Server.API.Posts
30maybeNotFound :: App (Maybe a) -> App a
31maybeNotFound :: App (Maybe a) -> App a
31maybeNotFound = (>>= (\t -> case t of
32maybeNotFound = (>>= (\t -> case t of
32 Just y -> return y
33 Just y -> return y
33 Nothing -> throwError err404))
34 Nothing -> throwError err404))
35−type API = "authenticate" :> AuthenticationHandler
38+ "authenticate" :> AuthenticationHandler :<|>
37 AuthProtect "basicAuth" :> (
39 AuthProtect "basicAuth" :> (
38 "users" :> ReqBody '[JSON] [UserId] :> Post '[JSON] [User] :<|>
40 "users" :> ReqBody '[JSON] [UserId] :> Post '[JSON] [User] :<|>
39 "posts" :> PostApi :<|>
41 "posts" :> PostApi :<|>
@@ -43,8 +45,10 @@ type API = "authenticate" :> AuthenticationHandler
43serverProxy :: Proxy API
45serverProxy :: Proxy API
44serverProxy = Proxy
46serverProxy = Proxy
46−serverAPI :: ServerT API App
48+mkServerAPI :: Logger -> ServerT API App
47−serverAPI = authenticate :<|> (\uId ->
51+ authenticate :<|> (\uId ->
48 mapM (runQnotFound . getUser) :<|>
52 mapM (runQnotFound . getUser) :<|>
49 postApi uId :<|>
53 postApi uId :<|>
50 draftApi uId
54 draftApi uId