module Handler.Utils.ExternalExam
  ( fetchExternalExam
  ) where

import Import


fetchExternalExam :: MonadHandler m => TermId -> SchoolId -> CourseName -> ExamName -> ReaderT SqlBackend m (Entity ExternalExam)
fetchExternalExam tid ssh coursen examn = 
  let cachId = encodeUtf8 $ tshow (tid, ssh, coursen, examn)
  in  cachedBy cachId $ do
      mExtEx <- getBy $ UniqueExternalExam tid ssh coursen examn
      case mExtEx of
        Just extEx -> return extEx
        _          -> notFound
