Skip to content
Permalink
Browse files

Implement most of usersShow

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 10aa133a7b45098f04d318dfce8a31b9dc811b86
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/Main.hs
@@ -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)
@@ -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

0 comments on commit 10aa133

Please sign in to comment.
You can’t perform that action at this time.