Compare commits

..

No commits in common. "6763d3ffa1a5a6cfde30b8ea3967ad54d7e681fa" and "d389e78ddcc4234245df5b10949b63a40989a1fb" have entirely different histories.

2 changed files with 4 additions and 12 deletions

View File

@ -8,4 +8,3 @@ Webserver that offers an HTML-only interface to Squeak.
- Improve error handling: Write functions that turn `Maybe` and `Either` `SpockAction`s that return `4xx` or `5xx`.
- Document JSON stuff
- Record times: How long did HTTP requests take?

View File

@ -9,7 +9,7 @@ module Lisa
import Control.Monad.IO.Class (MonadIO)
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Network.HTTP.Types.Status (Status, badRequest400, internalServerError500)
import Network.HTTP.Types.Status (badRequest400)
import Text.Blaze.Html (Html)
import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
import Web.Internal.HttpApiData (FromHttpApiData)
@ -38,13 +38,6 @@ requiredParam k = param k >>= \case
Just val ->
pure val
-- TODO: Generalize, introduce some sort of Lisa.Types.Error type
-- TODO: Make more readable
onLeft :: MonadIO m => (ActionCtxT ctx m (Either e a)) -> (Status, Text) -> ActionCtxT ctx m a
onLeft f (status, message) = f >>= (flip either pure $ \_ -> do
setStatus status
text message)
-- Exports
mkConfig :: IO (SpockCfg () Session State)
@ -58,9 +51,9 @@ app = do
blaze Views.viewIndex
get ("lectures" <//> var) $ \lid -> do
lecture <- getLectureByIdCached lid `onLeft` (internalServerError500, "Failed to retrieve lectures")
documents <- Squeak.getDocumentsByLectureId lid `onLeft` (internalServerError500, "Failed to retrieve documents")
blaze $ Views.viewLecture lecture documents
lecture <- getLectureByIdCached lid
documents <- Squeak.getDocumentsByLectureId lid
blaze $ either Views.viewSqueakError id $ Views.viewLecture <$> lecture <*> documents
get "lectures" $ do
query <- fromMaybe "" <$> param "query"