diff options
-rw-r--r-- | src/API.hs | 4 | ||||
-rw-r--r-- | src/App.hs | 8 | ||||
-rw-r--r-- | src/Types.hs | 12 |
3 files changed, 12 insertions, 12 deletions
diff --git a/src/API.hs b/src/API.hs index 98ffd6094631..ae85c8f93b26 100644 --- a/src/API.hs +++ b/src/API.hs @@ -15,8 +15,8 @@ import qualified Types as T -------------------------------------------------------------------------------- type API = "user" - :> ReqBody '[JSON] T.User + :> ReqBody '[JSON] T.Account :> Post '[JSON] (Maybe T.Session) :<|> "user" :> Capture "name" Text - :> Get '[JSON] (Maybe T.User) + :> Get '[JSON] (Maybe T.Account) diff --git a/src/App.hs b/src/App.hs index 203d1d073ead..40dc23a303a0 100644 --- a/src/App.hs +++ b/src/App.hs @@ -30,9 +30,9 @@ server pool = userAddH newUser = liftIO $ userAdd newUser userGetH name = liftIO $ userGet name - userAdd :: T.User -> IO (Maybe T.Session) + userAdd :: T.Account -> IO (Maybe T.Session) userAdd newUser = flip runSqlPersistMPool pool $ do - exists <- selectFirst [T.UserName ==. (T.userName newUser)] [] + exists <- selectFirst [T.AccountName ==. (T.accountName newUser)] [] case exists of Nothing -> do insert newUser @@ -42,9 +42,9 @@ server pool = }) Just _ -> pure Nothing - userGet :: Text -> IO (Maybe T.User) + userGet :: Text -> IO (Maybe T.Account) userGet name = flip runSqlPersistMPool pool $ do - mUser <- selectFirst [T.UserName ==. name] [] + mUser <- selectFirst [T.AccountName ==. name] [] pure $ entityVal <$> mUser app :: ConnectionPool -> Application diff --git a/src/Types.hs b/src/Types.hs index c2f0ee19b4d7..813a4b51c305 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -16,20 +16,20 @@ import Database.Persist.TH -------------------------------------------------------------------------------- share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| -User +Account name Text age Int UniqueName name deriving Eq Read Show |] -instance FromJSON User where +instance FromJSON Account where parseJSON = withObject "User" $ \ v -> - User <$> v .: "name" - <*> v .: "age" + Account <$> v .: "name" + <*> v .: "age" -instance ToJSON User where - toJSON (User name age) = +instance ToJSON Account where + toJSON (Account name age) = object [ "name" .= name , "age" .= age ] |