keCommentRouteDB :: [Language] -> CommentId -> DB (Maybe (Route App))
makeCommentRouteDB langs comment_id = get comment_id >>= \case
    Nothing -> return Nothing
    Just comment ->
        fetchDiscussionDB langs (commentDiscussion comment) >>= \case
            DiscussionOnProject (Entity _ project) ->
                return $ Just $
                    ProjectCommentR (projectHandle project) comment_id

            DiscussionOnWikiPage (Entity _ wiki_target) -> do
                project <- getJust $ wikiTargetProject wiki_target
                return $ Just $
                    WikiCommentR
                        (projectHandle project)
                        (wikiTargetLanguage wiki_target)
                        (wikiTargetTarget wiki_target)
                        comment_id

            DiscussionOnUser (Entity user_id _) ->
                return $ Just $ UserCommentR user_id comment_id

            DiscussionOnBlogPost (Entity _ blog_post) -> do
                project <- getJust $ blogPostProject blog_post

                return $ Just $
                    BlogPostCommentR
                    (projectHandle project)
                    (blogPostHandle blog_post)
                    comment_id

makeCommentRouteDB :: [Language] -> CommentId -> DB (Maybe (Route App))
makeCommentRouteDB langs comment_id = get comment_id >>= \case
    Nothing -> return Nothing
    Just comment ->
        fetchDiscussionDB langs (commentDiscussion comment) >>= \case
            DiscussionOnProject (Entity _ project) ->
                return $ Just $
                    ProjectCommentR (projectHandle project) comment_id

            DiscussionOnWikiPage (Entity _ wiki_target) -> do
                project <- getJust $ wikiTargetProject wiki_target
                return $ Just $
                    WikiCommentR
                        (projectHandle project)
                        (wikiTargetLanguage wiki_target)
                        (wikiTargetTarget wiki_target)
                        comment_id

            DiscussionOnUser (Entity user_id _) ->
                return $ Just $ UserCommentR user_id comment_id

            DiscussionOnBlogPost (Entity _ blog_post) -> do
                project <- getJust $ blogPostProject blog_post

                return $ Just $
                    BlogPostCommentR
                    (projectHandle project)
                    (blogPostHandle blog_post)
                    comment_id
makeCommentRouteDB langs comment_id = get comment_id >>= \case
    Nothing -> return Nothing
    Just comment ->
        fetchDiscussionDB langs (commentDiscussion comment) >>= \case
            DiscussionOnProject (Entity _ project) ->
                return $ Just $
                    ProjectCommentR (projectHandle project) comment_id

            DiscussionOnWikiPage (Entity _ wiki_target) -> do
                project <- getJust $ wikiTargetProject wiki_target
                return $ Just $
                    WikiCommentR
                        (projectHandle project)
                        (wikiTargetLanguage wiki_target)
                        (wikiTargetTarget wiki_target)
                        comment_id

            DiscussionOnUser (Entity user_id _) ->
                return $ Just $ UserCommentR user_id comment_id

            DiscussionOnBlogPost (Entity _ blog_post) -> do
                project <- getJust $ blogPostProject blog_post

                return $ Just $
                    BlogPostCommentR
                    (projectHandle project)
                    (blogPostHandle blog_post)
                    comment_id