Skip to content

Commit

Permalink
Add File upload question
Browse files Browse the repository at this point in the history
  • Loading branch information
vknaisl committed Oct 18, 2024
1 parent 4d89582 commit 7d3a657
Show file tree
Hide file tree
Showing 99 changed files with 1,436 additions and 23 deletions.
2 changes: 2 additions & 0 deletions shared-common/src/Shared/Common/Util/Aeson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jsonSpecialFields "qiId" = "id"
jsonSpecialFields "sId" = "id"
jsonSpecialFields "tId" = "id"
jsonSpecialFields "aData" = "data"
jsonSpecialFields "adData" = "data"
jsonSpecialFields "seData" = "data"
jsonSpecialFields "scData" = "data"
jsonSpecialFields "sqData" = "data"
Expand All @@ -66,6 +67,7 @@ jsonSpecialFields "oRole" = "role"
jsonSpecialFields "uRole" = "role"
jsonSpecialFields "sValue" = "value"
jsonSpecialFields "aValue" = "value"
jsonSpecialFields "fValue" = "value"
jsonSpecialFields "mcValue" = "value"
jsonSpecialFields "ilValue" = "value"
jsonSpecialFields "iValue" = "value"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ instance FromJSON AddQuestionEvent where
"ValueQuestion" -> parseJSON (Object o) >>= \event -> return (AddValueQuestionEvent' event)
"IntegrationQuestion" -> parseJSON (Object o) >>= \event -> return (AddIntegrationQuestionEvent' event)
"ItemSelectQuestion" -> parseJSON (Object o) >>= \event -> return (AddItemSelectQuestionEvent' event)
"FileQuestion" -> parseJSON (Object o) >>= \event -> return (AddFileQuestionEvent' event)
_ -> fail "One of the events has unsupported questionType"
parseJSON _ = mzero

Expand Down Expand Up @@ -66,6 +67,13 @@ instance FromJSON AddItemSelectQuestionEvent where
instance ToJSON AddItemSelectQuestionEvent where
toJSON = toJSONWithAdditionalData [("questionType", "ItemSelectQuestion")]

-- --------------------------------------------
instance FromJSON AddFileQuestionEvent where
parseJSON = genericParseJSON jsonOptions

instance ToJSON AddFileQuestionEvent where
toJSON = toJSONWithAdditionalData [("questionType", "FileQuestion")]

-- --------------------------------------------
-- --------------------------------------------
instance ToJSON EditQuestionEvent where
Expand All @@ -81,6 +89,7 @@ instance FromJSON EditQuestionEvent where
"ValueQuestion" -> parseJSON (Object o) >>= \event -> return (EditValueQuestionEvent' event)
"IntegrationQuestion" -> parseJSON (Object o) >>= \event -> return (EditIntegrationQuestionEvent' event)
"ItemSelectQuestion" -> parseJSON (Object o) >>= \event -> return (EditItemSelectQuestionEvent' event)
"FileQuestion" -> parseJSON (Object o) >>= \event -> return (EditFileQuestionEvent' event)
_ -> fail "One of the events has unsupported questionType"
parseJSON _ = mzero

Expand Down Expand Up @@ -126,6 +135,13 @@ instance FromJSON EditItemSelectQuestionEvent where
instance ToJSON EditItemSelectQuestionEvent where
toJSON = toJSONWithAdditionalData [("questionType", "ItemSelectQuestion")]

-- --------------------------------------------
instance FromJSON EditFileQuestionEvent where
parseJSON = genericParseJSON jsonOptions

instance ToJSON EditFileQuestionEvent where
toJSON = toJSONWithAdditionalData [("questionType", "FileQuestion")]

-- --------------------------------------------
-- --------------------------------------------
instance FromJSON DeleteQuestionEvent where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ instance ToSchema AddIntegrationQuestionEvent where
instance ToSchema AddItemSelectQuestionEvent where
declareNamedSchema = toSwaggerWithType "eventType" a_km1_ch3_q13'

instance ToSchema AddFileQuestionEvent where
declareNamedSchema = toSwaggerWithType "eventType" a_km1_ch3_q14'

-- --------------------------------------------
-- --------------------------------------------
instance ToSchema EditQuestionEvent
Expand All @@ -52,6 +55,9 @@ instance ToSchema EditIntegrationQuestionEvent where
instance ToSchema EditItemSelectQuestionEvent where
declareNamedSchema = toSwaggerWithType "eventType" e_km1_ch3_q13'

instance ToSchema EditFileQuestionEvent where
declareNamedSchema = toSwaggerWithType "eventType" e_km1_ch3_q14'

-- --------------------------------------------
-- --------------------------------------------
instance ToSchema DeleteQuestionEvent where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ instance FromJSON Question where
"ValueQuestion" -> parseJSON (Object o) >>= \event -> return (ValueQuestion' event)
"IntegrationQuestion" -> parseJSON (Object o) >>= \event -> return (IntegrationQuestion' event)
"ItemSelectQuestion" -> parseJSON (Object o) >>= \event -> return (ItemSelectQuestion' event)
"FileQuestion" -> parseJSON (Object o) >>= \event -> return (FileQuestion' event)
_ -> fail "One of the questions has unsupported questionType"
parseJSON _ = mzero

Expand Down Expand Up @@ -93,6 +94,13 @@ instance ToJSON ItemSelectQuestion where
instance FromJSON ItemSelectQuestion where
parseJSON = genericParseJSON (jsonOptionsWithTypeField "questionType")

-- --------------------------------------------------------------------
instance ToJSON FileQuestion where
toJSON = genericToJSON (jsonOptionsWithTypeField "questionType")

instance FromJSON FileQuestion where
parseJSON = genericParseJSON (jsonOptionsWithTypeField "questionType")

-- --------------------------------------------------------------------
-- --------------------------------------------------------------------
instance ToJSON Answer where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ instance ToSchema IntegrationQuestion where
instance ToSchema ItemSelectQuestion where
declareNamedSchema = toSwaggerWithType "questionType" question13

-- --------------------------------------------------------------------
instance ToSchema FileQuestion where
declareNamedSchema = toSwaggerWithType "questionType" question14

-- --------------------------------------------------------------------
-- --------------------------------------------------------------------
instance ToSchema Answer where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,25 @@ a_km1_ch3_q13 =
, createdAt = dt' 2018 1 21
}

a_km1_ch3_q14' :: AddQuestionEvent
a_km1_ch3_q14' = AddFileQuestionEvent' a_km1_ch3_q14

a_km1_ch3_q14 :: AddFileQuestionEvent
a_km1_ch3_q14 =
AddFileQuestionEvent
{ uuid = u' "cdd54bfa-b2de-4ab3-9022-bc512cfa297f"
, parentUuid = chapter3.uuid
, entityUuid = question14.uuid
, title = question14.title
, text = question14.text
, requiredPhaseUuid = question14.requiredPhaseUuid
, annotations = question14.annotations
, tagUuids = question14.tagUuids
, maxSize = question14.maxSize
, fileTypes = question14.fileTypes
, createdAt = dt' 2018 1 21
}

e_km1_ch1_q1' :: EditQuestionEvent
e_km1_ch1_q1' = EditValueQuestionEvent' e_km1_ch1_q1

Expand Down Expand Up @@ -531,7 +550,7 @@ e_km1_ch3_q13 =
EditItemSelectQuestionEvent
{ uuid = u' "f95ace16-9a2c-4f66-b22f-e419e5014c58"
, parentUuid = chapter3.uuid
, entityUuid = question2.uuid
, entityUuid = question13Edited.uuid
, title = ChangedValue $ question13Edited.title
, text = ChangedValue $ question13Edited.text
, requiredPhaseUuid = ChangedValue $ question13Edited.requiredPhaseUuid
Expand All @@ -543,6 +562,27 @@ e_km1_ch3_q13 =
, createdAt = dt' 2018 1 21
}

e_km1_ch3_q14' :: EditQuestionEvent
e_km1_ch3_q14' = EditFileQuestionEvent' e_km1_ch3_q14

e_km1_ch3_q14 :: EditFileQuestionEvent
e_km1_ch3_q14 =
EditFileQuestionEvent
{ uuid = u' "cd144dd9-c722-400f-9972-2642177dee06"
, parentUuid = chapter3.uuid
, entityUuid = question14Edited.uuid
, title = ChangedValue question14Edited.title
, text = ChangedValue question14Edited.text
, requiredPhaseUuid = ChangedValue question14Edited.requiredPhaseUuid
, annotations = ChangedValue question14Edited.annotations
, tagUuids = ChangedValue question14Edited.tagUuids
, expertUuids = ChangedValue question14Edited.expertUuids
, referenceUuids = ChangedValue question14Edited.referenceUuids
, maxSize = ChangedValue question14Edited.maxSize
, fileTypes = ChangedValue question14Edited.fileTypes
, createdAt = dt' 2018 1 21
}

d_km1_ch1_q1 :: DeleteQuestionEvent
d_km1_ch1_q1 =
DeleteQuestionEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ chapter3 =
, title = "Data Capture/Measurement"
, text = Just ""
, annotations = []
, questionUuids = [question9.uuid, question10.uuid, question11.uuid, question12.uuid, question13.uuid]
, questionUuids = [question9.uuid, question10.uuid, question11.uuid, question12.uuid, question13.uuid, question14.uuid]
}

chapter4WithoutQuestions :: Chapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ km1 =
, question11'
, question12'
, question13'
, question14'
]
, answers =
toMap
Expand Down Expand Up @@ -138,6 +139,7 @@ km1WithQ4Plain =
, question11'
, question12'
, question13'
, question14'
]
, answers =
toMap
Expand Down Expand Up @@ -198,6 +200,7 @@ km1WithQ4 =
, question11'
, question12'
, question13'
, question14'
]
, answers =
toMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,39 @@ question13Edited =
, expertUuids = []
, listQuestionUuid = Just q4_it1_question5.uuid
}

question14' :: Question
question14' = FileQuestion' question14

question14 :: FileQuestion
question14 =
FileQuestion
{ uuid = u' "00000000-0000-0000-0000-000000000f14"
, title = "Fourteen Question"
, text = Just "Some non-funny description"
, requiredPhaseUuid = Nothing
, annotations = []
, tagUuids = [tagBioInformatic.uuid]
, referenceUuids = []
, expertUuids = []
, maxSize = Just 20000
, fileTypes = Just "application/json"
}

question14Edited' :: Question
question14Edited' = FileQuestion' question14Edited

question14Edited :: FileQuestion
question14Edited =
FileQuestion
{ uuid = question14.uuid
, title = "EDITED: Fourteen Question"
, text = Just "EDITED: Some non-funny description"
, requiredPhaseUuid = Just $ phase2.uuid
, annotations = []
, tagUuids = [tagBioInformatic.uuid]
, referenceUuids = []
, expertUuids = []
, maxSize = Just 40000
, fileTypes = Just "text/html"
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ germanyPackage =
, AddChoiceEvent' a_km1_ch3_q11_cho2
, AddQuestionEvent' a_km1_ch3_q12'
, AddQuestionEvent' a_km1_ch3_q13'
, AddQuestionEvent' a_km1_ch3_q14'
]
, nonEditable = False
, tenantUuid = U.nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data AddQuestionEvent
| AddValueQuestionEvent' AddValueQuestionEvent
| AddIntegrationQuestionEvent' AddIntegrationQuestionEvent
| AddItemSelectQuestionEvent' AddItemSelectQuestionEvent
| AddFileQuestionEvent' AddFileQuestionEvent
deriving (Show, Eq, Generic)

data AddOptionsQuestionEvent = AddOptionsQuestionEvent
Expand Down Expand Up @@ -100,6 +101,21 @@ data AddItemSelectQuestionEvent = AddItemSelectQuestionEvent
}
deriving (Show, Eq, Generic)

data AddFileQuestionEvent = AddFileQuestionEvent
{ uuid :: U.UUID
, parentUuid :: U.UUID
, entityUuid :: U.UUID
, title :: String
, text :: Maybe String
, requiredPhaseUuid :: Maybe U.UUID
, annotations :: [MapEntry String String]
, tagUuids :: [U.UUID]
, maxSize :: Maybe Int
, fileTypes :: Maybe String
, createdAt :: UTCTime
}
deriving (Show, Eq, Generic)

-- --------------------------------------------
data EditQuestionEvent
= EditOptionsQuestionEvent' EditOptionsQuestionEvent
Expand All @@ -108,6 +124,7 @@ data EditQuestionEvent
| EditValueQuestionEvent' EditValueQuestionEvent
| EditIntegrationQuestionEvent' EditIntegrationQuestionEvent
| EditItemSelectQuestionEvent' EditItemSelectQuestionEvent
| EditFileQuestionEvent' EditFileQuestionEvent
deriving (Show, Eq, Generic)

data EditOptionsQuestionEvent = EditOptionsQuestionEvent
Expand Down Expand Up @@ -207,6 +224,23 @@ data EditItemSelectQuestionEvent = EditItemSelectQuestionEvent
}
deriving (Show, Eq, Generic)

data EditFileQuestionEvent = EditFileQuestionEvent
{ uuid :: U.UUID
, parentUuid :: U.UUID
, entityUuid :: U.UUID
, title :: EventField String
, text :: EventField (Maybe String)
, requiredPhaseUuid :: EventField (Maybe U.UUID)
, annotations :: EventField [MapEntry String String]
, tagUuids :: EventField [U.UUID]
, expertUuids :: EventField [U.UUID]
, referenceUuids :: EventField [U.UUID]
, maxSize :: EventField (Maybe Int)
, fileTypes :: EventField (Maybe String)
, createdAt :: UTCTime
}
deriving (Show, Eq, Generic)

-- --------------------------------------------
data DeleteQuestionEvent = DeleteQuestionEvent
{ uuid :: U.UUID
Expand Down
Loading

0 comments on commit 7d3a657

Please sign in to comment.