diff --git a/CHANGELOG.md b/CHANGELOG.md index ac46b534c..b9628fd1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ changes. ### Fixed -- +- Fix mzero parsing error on fetching the /proposal/list [Issue 2446](https://github.com/IntersectMBO/govtool/issues/2446) ### Changed diff --git a/govtool/backend/src/VVA/API/Types.hs b/govtool/backend/src/VVA/API/Types.hs index be1e4000b..3360b3daf 100644 --- a/govtool/backend/src/VVA/API/Types.hs +++ b/govtool/backend/src/VVA/API/Types.hs @@ -274,17 +274,7 @@ newtype GovernanceActionDetails deriving newtype (Show) instance FromJSON GovernanceActionDetails where - parseJSON v@(Aeson.Object o) = do - let kvpList = map snd $ Aeson.toList o - forM_ kvpList $ \case - (Aeson.Object _) -> fail "GovernanceActionDetails cannot have nested objects" - (Aeson.Array a) -> forM_ (toList a) $ \case - (Aeson.Object _) -> fail "GovernanceActionDetails cannot have nested objects" - (Aeson.Array _) -> fail "GovernanceActionDetails cannot have nested arrays" - _ -> pure () - _ -> pure () - return $ GovernanceActionDetails v - parseJSON _ = fail "GovernanceActionDetails has to be an object" + parseJSON v = return $ GovernanceActionDetails v instance ToJSON GovernanceActionDetails where toJSON (GovernanceActionDetails g) = g @@ -292,11 +282,13 @@ instance ToJSON GovernanceActionDetails where instance ToSchema GovernanceActionDetails where declareNamedSchema _ = pure $ NamedSchema (Just "GovernanceActionDetails") $ mempty & type_ ?~ OpenApiObject - & description ?~ "A simple JSON value, with object type values, and no nested arrays" - & example - ?~ toJSON - ("{\"some_key\": \"some value\", \"some_key2\": [1,2,3]}" :: Text) - + & description ?~ "A JSON value that can include nested objects and arrays" + & example ?~ toJSON + (Aeson.object + [ "some_key" .= ("some value" :: String) + , "nested_key" .= Aeson.object ["inner_key" .= (1 :: Int)] + , "array_key" .= [1, 2, 3 :: Int] + ]) newtype GovernanceActionMetadata = GovernanceActionMetadata Value @@ -440,6 +432,11 @@ exampleProposalResponse = "{ \"id\": \"proposalId123\"," <> "\"prevGovActionIndex\": 0," <> "\"prevGovActionTxHash\": \"47c14a128cd024f1b990c839d67720825921ad87ed875def42641ddd2169b39c\"}" +instance ToSchema Value where + declareNamedSchema _ = pure $ NamedSchema (Just "Value") $ mempty + & type_ ?~ OpenApiObject + & description ?~ "Arbitrary JSON value" + instance ToSchema ProposalResponse where declareNamedSchema proxy = do NamedSchema name_ schema_ <- diff --git a/govtool/backend/src/VVA/Proposal.hs b/govtool/backend/src/VVA/Proposal.hs index 22d69ab8e..89e72a8c8 100644 --- a/govtool/backend/src/VVA/Proposal.hs +++ b/govtool/backend/src/VVA/Proposal.hs @@ -82,6 +82,6 @@ getProposals mSearchTerms = withPool $ \conn -> do ) case result of Left (e :: SomeException) -> do + putStrLn $ "Error fetching proposals: " <> show e return [] - Right rows -> do - return rows + Right rows -> return rows \ No newline at end of file diff --git a/govtool/backend/src/VVA/Types.hs b/govtool/backend/src/VVA/Types.hs index 3ce90ca7a..1fcecdd4f 100644 --- a/govtool/backend/src/VVA/Types.hs +++ b/govtool/backend/src/VVA/Types.hs @@ -122,69 +122,69 @@ data DRepRegistration , dRepRegistrationImageHash :: Maybe Text } -data Proposal +data Proposal = Proposal - { proposalId :: Integer - , proposalTxHash :: Text - , proposalIndex :: Integer - , proposalType :: Text - , proposalDetails :: Maybe Value - , proposalExpiryDate :: Maybe LocalTime - , proposalExpiryEpochNo :: Maybe Integer - , proposalCreatedDate :: LocalTime - , proposalCreatedEpochNo :: Integer - , proposalUrl :: Text - , proposalDocHash :: Text - , proposalProtocolParams :: Maybe Value - , proposalTitle :: Maybe Text - , proposalAbstract :: Maybe Text - , proposalMotivation :: Maybe Text - , proposalRationale :: Maybe Text - , proposalDRepYesVotes :: Integer - , proposalDRepNoVotes :: Integer - , proposalDRepAbstainVotes :: Integer - , proposalPoolYesVotes :: Integer - , proposalPoolNoVotes :: Integer - , proposalPoolAbstainVotes :: Integer - , proposalCcYesVotes :: Integer - , proposalCcNoVotes :: Integer - , proposalCcAbstainVotes :: Integer - , proposalPrevGovActionIndex :: Maybe Integer - , proposalPrevGovActionTxHash :: Maybe Text + { proposalId :: Integer + , proposalTxHash :: Text + , proposalIndex :: Integer + , proposalType :: Text + , proposalDetails :: Maybe Value + , proposalExpiryDate :: Maybe LocalTime + , proposalExpiryEpochNo :: Maybe Integer + , proposalCreatedDate :: LocalTime + , proposalCreatedEpochNo :: Integer + , proposalUrl :: Text + , proposalDocHash :: Text + , proposalProtocolParams :: Maybe Value + , proposalTitle :: Maybe Text + , proposalAbstract :: Maybe Text + , proposalMotivation :: Maybe Text + , proposalRationale :: Maybe Text + , proposalDRepYesVotes :: Integer + , proposalDRepNoVotes :: Integer + , proposalDRepAbstainVotes :: Integer + , proposalPoolYesVotes :: Integer + , proposalPoolNoVotes :: Integer + , proposalPoolAbstainVotes :: Integer + , proposalCcYesVotes :: Integer + , proposalCcNoVotes :: Integer + , proposalCcAbstainVotes :: Integer + , proposalPrevGovActionIndex :: Maybe Integer + , proposalPrevGovActionTxHash :: Maybe Text } deriving (Show) instance FromRow Proposal where fromRow = Proposal - <$> field - <*> field - <*> (floor @Scientific <$> field) - <*> field - <*> field - <*> field - <*> field - <*> field - <*> field - <*> field - <*> field - <*> field - <*> field - <*> field - <*> field - <*> field - <*> (floor @Scientific <$> field) - <*> (floor @Scientific <$> field) - <*> (floor @Scientific <$> field) - <*> (floor @Scientific <$> field) - <*> (floor @Scientific <$> field) - <*> (floor @Scientific <$> field) - <*> (floor @Scientific <$> field) - <*> (floor @Scientific <$> field) - <*> (floor @Scientific <$> field) - <*> field - <*> field - + <$> field -- proposalId + <*> field -- proposalTxHash + <*> (floor @Scientific <$> field) -- proposalIndex + <*> field -- proposalType + <*> field -- proposalDetails + <*> field -- proposalExpiryDate + <*> field -- proposalExpiryEpochNo + <*> field -- proposalCreatedDate + <*> field -- proposalCreatedEpochNo + <*> field -- proposalUrl + <*> field -- proposalDocHash + <*> field -- proposalProtocolParams + <*> field -- proposalTitle + <*> field -- proposalAbstract + <*> field -- proposalMotivation + <*> field -- proposalRationale + <*> (floor @Scientific <$> field) -- proposalDRepYesVotes + <*> (floor @Scientific <$> field) -- proposalDRepNoVotes + <*> (floor @Scientific <$> field) -- proposalDRepAbstainVotes + <*> (floor @Scientific <$> field) -- proposalPoolYesVotes + <*> (floor @Scientific <$> field) -- proposalPoolNoVotes + <*> (floor @Scientific <$> field) -- proposalPoolAbstainVotes + <*> (floor @Scientific <$> field) -- proposalCcYesVotes + <*> (floor @Scientific <$> field) -- proposalCcNoVotes + <*> (floor @Scientific <$> field) -- proposalCcAbstainVotes + <*> field -- prevGovActionIndex + <*> field -- prevGovActionTxHash + data TransactionStatus = TransactionStatus { transactionConfirmed :: Bool , votingProcedure :: Maybe Value