eidolon/Handler/AdminComments.hs
2014-12-28 01:08:35 +01:00

44 lines
1.4 KiB
Haskell

module Handler.AdminComments where
import Import
import Handler.Commons
import Data.Maybe
import Data.Time
import System.Locale
getAdminCommentR :: Handler Html
getAdminCommentR = do
adminCheck <- loginIsAdmin
case adminCheck of
Right _ -> do
media <- runDB $ selectList [] [Desc MediumTime]
comments <- runDB $ selectList [CommentParent ==. Nothing] [Desc CommentTime]
replies <- runDB $ selectList [CommentParent !=. Nothing] [Desc CommentTime]
defaultLayout $ do
setTitle "Administration: Comments"
$(widgetFile "adminComments")
Left (errorMsg, route) -> do
setMessage errorMsg
redirect $ route
getAdminCommentDeleteR :: CommentId -> Handler Html
getAdminCommentDeleteR commentId = do
adminCheck <- loginIsAdmin
case adminCheck of
Right _ -> do
tempComment <- runDB $ get commentId
case tempComment of
Just comment -> do
-- delete comment children
children <- runDB $ selectList [CommentParent ==. (Just commentId)] []
mapM (\ent -> runDB $ delete $ entityKey ent) children
-- delete comment itself
runDB $ delete commentId
setMessage "Comment deleted succesfully"
redirect $ AdminR
Nothing -> do
setMessage "This comment does not exist"
redirect $ AdminR
Left (errorMsg, route) -> do
setMessage errorMsg
redirect $ route