tuna42na / baby-namr

Baby Naming Application Frontend
0 stars 1 forks source link

Support year range query parameters #4

Open trvslhlt opened 3 years ago

trvslhlt commented 3 years ago

We would like users to be able to look at names from a range of years. The current api supports a "year" query param. We want to enhance this to allow start and end year ranges.

tuna42na commented 3 years ago

@cwkarwisch You have any preferences? On the frontend, I believe that it would be easiest to split this into two parameters. That way if a person is to submit a request that wants all years after 1930 you don't have to run a separate query to make sure that all the dates are before 2019.

does "yearBegin=" and "yearEnd=" work for you as a schema?

cwkarwisch commented 3 years ago

"yearBegin=" and "yearEnd=" works for me.

tuna42na commented 3 years ago

@cwkarwisch what are the year ranges that we are working with again? 1890 -2019?

cwkarwisch commented 3 years ago

@tuna42na We have data for 1880-2019.

cwkarwisch commented 3 years ago

@tuna42na I've updated the api to support year ranges and deployed those changes to Heroku. You can take a look at the pull request with the relevant changes here.

Now, for example, you could make a request for /names?name=David&yearStart=2018&yearEnd=2019 and you would receive the following JSON back:

[{"id":276899,"name":"David","sex":"M","count":9767,"popularity":22,"year":2018,"country":"U.S.A.","created_at":"2021-02-19T02:57:41.148Z","updated_at":"2021-02-19T02:57:41.148Z"},{"id":278904,"name":"David","sex":"M","count":8896,"popularity":27,"year":2019,"country":"U.S.A.","created_at":"2021-02-19T02:57:41.863Z","updated_at":"2021-02-19T02:57:41.863Z"}]

As written, if a yearStart query parameter is included, but no yearEnd, the api will only send data for the year specified in yearStart. Similarly, if a yearEnd parameter is included without a yearStart, the api will only send data for the yearEnd provided.