Always serialize OaklandCandidate with contribution calculations
By adding a `supporting_contribution_data` and
`opposing_contribution_data` to the candidate object's serialization, we
will make sure that we have top-line contribution numbers for any screen
we could need it. Plus it's not good API design to return two different
versions of the same object depending on the endpoint requested.
Fixes #17
cc @adborden @jnmarcus @kylew because of the backwards incompatibility
https://github.com/caciviclab/disclosure-backend-static/pull/19
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
Oops, messed up the JSON shenanigans.
@adborden commented on this pull request.
In models/oakland_candidate.rb:
> @@ -30,6 +30,29 @@ def as_json(options = nil) last_name: last_name, ballot_item: office_election.id, office_election: office_election.id, + + # contribution data + supporting_contribution_data: {
nitpick, I prefer to leave off the _data
, since all of this is data and feels redundant. I think having an entity named supporting_contributions
or supporting_money
is totally cool and very descriptive of the domain we're working in.
Sweeet, thanks for getting to this so fast! I talked to Tom briefly and this was the high-level comments I had:
/locality/:id/current_ballot
) because this extra support/opposing data would also be included for all candidates. Not a huge deal, but might consider maybe we don't need candidates at all in that endpoint.👍
> @@ -30,6 +30,29 @@ def as_json(options = nil) last_name: last_name, ballot_item: office_election.id, office_election: office_election.id
, + + # contribution data + supporting_contribution_data: { + contributions_received: calculation(:total_contributions).try(:to_f), + total_contributions: calculation(:total_contributions).try(:to_f), + total_expenditures: calculation(:total_expenditures).try(:to_f), + total_loans_received: calculation(:total_loans_received).try(:to_f), + contributions_by_type: calculation(:contributions_by_type) || {}, + expenditures_by_type: calculation(:expenditures_by_type) || {}, + }, + opposing_contribution_data: {
Oh, I'm trying to get clarification from Suzanne, but I'm not sure that there is anyway for money opposing a candidate to be filed... like it would just show up as expenditures from another committee, but not actually tied in anyway to the candidate through filings... Do you know how that works?
@adborden commented on this pull request.
In models/oakland_candidate.rb:
> @@ -30,6 +30,29 @@ def as_json(options = nil) last_name: last_name, ballot_item: office_election.id, office_election: office_election.id, + + # contribution data + supporting_contribution_data: { + contributions_received: calculation(:total_contributions).try(:to_f), + total_contributions: calculation(:total_contributions).try(:to_f), + total_expenditures: calculation(:total_expenditures).try(:to_f), + total_loans_received: calculation(:total_loans_received).try(:to_f), + contributions_by_type: calculation(:contributions_by_type) || {}, + expenditures_by_type: calculation(:expenditures_by_type) || {}, + }, + opposing_contribution_data: {
Ah, I got an answer, it does get reported. A committee can exist for the purpose of defeating a candidate and will report expenditures as opposing the candidate. Carry on.
@tdooner commented on this pull request.
In models/oakland_candidate.rb:
> @@ -30,6 +30,29 @@ def as_json(options = nil) last_name: last_name, ballot_item: office_election.id, office_election: office_election.id, + + # contribution data + supporting_contribution_data: {
Hm, okay, I'll do that before merging.
> @@ -30,6 +30,29 @@ def as_json(options = nil) last_name: last_name, ballot_item: office_election.id, office_election: office_election.id
, + + # contribution data + supporting_contribution_data: { + contributions_received: calculation(:total_contributions).try(:to_f), + total_contributions: calculation(:total_contributions).try(:to_f), + total_expenditures: calculation(:total_expenditures).try(:to_f), + total_loans_received: calculation(:total_loans_received).try(:to_f), + contributions_by_type: calculation(:contributions_by_type) || {}, + expenditures_by_type: calculation(:expenditures_by_type) || {}, + }, + opposing_contribution_data: {
Yeah, I'd be surprised if we have any data for this, but I guess we want to at least start theoretically tracking this.
@tdooner pushed 1 commit.
—
You are receiving this because you are subscribed to this thread.
View it on GitHub or mute the thread.
Merged #19.