{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
module GitLab.API.Users where
import Control.Monad.IO.Class
import Data.List
import Data.Maybe
import Data.Text (Text)
import GitLab.Types
import GitLab.WebRequests.GitLabWebCalls
allUsers :: (MonadIO m) => GitLab m [User]
allUsers = do
let path = "/users"
gitlab path
searchUser :: (MonadIO m)
=> Text
-> GitLab m (Maybe User)
searchUser username = do
let path = "/users"
attrs = "&username=" <> username
res <- gitlabWithAttrs path attrs
if null res
then return Nothing
else return (Just (head res))
orderedUsers :: (MonadIO m)
=> [Text]
-> GitLab m [User]
orderedUsers usernames = do
users <- catMaybes <$> mapM searchUser usernames
return (orderUsersByName users)
where
orderUsersByName :: [User] -> [User]
orderUsersByName =
sortBy (\u1 u2 -> compare (user_name u1) (user_name u2))