From af9fe80bf5e816b5f3a383b1b711f4291e44fa6f Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 6 Sep 2019 09:38:00 +0200 Subject: [PATCH] refactor: cleanup --- src/Handler/Utils/Submission.hs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Handler/Utils/Submission.hs b/src/Handler/Utils/Submission.hs index 951b711fd..bafc69e84 100644 --- a/src/Handler/Utils/Submission.hs +++ b/src/Handler/Utils/Submission.hs @@ -76,16 +76,18 @@ writeSubmissionPlan :: Map SubmissionId (Maybe UserId) ) -- ^ Returns assigned and unassigned submissions; unassigned submissions occur only if no tutors have an assigned load writeSubmissionPlan newSubmissionData = do now <- liftIO getCurrentTime - execWriterT . forM_ (Map.toList newSubmissionData) $ \(subId, mCorrector) -> case mCorrector of - Just _ -> do - sub <- lift $ getJust subId - lift $ update subId [ SubmissionRatingBy =. mCorrector - , SubmissionRatingAssigned =. Just now - ] - lift $ audit $ TransactionSubmissionEdit subId $ sub ^. _submissionSheet - tell (Set.singleton subId, mempty) - Nothing -> - tell (mempty, Set.singleton subId) + execWriterT . forM_ (Map.toList newSubmissionData) $ \(subId, mCorrector) -> if + | is _Just mCorrector + -> do + lift $ do + Submission{submissionSheet} <- updateGet subId + [ SubmissionRatingBy =. mCorrector + , SubmissionRatingAssigned =. Just now + ] + audit $ TransactionSubmissionEdit subId submissionSheet + tell (Set.singleton subId, mempty) + | otherwise + -> tell (mempty, Set.singleton subId) -- | Compute a map that shows which submissions ought the be assigned to each corrector according to sheet corrector loads, but does not alter database yet! -- May throw an exception if there are no suitable correctors @@ -569,10 +571,10 @@ sinkSubmission userId mExists isUpdate = do getSheetId :: MonadIO m => ReaderT SqlBackend m SheetId getSheetId = case mExists of - Left shid -> return shid - Right _ -> do - Just Submission{submissionSheet} <- E.get submissionId -- there must have been a submission, otherwise mExists would have been Left shid - return submissionSheet + Left shid + -> return shid + Right _ + -> submissionSheet <$> getJust submissionId -- there must have been a submission, otherwise mExists would have been Left shid finalize :: SubmissionSinkState -> YesodJobDB UniWorX () finalize SubmissionSinkState{..} = do