Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor

  • Loading branch information...
commit 4375cef67b78b04d6029bf8998ff9bf718ca6e80 1 parent 3aed704
@samstokes authored
Showing with 7 additions and 6 deletions.
  1. +7 −6 Handler/Root.hs
View
13 Handler/Root.hs
@@ -3,6 +3,7 @@ module Handler.Root where
import Control.Applicative
import Data.Text (Text)
+import Database.Persist.GenericSql.Raw (SqlPersist)
import Yesod.Auth (maybeAuthId)
import Foundation
@@ -69,15 +70,15 @@ postTasksR = maybeAuthId >>= postTasksR' where
postCompleteTaskR :: TaskId -> Handler RepHtml
-postCompleteTaskR = setTaskDoneness True
+postCompleteTaskR = updateAndRedirect TasksR [TaskDone =. True]
postRestartTaskR :: TaskId -> Handler RepHtml
-postRestartTaskR = setTaskDoneness False
+postRestartTaskR = updateAndRedirect TasksR [TaskDone =. False]
-setTaskDoneness :: Bool -> TaskId -> Handler RepHtml
-setTaskDoneness done taskId = do
- runDB $ update taskId [TaskDone =. done]
- redirectTemporary TasksR
+updateAndRedirect :: (PersistEntity val, HasReps a) => YesodoroRoute -> [Update val] -> Key SqlPersist val -> Handler a
+updateAndRedirect route updates fieldId = do
+ runDB $ update fieldId updates
+ redirectTemporary route
setTaskDonenessRoute :: (TaskId, Task) -> YesodoroRoute
setTaskDonenessRoute (taskId, task) = route taskId
Please sign in to comment.
Something went wrong with that request. Please try again.