ageddesi/Mocked-API

Sports endpoint amount filter doesn't work properly

GuilhermeFernandes01 opened this issue · 3 comments

Describe the bug
Endpoint /sports/football/leagues/premier/teams should expect qty path parameter to return the amount of results wanted but it doesn't work. It always returns all teams.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '/sports/football/leagues/premier/teams' endpoint
  2. Try to call the endpoint with qty path parameter setted to any value from 1 to 19
  3. See error (all teams were returned)

Expected behavior
Return the amount of teams wanted.

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Version: 105.0.5195.127

Additional context
I'd like to contribute with this issue and I have some suggestions:

  1. To move qty path param to be a query param so when we fix to use qty param as an amount filter it wouldn't be a breaking change
  2. To return random teams when it's a sub array of the league (qty < 20)
  3. To return the list in random order when all teams are requested
  4. To add other leagues (/sports/football/leagues/laliga/teams, /sports/football/leagues/ligue1/teams, etc.)

What do you think?

nibih commented

hi, can i take a crack at this?

Hi @GuilhermeFernandes01
Thanks for the suggestions. This would be a great fix and addition to the API. We have a helper function for the qty from url params. so please use this. getQtyFromRequest

The latest branch is v0.13.0 and if you need any help feel free to message here or join our discord channel. https://discord.gg/6UaxgtsM

Maybe you could give one of the leagues to add to @nibih

Hi @nibih, sure. You could get the fix on '/sports/football/leagues/premier/teams' endpoint if you want to. I've just opened a PR #185 with La Liga endpoint implementation and created a helper function to return a random subarray. You could use it getRandomSubArray.

Hey @ageddesi would be valid add a hacktoberfest label here? 😄