diff options
| -rw-r--r-- | Omni/Jr/Web.hs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/Omni/Jr/Web.hs b/Omni/Jr/Web.hs index 7416604..beef8bb 100644 --- a/Omni/Jr/Web.hs +++ b/Omni/Jr/Web.hs @@ -23,6 +23,8 @@ import Servant import qualified Servant.HTML.Lucid as Lucid import Web.FormUrlEncoded (FromForm (..), parseUnique) +type PostRedirect = Verb 'POST 303 '[Lucid.HTML] (Headers '[Header "Location" Text] NoContent) + defaultPort :: Warp.Port defaultPort = 8080 @@ -30,7 +32,7 @@ type API = Get '[Lucid.HTML] HomePage :<|> "tasks" :> Get '[Lucid.HTML] TaskListPage :<|> "tasks" :> Capture "id" Text :> Get '[Lucid.HTML] TaskDetailPage - :<|> "tasks" :> Capture "id" Text :> "status" :> ReqBody '[FormUrlEncoded] StatusForm :> Post '[Lucid.HTML] TaskDetailPage + :<|> "tasks" :> Capture "id" Text :> "status" :> ReqBody '[FormUrlEncoded] StatusForm :> PostRedirect newtype HomePage = HomePage () @@ -330,13 +332,10 @@ server = homeHandler :<|> taskListHandler :<|> taskDetailHandler :<|> taskStatus Nothing -> pure (TaskDetailNotFound tid) Just task -> pure (TaskDetailFound task tasks) - taskStatusHandler :: Text -> StatusForm -> Servant.Handler TaskDetailPage + taskStatusHandler :: Text -> StatusForm -> Servant.Handler (Headers '[Header "Location" Text] NoContent) taskStatusHandler tid (StatusForm newStatus) = do liftIO <| TaskCore.updateTaskStatus tid newStatus [] - tasks <- liftIO TaskCore.loadTasks - case TaskCore.findTask tid tasks of - Nothing -> pure (TaskDetailNotFound tid) - Just task -> pure (TaskDetailFound task tasks) + pure <| addHeader ("/tasks/" <> tid) NoContent app :: Application app = serve api server |
