indigotech / onboard-hugo-cruz

0 stars 0 forks source link

[Track 7/7] Users query #17

Open taki-tiler-server[bot] opened 4 years ago

taki-tiler-server[bot] commented 4 years ago

Step 1/2 - Only list

Estimated time: 2 hours

Your task now is to create a new query called Users.

  1. It will be an authenticated query
  2. It should receive an integer as parameter (optional) that indicates the maximum number of users to return. If not passed, you can return a default number.
  3. It should return users ordered alphabetically
hmartinsc commented 4 years ago

next

taki-tiler-server[bot] commented 4 years ago

Step 2/2 - Pagination

Estimated time: 6 hours

Now, let's increment your Users query with a nice feature: pagination. Let's say the clients using your server want to fetch a list of users and there are lots of them on database. It's not a good practice to return too much users on a single request, because generally the client is not interested in using all of them. So, the solution is to offer separated small parts of users, according to some conditions the client sends.

Let's consider our alphabetically ordered list of users. Your paginated query response should contain the following information:

The client should have the possibility, using optional parameters, to:

In case it's not that clear yet, let's take an example to help: an e-commerce app has to implement a feature of listing all the past orders for a user. The creation team decided that it's going to show, from the most recent to the oldest, the first 10 orders. If the user starts scrolling and reaches some point, 10 more should load. If he/she continues to scroll, 10 more are shown, and so on, until he/she reaches the last order.

In this case, the app should ask the server, in that order:

  1. The first 10 orders
  2. The 10 orders after skipping 10
  3. The 10 orders after skipping 20 (...)

Let's say some user has a total of 35 orders. The steps above would be repeated until the client asks for the last 10 orders (after 30th), in which the server would return the 5 last orders, and some information warning that are no more orders to be loaded.

If you search on the internet, you're going to find different ways of doing pagination, but in general they follow the rules listed above. You can choose anyway you want to do this, given they are followed.

NOTE: as usual, don't forget to write the tests for you query!

hmartinsc commented 4 years ago

next

taki-tiler-server[bot] commented 4 years ago

Congratulations! You just finished the onboard! 🎉