Skip to content

Commit

Permalink
Added resolvers for DateTime and DateTime nullable.
Browse files Browse the repository at this point in the history
Added endpoints for Specific Bill endpoint.
  • Loading branch information
babelshift committed Feb 17, 2017
1 parent 5f32ef2 commit 4712cf7
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 56 deletions.
98 changes: 48 additions & 50 deletions ProPublicaCongressAPI/AutoMapperConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using AutoMapper;
using ProPublicaCongressAPI.Resolvers;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace ProPublicaCongressAPI
{
Expand Down Expand Up @@ -41,17 +39,7 @@ public static void Initialize()
x.CreateMap<InternalModels.MemberVote, Contracts.MemberVote>()
.ForMember(dest => dest.DateTimeVoted, opts => opts.ResolveUsing(source =>
{
string rawDateTimeVoted = source.DateVoted;
if(!String.IsNullOrWhiteSpace(source.TimeVoted))
{
rawDateTimeVoted += " " + source.TimeVoted;
}
DateTime dateTimeVoted;
DateTime.TryParse(rawDateTimeVoted, out dateTimeVoted);
return dateTimeVoted;
return CreateDateTimeFromDateAndTime(source.DateVoted, source.TimeVoted);
}));
x.CreateMap<InternalModels.MemberVotesContainer, Contracts.MemberVotesContainer>();
Expand All @@ -67,17 +55,7 @@ public static void Initialize()
x.CreateMap<InternalModels.RollCallVote, Contracts.RollCallVote>()
.ForMember(dest => dest.DateTimeRollCall, opts => opts.ResolveUsing(source =>
{
string rawDateTimeVoted = source.DateRollCall;
if (!String.IsNullOrWhiteSpace(source.TimeRollCall))
{
rawDateTimeVoted += " " + source.TimeRollCall;
}
DateTime dateTimeVoted;
DateTime.TryParse(rawDateTimeVoted, out dateTimeVoted);
return dateTimeVoted;
return CreateDateTimeFromDateAndTime(source.DateRollCall, source.TimeRollCall);
}));
x.CreateMap<InternalModels.RollCallVoteSummaryDemocratic, Contracts.RollCallVoteSummaryDemocratic>();
x.CreateMap<InternalModels.RollCallVoteSummaryRepublican, Contracts.RollCallVoteSummaryRepublican>();
Expand All @@ -92,43 +70,48 @@ public static void Initialize()
x.CreateMap<InternalModels.VoteByDate, Contracts.VoteByDate>()
.ForMember(dest => dest.DateTimeVoted, opts => opts.ResolveUsing(source =>
{
string rawDateTimeVoted = source.DateVoted;
if (!String.IsNullOrWhiteSpace(source.TimeVoted))
{
rawDateTimeVoted += " " + source.TimeVoted;
}
DateTime dateTimeVoted;
DateTime.TryParse(rawDateTimeVoted, out dateTimeVoted);
return dateTimeVoted;
return CreateDateTimeFromDateAndTime(source.DateVoted, source.TimeVoted);
}));
x.CreateMap<InternalModels.VoteByDateContainer, Contracts.VoteByDateContainer>();
x.CreateMap<InternalModels.SenateNominationVote, Contracts.SenateNominationVote>()
.ForMember(dest => dest.DateTimeVoted, opts => opts.ResolveUsing(source =>
{
string rawDateTimeVoted = source.DateVoted;
if (!String.IsNullOrWhiteSpace(source.TimeVoted))
{
rawDateTimeVoted += " " + source.TimeVoted;
}
DateTime dateTimeVoted;
DateTime.TryParse(rawDateTimeVoted, out dateTimeVoted);
return dateTimeVoted;
return CreateDateTimeFromDateAndTime(source.DateVoted, source.TimeVoted);
}));
x.CreateMap<InternalModels.SenateNominationVoteContainer, Contracts.SenateNominationVoteContainer>();
x.CreateMap<InternalModels.RecentBill, Contracts.RecentBill>();
x.CreateMap<InternalModels.RecentBill, Contracts.RecentBill>()
.ForMember(dest => dest.DateIntroduced,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateIntroduced))
.ForMember(dest => dest.DateLatestMajorAction,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateLatestMajorAction));
x.CreateMap<InternalModels.RecentBillsContainer, Contracts.RecentBillsContainer>();
x.CreateMap<InternalModels.RecentBillByMember, Contracts.RecentBillByMember>();
x.CreateMap<InternalModels.RecentBillByMember, Contracts.RecentBillByMember>()
.ForMember(dest => dest.DateIntroduced,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateIntroduced))
.ForMember(dest => dest.DateLatestMajorAction,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateLatestMajorAction));
x.CreateMap<InternalModels.RecentBillsByMemberContainer, Contracts.RecentBillsByMemberContainer>();
x.CreateMap<InternalModels.SpecificBillVoteSummary, Contracts.SpecificBillVoteSummary>()
.ForMember(dest => dest.DateTimeVoted, opts => opts.ResolveUsing(source =>
{
return CreateDateTimeFromDateAndTime(source.DateVoted, source.TimeVoted);
}));
x.CreateMap<InternalModels.SpecificBillAction, Contracts.SpecificBillAction>()
.ForMember(dest => dest.DateTimeOccurred,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateTimeOccurred));
x.CreateMap<InternalModels.SpecificBill, Contracts.SpecificBill>()
.ForMember(dest => dest.DateIntroduced,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateIntroduced))
.ForMember(dest => dest.DateHousePassageVote,
opts => opts.ResolveUsing<NullableDateTimeResolver, string>(s => s.DateHousePassageVote))
.ForMember(dest => dest.DateSenatePassageVote,
opts => opts.ResolveUsing<NullableDateTimeResolver, string>(s => s.DateSenatePassageVote))
.ForMember(dest => dest.DateLatestMajorAction,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateLatestMajorAction));
});
}

Expand All @@ -144,6 +127,21 @@ public static void Initialize()
#endif
}

private static DateTime CreateDateTimeFromDateAndTime(string date, string time)
{
string rawDateTime = date;

if (!String.IsNullOrWhiteSpace(time))
{
rawDateTime += " " + time;
}

DateTime parsedDateTime;
DateTime.TryParse(rawDateTime, out parsedDateTime);

return parsedDateTime;
}

public static void Reset()
{
config = null;
Expand Down
8 changes: 5 additions & 3 deletions ProPublicaCongressAPI/Contracts/RecentBill.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace ProPublicaCongressAPI.Contracts
using System;

namespace ProPublicaCongressAPI.Contracts
{
public class RecentBill
{
Expand All @@ -10,15 +12,15 @@ public class RecentBill

public string SponsorMemberDetailUrl { get; set; }

public string DateIntroduced { get; set; }
public DateTime DateIntroduced { get; set; }

public int CosponsorCount { get; set; }

public string Committees { get; set; }

public string PrimarySubject { get; set; }

public string DateLatestMajorAction { get; set; }
public DateTime DateLatestMajorAction { get; set; }

public string LatestMajorAction { get; set; }
}
Expand Down
8 changes: 5 additions & 3 deletions ProPublicaCongressAPI/Contracts/RecentBillByMember.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace ProPublicaCongressAPI.Contracts
using System;

namespace ProPublicaCongressAPI.Contracts
{
public class RecentBillByMember
{
Expand All @@ -12,15 +14,15 @@ public class RecentBillByMember

public string SponsorMemberId { get; set; }

public string DateIntroduced { get; set; }
public DateTime DateIntroduced { get; set; }

public int CosponsorCount { get; set; }

public string Committees { get; set; }

public string PrimarySubject { get; set; }

public string DateLatestMajorAction { get; set; }
public DateTime DateLatestMajorAction { get; set; }

public string LatestMajorAction { get; set; }
}
Expand Down
26 changes: 26 additions & 0 deletions ProPublicaCongressAPI/Contracts/SpecificBill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;

namespace ProPublicaCongressAPI.Contracts
{
public class SpecificBill
{
public int Congress { get; set; }
public string BillNumber { get; set; }
public string BillDetailUrl { get; set; }
public string BillTitle { get; set; }
public string SponsorMemberName { get; set; }
public string SponsorMemberDetailUrl { get; set; }
public string BillDocumentPdfUrl { get; set; }
public DateTime DateIntroduced { get; set; }
public int CosponsorCount { get; set; }
public string PrimarySubject { get; set; }
public string Committees { get; set; }
public DateTime DateLatestMajorAction { get; set; }
public string LatestMajorAction { get; set; }
public DateTime? DateHousePassageVote { get; set; }
public DateTime? DateSenatePassageVote { get; set; }
public IReadOnlyCollection<SpecificBillAction> Actions { get; set; }
public IReadOnlyCollection<SpecificBillVoteSummary> Votes { get; set; }
}
}
11 changes: 11 additions & 0 deletions ProPublicaCongressAPI/Contracts/SpecificBillAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace ProPublicaCongressAPI.Contracts
{
public class SpecificBillAction
{
public DateTime DateTimeOccurred { get; set; }

public string Description { get; set; }
}
}
25 changes: 25 additions & 0 deletions ProPublicaCongressAPI/Contracts/SpecificBillVoteSummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace ProPublicaCongressAPI.Contracts
{
public class SpecificBillVoteSummary
{
public string Chamber { get; set; }

public DateTime DateTimeVoted { get; set; }

public int RollCallNumber { get; set; }

public string Question { get; set; }

public string Result { get; set; }

public int TotalYesVoteCount { get; set; }

public int TotalNoVoteCount { get; set; }

public int TotalNotVotingCount { get; set; }

public string VoteDetailUrl { get; set; }
}
}
59 changes: 59 additions & 0 deletions ProPublicaCongressAPI/InternalModels/SpecificBill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace ProPublicaCongressAPI.InternalModels
{
internal class SpecificBill
{
[JsonProperty("datetime")]
public int Congress { get; set; }

[JsonProperty("bill")]
public string BillNumber { get; set; }

[JsonProperty("bill_uri")]
public string BillDetailUrl { get; set; }

[JsonProperty("title")]
public string BillTitle { get; set; }

[JsonProperty("sponsor")]
public string SponsorMemberName { get; set; }

[JsonProperty("sponsor_uri")]
public string SponsorMemberDetailUrl { get; set; }

[JsonProperty("gpo_pdf_uri")]
public string BillDocumentPdfUrl { get; set; }

[JsonProperty("introduced_date")]
public string DateIntroduced { get; set; }

[JsonProperty("cosponsors")]
public int CosponsorCount { get; set; }

[JsonProperty("primary_subject")]
public string PrimarySubject { get; set; }

[JsonProperty("committees")]
public string Committees { get; set; }

[JsonProperty("latest_major_action_date")]
public string DateLatestMajorAction { get; set; }

[JsonProperty("latest_major_action")]
public string LatestMajorAction { get; set; }

[JsonProperty("house_passage_vote")]
public string DateHousePassageVote { get; set; }

[JsonProperty("senate_passage_vote")]
public string DateSenatePassageVote { get; set; }

[JsonProperty("actions")]
public IReadOnlyCollection<SpecificBillAction> Actions { get; set; }

[JsonProperty("votes")]
public IReadOnlyCollection<SpecificBillVoteSummary> Votes { get; set; }
}
}
13 changes: 13 additions & 0 deletions ProPublicaCongressAPI/InternalModels/SpecificBillAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace ProPublicaCongressAPI.InternalModels
{
internal class SpecificBillAction
{
[JsonProperty("datetime")]
public string DateTimeOccurred { get; set; }

[JsonProperty("description")]
public string Description { get; set; }
}
}
37 changes: 37 additions & 0 deletions ProPublicaCongressAPI/InternalModels/SpecificBillVoteSummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Newtonsoft.Json;

namespace ProPublicaCongressAPI.InternalModels
{
internal class SpecificBillVoteSummary
{
[JsonProperty("chamber")]
public string Chamber { get; set; }

[JsonProperty("date")]
public string DateVoted { get; set; }

[JsonProperty("time")]
public string TimeVoted { get; set; }

[JsonProperty("roll_call")]
public int RollCallNumber { get; set; }

[JsonProperty("question")]
public string Question { get; set; }

[JsonProperty("result")]
public string Result { get; set; }

[JsonProperty("total_yes")]
public int TotalYesVoteCount { get; set; }

[JsonProperty("total_no")]
public int TotalNoVoteCount { get; set; }

[JsonProperty("total_not_voting")]
public int TotalNotVotingCount { get; set; }

[JsonProperty("api_url")]
public string VoteDetailUrl { get; set; }
}
}
Loading

0 comments on commit 4712cf7

Please sign in to comment.