Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
18 changes: 18 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const express = require('express'),
path = require('path'),
app = express();

const legislators = require('./controllers/legislators_controller');

app.set('view engine', 'hbs');
app.use(express.static(path.join(__dirname, 'public')));

app.get('/', (req, res, next) => {
res.render('homepage');
});

app.use('/legislators', legislators);

app.listen(3000, () => {
console.log('success!');
});
172 changes: 172 additions & 0 deletions assets/stylesheets/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
$root-font-size: 16px;
$primary-font-family: "Lucida Grande", Helvetica, Arial, sans-serif;
$primary-font-color: #333;

$primary-color: #F5F5F5;
$secondary-color: #FEFFF8;
$highlight-color: #EBFF00;
$border-color: #ccc;

// Normalize
* {
padding: 0;
margin: 0;
box-sizing: border-box;
color: $primary-font-color;
font-family: $primary-font-family;
font-weight: normal;
}

body {
font-size: $root-font-size;
background-color: $primary-color;
padding: 2rem;
}

main {
width: 500px;
}

section, div, h1, h2, h3, h4, p {
margin-bottom: 1rem;
}

ul {
list-style-type: none;
}

a:link, a:visited, a:active {
text-decoration: none;
color: $primary-font-color;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}

// Utilities
.hide {
display: none;
}

.highlight {
background-color: $highlight-color;
}

.callout {
opacity: .5;
}

.bold {
font-weight: bold;
}

.center {
margin: 0 auto;
}

.text-align--center {
text-align: center;
}

// Components
.card {
border: 1px solid $border-color;
background-color: white;
padding: 1rem;
text-align: start;
margin-bottom: .5rem;

&.card--red {
border-color: red;
}

&.card--green {
border-color: green;
}
}

// Page
.page__title {
text-align: center;
font-weight: bold;
}

// Button
.btn {
background-color: $highlight-color;
border: 1px solid $border-color;
border-radius: 8px;
padding: .3rem 1rem;
}

// Zip
.zip__container {
border: 1px solid $border-color;
background-color: $secondary-color;
padding: .5rem;
display: flex;
flex-direction: column;
align-items: center;
}

.zip__numbers__list {
display: flex;
justify-content: space-around;
margin-bottom: .5rem;
}

.zip__numbers__item {
border: 1px solid $border-color;
background-color: white;
height: 3rem;
width: 2.6rem;
border-radius: 6px;
display: flex;
align-items: center;
justify-content: center;

&:not(:last-child) {
margin-right: 1rem;
}
}

.zip__number {
border: none;
height: 2.5rem;
width: 2rem;
font-size: 1.5rem;
text-align: center;
}

.zip {
margin-bottom: 2rem;
}

// Legislator
.legislators__list {
text-align: start;
}

.legislator__item {
display: flex;
margin-bottom: 1.5rem;
}

.legislator__photo {
width: 100px;
height: 100px;
border-radius: 100px;
margin-right: 1.5rem;
}

.legislator__info {
align-self: center;
}

.legislator__name {
font-size: 1.3rem;
font-weight: bold;
}
27 changes: 27 additions & 0 deletions controllers/legislators_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const express = require('express');
const router = express.Router();
const Legislator = require('../models/legislator');

router.get('/', (req, res, next) => {
const zip = req.query.zip

Legislator.findByZip(zip)
.then(legislators => {
res.render('index', {
zip: zip,
houseMembers: Legislator.filterForHouse(legislators),
senateMembers: Legislator.filterForSenate(legislators)
});
});
});

router.get('/:id', (req, res, next) => {
Legislator.findById(req.params.id)
.then(legislator => {
legislator.bills().then(bills => {
res.render('show', {legislator: legislator, bills: bills});
});
});
});

module.exports = router;
7 changes: 7 additions & 0 deletions models/bill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = class Bill {
constructor(id, description, vote) {
this.id = id;
this.description = description;
this.vote = vote;
}
}
83 changes: 83 additions & 0 deletions models/legislator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const Bill = require('./bill');
const SunlightCongress = require('../services/sunlight_congress_wrapper');
const api = new SunlightCongress

const photoUrlBase = 'https://theunitedstates.io/images/congress/225x275'

module.exports = class Legislator {
constructor(attributes = {}) {
this.id = attributes.id;
this.name = attributes.name
this.phone = attributes.phone;
this.website = attributes.website;
this.chamber = attributes.chamber;
this.party = attributes.party;
this.photo = attributes.photo;
}


bills() {
return api.billsByLegislator(this.id, bills => {
const newBills = bills.map(bill_container => {
const bill = bill_container.bill
const vote = bill_container.voters[this.id].vote;

if(bill && vote) {
return new Bill(bill.bill_id, bill.official_title, vote);
}
});

return newBills.filter(bill => bill);
});
}

static get photoUrlBase() {
return photoUrlBase;
}

static photo(bioguide_id) {
return `${photoUrlBase}/${bioguide_id}.jpg`
}

static findByZip(zip) {
return api.legislatorsByLocale(zip, legislators => {
return legislators.map(legislator => {
return new Legislator({
id: legislator.bioguide_id,
name: `${legislator.first_name} ${legislator.last_name}`,
phone: legislator.phone,
website: legislator.website,
chamber: `${legislator.chamber}`,
party: Legislator.partyFullName(legislator.party),
photo: Legislator.photo(legislator.bioguide_id)
})
});
});
}

static findById(bioguide_id) {
return api.legislator(bioguide_id, legislator => {
return new Legislator({
id: legislator.bioguide_id,
name: `${legislator.first_name} ${legislator.last_name}`,
phone: legislator.phone,
website: legislator.website,
chamber: `${legislator.chamber}`,
party: Legislator.partyFullName(legislator.party),
photo: Legislator.photo(legislator.bioguide_id)
})
});
}

static partyFullName(partyShortName) {
return partyShortName === 'D' ? 'Democrat' : 'Republican';
}

static filterForSenate(legislators) {
return legislators.filter(legislator => legislator.chamber === "senate");
}

static filterForHouse(legislators) {
return legislators.filter(legislator => legislator.chamber === "house");
}
}
1 change: 1 addition & 0 deletions node_modules/.bin/node-sass

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/nodemon

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.yarn-integrity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/abbrev/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions node_modules/abbrev/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading