{-# LANGUAGE OverloadedStrings #-}

module Controller.User
  ( getUsers
  , whoAmI
  ) where

import Web.Scotty

import Control.Monad.IO.Class (liftIO)

import qualified Secure

import Model.Database
import qualified Model.User as U

getUsers :: ActionM ()
getUsers =
  Secure.loggedAction (\_ ->
    (liftIO $ map U.getJsonUser <$> runDb U.getUsers) >>= json
  )

whoAmI :: ActionM ()
whoAmI =
  Secure.loggedAction (\user ->
    json (U.getJsonUser user)
  )