diff options
author | William Carroll <wpcarro@gmail.com> | 2020-07-24T22·35+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-07-24T22·35+0100 |
commit | 718152ec14242a83fa63c5272c7527dbbd928ee2 (patch) | |
tree | 8a0dfdddfcba4678bb5055ae932e43f3317cc750 /src/App.hs | |
parent | 1d47e94bbe26479ffaaafecd27cdb83d072bfe01 (diff) |
Return a Session
Define the Session type and return it for the POST /user endpoint
Diffstat (limited to 'src/App.hs')
-rw-r--r-- | src/App.hs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/App.hs b/src/App.hs index 1f7754517596..203d1d073ead 100644 --- a/src/App.hs +++ b/src/App.hs @@ -20,7 +20,7 @@ import Network.Wai.Handler.Warp as Warp import Servant import API -import Types +import qualified Types as T -------------------------------------------------------------------------------- server :: ConnectionPool -> Server API @@ -30,17 +30,22 @@ server pool = userAddH newUser = liftIO $ userAdd newUser userGetH name = liftIO $ userGet name - userAdd :: User -> IO (Maybe (Key User)) + userAdd :: T.User -> IO (Maybe T.Session) userAdd newUser = flip runSqlPersistMPool pool $ do - exists <- selectFirst [UserName ==. (userName newUser)] [] + exists <- selectFirst [T.UserName ==. (T.userName newUser)] [] case exists of - Nothing -> Just <$> insert newUser - Just _ -> return Nothing - - userGet :: Text -> IO (Maybe User) + Nothing -> do + insert newUser + pure $ Just (T.Session { T.username = T.Username "wpcarro" + , T.password = T.Password "testing" + , T.role = T.RegularUser + }) + Just _ -> pure Nothing + + userGet :: Text -> IO (Maybe T.User) userGet name = flip runSqlPersistMPool pool $ do - mUser <- selectFirst [UserName ==. name] [] - return $ entityVal <$> mUser + mUser <- selectFirst [T.UserName ==. name] [] + pure $ entityVal <$> mUser app :: ConnectionPool -> Application app pool = serve (Proxy @ API) $ server pool @@ -50,8 +55,8 @@ mkApp sqliteFile = do pool <- runStderrLoggingT $ do createSqlitePool (cs sqliteFile) 5 - runSqlPool (runMigration migrateAll) pool - return $ app pool + runSqlPool (runMigration T.migrateAll) pool + pure $ app pool run :: FilePath -> IO () run sqliteFile = |