Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Track 8/9] Users query #30

Open
taki-tiler-server bot opened this issue Sep 9, 2024 · 4 comments
Open

[Track 8/9] Users query #30

taki-tiler-server bot opened this issue Sep 9, 2024 · 4 comments

Comments

@taki-tiler-server
Copy link

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
@GuiCastelo
Copy link
Contributor

Finish

Copy link
Author

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. Change the query response type to be of the type below:

  • The users, obviously 🤣
  • The total number of users
  • Some way of knowing if there are users before those that just returned
  • Some way of knowing if there are users after those that just returned

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

  • Skip a certain number of users
  • Choose the amount of users that will return (already implemented on previous step)

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. 10 more orders, skipping 10
  3. 10 more orders, 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 the information 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!

@GuiCastelo
Copy link
Contributor

Finish

Copy link
Author

Click here for your next track

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant