Skip to content

Commit 094150d

Browse files
Merge pull request #368 from ProgramEquity/gov-filtering-cicero-api
Updated gov filtering to work with Cicero API
2 parents 2578f65 + 40b71f4 commit 094150d

2 files changed

Lines changed: 38 additions & 28 deletions

File tree

server/routes/api/representatives.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ const router = express.Router()
99
const { CICERO_API_KEY } = process.env
1010

1111
const JURISDICTION_FILTER_MAP = {
12-
federal: 'country',
13-
state: 'administrativeArea1',
14-
county: 'administrativeArea2',
15-
municipality: 'locality'
12+
federal: ['NATIONAL_UPPER', 'NATIONAL_LOWER'],
13+
state: ['STATE_EXEC', 'STATE_UPPER', 'STATE_LOWER'],
14+
county: ['COUNTY'],
15+
local: ['LOCAL_EXEC', 'LOCAL'],
16+
school: ['SCHOOL']
1617
}
1718
const ALLOWED_JURISDICTION_FILTERS = Object.keys(JURISDICTION_FILTER_MAP)
1819

@@ -40,27 +41,24 @@ router.get('/:zipCode', async (req, res) => {
4041
}
4142

4243
try {
44+
const params = {
45+
search_postal: zipCode,
46+
search_country: 'US',
47+
order: 'district_type', // https://cicero.azavea.com/docs/#order-by-district-type
48+
sort: 'asc',
49+
max: 200,
50+
format: 'json',
51+
key: CICERO_API_KEY
52+
}
53+
54+
if (filter != null) {
55+
params.district_type = JURISDICTION_FILTER_MAP[filter]
56+
}
57+
4358
const {
4459
data: { response }
4560
} = await axios.get('https://cicero.azavea.com/v3.1/official', {
46-
params: {
47-
search_postal: zipCode,
48-
search_country: 'US',
49-
district_type: [
50-
'NATIONAL_UPPER',
51-
'NATIONAL_LOWER',
52-
'STATE_EXEC',
53-
'STATE_UPPER',
54-
'STATE_LOWER',
55-
'LOCAL_EXEC',
56-
'LOCAL'
57-
],
58-
order: 'district_type', // https://cicero.azavea.com/docs/#order-by-district-type
59-
sort: 'asc',
60-
max: 200,
61-
format: 'json',
62-
key: CICERO_API_KEY
63-
},
61+
params,
6462
paramsSerializer: (params) =>
6563
qs.stringify(params, { arrayFormat: 'repeat' })
6664
})

src/components/SearchReps.vue

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@
4747
State
4848
</v-btn>
4949

50+
<v-btn
51+
rounded
52+
dark
53+
class="ui button toggle search-reps-button"
54+
:style="{
55+
backgroundColor:
56+
currentFilter === 'local' && isActive ? 'blue' : 'gray'
57+
}"
58+
@click="FilterList('local')"
59+
>
60+
Local
61+
</v-btn>
62+
5063
<v-btn
5164
class="search-reps-button"
5265
rounded
@@ -62,18 +75,17 @@
6275
</v-btn>
6376

6477
<v-btn
78+
class="search-reps-button"
6579
rounded
6680
dark
67-
class="ui button toggle search-reps-button"
81+
:class="{ active: isActive }"
6882
:style="{
6983
backgroundColor:
70-
currentFilter === 'municipality' && isActive
71-
? 'blue'
72-
: 'gray'
84+
currentFilter === 'school' && isActive ? 'blue' : 'gray'
7385
}"
74-
@click="FilterList('municipality')"
86+
v-on:click="FilterList('school')"
7587
>
76-
Local
88+
School
7789
</v-btn>
7890
</v-col>
7991
</v-row>

0 commit comments

Comments
 (0)