Skip to content

Commit

Permalink
Implement most of usersShow
Browse files Browse the repository at this point in the history
What to do when we don't _find_ a user for the username param?
  • Loading branch information
bradparker committed Oct 2, 2019
1 parent 25cb688 commit 10aa133
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
module Main where

import Data.Aeson (ToJSON)
import Data.Foldable (find)
import Data.Proxy (Proxy(Proxy))
import Data.Time (Day, fromGregorian)
import GHC.Generics (Generic)
Expand Down Expand Up @@ -65,8 +66,14 @@ users =
usersIndex :: Handler [User]
usersIndex = pure users

matchesUsername :: String -> User -> Bool
matchesUsername uname = (uname ==) . username

usersShow :: String -> Handler User
usersShow _uname = _
usersShow uname =
case find (matchesUsername uname) users of
Nothing -> _
Just user -> pure user

usersServer :: Server UsersAPI
usersServer = usersIndex :<|> usersShow
Expand Down

0 comments on commit 10aa133

Please sign in to comment.