chore(exams): connect exam authorship statement form part to model

This commit is contained in:
Sarah Vaupel 2021-06-10 15:13:55 +02:00 committed by Gregor Kleen
parent 57a259d8a2
commit b6a72d9a45
4 changed files with 19 additions and 3 deletions

View File

@ -20,7 +20,7 @@ Exam
examMode ExamMode
staff Text Maybe
partsFrom UTCTime Maybe
-- authorshipStatement AuthorshipStatementDefinitionId Maybe
authorshipStatement AuthorshipStatementDefinitionId Maybe
UniqueExam course name
deriving Generic
ExamPart

View File

@ -40,6 +40,19 @@ postEEditR tid ssh csh examn = do
editExamAct <- formResultMaybe editExamResult $ \ExamForm{..} -> do
res <- trySql @ExamEditException $ do
mAuthorshipStatementId <- case efAuthorshipStatement of
Nothing -> return Nothing
Just newStatementContent -> do
mPreviousStatement <- maybe (pure Nothing) getEntity (oldExam ^. _examAuthorshipStatement)
if
| Just (Entity previousStatementId AuthorshipStatementDefinition{authorshipStatementDefinitionContent=previousStatementContent}) <- mPreviousStatement
, newStatementContent == previousStatementContent
-> return $ Just previousStatementId
| Just (Entity previousStatementId _) <- mPreviousStatement
-> update previousStatementId [ AuthorshipStatementDefinitionContent =. newStatementContent ] >> return (Just previousStatementId)
| otherwise
-> fmap Just $ insert AuthorshipStatementDefinition { authorshipStatementDefinitionContent = newStatementContent }
insertRes <- myReplaceUnique eId Exam
{ examCourse = cid
, examName = efName
@ -60,9 +73,9 @@ postEEditR tid ssh csh examn = do
, examGradingMode = efGradingMode
, examDescription = efDescription
, examExamMode = efExamMode
-- , examAuthorshipStatement = Nothing -- TODO
, examStaff = efStaff
, examPartsFrom = efPartsFrom
, examAuthorshipStatement = mAuthorshipStatementId
}
when (is _Just insertRes) $

View File

@ -29,6 +29,8 @@ postCExamNewR tid ssh csh = do
newExamAct <- formResultMaybe newExamResult $ \ExamForm{..} -> do
now <- liftIO getCurrentTime
mAuthorshipStatementId <- maybe (return Nothing) (fmap Just . insert . AuthorshipStatementDefinition) efAuthorshipStatement
insertRes <- insertUnique Exam
{ examName = efName
, examCourse = cid
@ -49,9 +51,9 @@ postCExamNewR tid ssh csh = do
, examPublicStatistics = efPublicStatistics
, examDescription = efDescription
, examExamMode = efExamMode
-- , examAuthorshipStatement = Nothing -- TODO
, examStaff = efStaff
, examPartsFrom = efPartsFrom
, examAuthorshipStatement = mAuthorshipStatementId
}
whenIsJust insertRes $ \examid -> do
insertMany_

View File

@ -734,6 +734,7 @@ fillDb = do
}
-- , examAuthorshipStatement = Nothing
, examStaff = Just "Hofmann"
, examAuthorshipStatement = Nothing
}
_ <- insert' Material
{ materialCourse = ffp