Skip to content

Instantly share code, notes, and snippets.

@5outh
Last active July 3, 2018 19:35
Embed
What would you like to do?
Authorized
orNotFound :: MaybeT Handler a -> Handler a
orNotFound mHandler = do
act <- runMaybeT mHandler
maybe notFound act
withStudentToken :: (StudentId -> CourseId -> Handler a) -> MaybeT Handler a
withStudentToken action = do
mStudentToken <- MaybeT optionalStudentToken
case mStudentToken of
Nothing -> mempty
Just (StudentAuth studentId courseId) -> MaybeT $ action studentId courseId
withTeacherToken :: (TeacherId -> Handler a) -> MaybeT Handler a
withTeacherToken action = do
mTeacherToken <- MaybeT optionalTeacherToken
case mTeacherToken of
Nothing -> mempty
Just (TeacherAuth teacherId) -> MaybeT $ action teacherId
myHandler = orNotFound $ withStudentToken handleStudent <|> withTeacherToken handleTeacher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment