Skip to content

Commit 10aa133

Browse files
committed
Implement most of usersShow
What to do when we don't _find_ a user for the username param?
1 parent 25cb688 commit 10aa133

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Main.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
module Main where
88

99
import Data.Aeson (ToJSON)
10+
import Data.Foldable (find)
1011
import Data.Proxy (Proxy(Proxy))
1112
import Data.Time (Day, fromGregorian)
1213
import GHC.Generics (Generic)
@@ -65,8 +66,14 @@ users =
6566
usersIndex :: Handler [User]
6667
usersIndex = pure users
6768

69+
matchesUsername :: String -> User -> Bool
70+
matchesUsername uname = (uname ==) . username
71+
6872
usersShow :: String -> Handler User
69-
usersShow _uname = _
73+
usersShow uname =
74+
case find (matchesUsername uname) users of
75+
Nothing -> _
76+
Just user -> pure user
7077

7178
usersServer :: Server UsersAPI
7279
usersServer = usersIndex :<|> usersShow

0 commit comments

Comments
 (0)