From e9cdbea34a59b031251a4426d48d77f33b1485ab Mon Sep 17 00:00:00 2001 From: jankun4 Date: Sun, 7 Apr 2024 20:18:43 +0200 Subject: [PATCH] [#636] add references to all proposal related endpoints --- CHANGELOG.md | 1 + govtool/backend/sql/list-proposals.sql | 1 + govtool/backend/src/VVA/API.hs | 1 + govtool/backend/src/VVA/API/Types.hs | 23 +++++++++++++++++++++++ govtool/backend/src/VVA/Proposal.hs | 2 ++ govtool/backend/src/VVA/Types.hs | 1 + 6 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92b74e9d3..2524c51f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ changes. - addded latestTxHash to the `drep/info` and `drep/list` endpoints [Issue 627](https://github.com/IntersectMBO/govtool/issues/627) - added `txHash` to `drep/getVotes` [Issue 626](https://github.com/IntersectMBO/govtool/issues/626) +- added `references` to all proposal related endpoints - added `epochNo` and `date` to `drep/getVotes` and `proposal/get` - Added `isRegisteredAsSoleVoter` and `wasRegisteredAsSoleVoter` fields to the drep/info response [Issue 212](https://github.com/IntersectMBO/govtool/issues/212) - Abandoning registration as DRep [Issue 151](https://github.com/IntersectMBO/govtool/issues/151) diff --git a/govtool/backend/sql/list-proposals.sql b/govtool/backend/sql/list-proposals.sql index f0bc3cc13..e6a67bd0a 100644 --- a/govtool/backend/sql/list-proposals.sql +++ b/govtool/backend/sql/list-proposals.sql @@ -60,6 +60,7 @@ SELECT off_chain_vote_data.motivation, off_chain_vote_data.rationale, off_chain_vote_data.json, + off_chain_vote_data.json#>'{body, references}' as references, coalesce(Sum(ldd.amount) FILTER (WHERE voting_procedure.vote::text = 'Yes'), 0) +( CASE WHEN gov_action_proposal.type = 'NoConfidence' THEN always_no_confidence_voting_power.amount diff --git a/govtool/backend/src/VVA/API.hs b/govtool/backend/src/VVA/API.hs index e5ef660a0..c10c257b6 100644 --- a/govtool/backend/src/VVA/API.hs +++ b/govtool/backend/src/VVA/API.hs @@ -138,6 +138,7 @@ proposalToResponse Types.Proposal {..} = proposalResponseMotivation = proposalMotivaiton, proposalResponseRationale = proposalRationale, proposalResponseMetadata = GovernanceActionMetadata <$> proposalMetadata, + proposalResponseReferences = GovernanceActionReferences <$> proposalReferences, proposalResponseYesVotes = proposalYesVotes, proposalResponseNoVotes = proposalNoVotes, proposalResponseAbstainVotes = proposalAbstainVotes diff --git a/govtool/backend/src/VVA/API/Types.hs b/govtool/backend/src/VVA/API/Types.hs index d1e2024ca..354ae54a4 100644 --- a/govtool/backend/src/VVA/API/Types.hs +++ b/govtool/backend/src/VVA/API/Types.hs @@ -267,6 +267,27 @@ instance ToSchema GovernanceActionMetadata where +newtype GovernanceActionReferences + = GovernanceActionReferences Value + deriving newtype (Show) + +instance FromJSON GovernanceActionReferences where + parseJSON v@(Aeson.Array a) = pure (GovernanceActionReferences v) + parseJSON _ = fail "GovernanceActionReferences has to be an array" + +instance ToJSON GovernanceActionReferences where + toJSON (GovernanceActionReferences g) = g + +instance ToSchema GovernanceActionReferences where + declareNamedSchema _ = pure $ NamedSchema (Just "GovernanceActionReferences") $ mempty + & type_ ?~ OpenApiObject + & description ?~ "A Governance Action References" + & example + ?~ toJSON + ("[{\"uri\": \"google.com\", \"@type\": \"Other\", \"label\": \"example label\"}]" :: Text) + + + data ProposalResponse = ProposalResponse { proposalResponseId :: Text @@ -285,6 +306,7 @@ data ProposalResponse , proposalResponseMotivation :: Maybe Text , proposalResponseRationale :: Maybe Text , proposalResponseMetadata :: Maybe GovernanceActionMetadata + , proposalResponseReferences :: Maybe GovernanceActionReferences , proposalResponseYesVotes :: Integer , proposalResponseNoVotes :: Integer , proposalResponseAbstainVotes :: Integer @@ -310,6 +332,7 @@ exampleProposalResponse = "{ \"id\": \"proposalId123\"," <> "\"motivation\": \"Proposal Motivation\"," <> "\"rationale\": \"Proposal Rationale\"," <> "\"metadata\": {\"key\": \"value\"}," + <> "\"references\": [{\"uri\": \"google.com\", \"@type\": \"Other\", \"label\": \"example label\"}]," <> "\"yesVotes\": 0," <> "\"noVotes\": 0," <> "\"abstainVotes\": 0}" diff --git a/govtool/backend/src/VVA/Proposal.hs b/govtool/backend/src/VVA/Proposal.hs index e2c949992..970ebde78 100644 --- a/govtool/backend/src/VVA/Proposal.hs +++ b/govtool/backend/src/VVA/Proposal.hs @@ -87,6 +87,7 @@ getProposals mProposalIds = withPool $ \conn -> do , motivation' , rationale' , metadataJson' + , references' , yesVotes' , noVotes' , abstainVotes' @@ -111,6 +112,7 @@ getProposals mProposalIds = withPool $ \conn -> do motivation' rationale' metadataJson' + references' (floor @Scientific yesVotes') (floor @Scientific noVotes') (floor @Scientific abstainVotes') diff --git a/govtool/backend/src/VVA/Types.hs b/govtool/backend/src/VVA/Types.hs index b913270d3..91f2952b4 100644 --- a/govtool/backend/src/VVA/Types.hs +++ b/govtool/backend/src/VVA/Types.hs @@ -113,6 +113,7 @@ data Proposal , proposalMotivaiton :: Maybe Text , proposalRationale :: Maybe Text , proposalMetadata :: Maybe Value + , proposalReferences :: Maybe Value , proposalYesVotes :: Integer , proposalNoVotes :: Integer , proposalAbstainVotes :: Integer