Skip to content

Commit

Permalink
Pagination limit and readme update (#40)
Browse files Browse the repository at this point in the history
* update readme with pagination query param

* customize pagination
  • Loading branch information
Prometheo authored Jul 9, 2024
1 parent 60a430a commit 59dc627
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Possible Error Codes:

#### Pagination

Pagination available using `limit` and `offset` query params on endpoints that specify `paginated`. Default `limit` is 30.
Pagination available using `limit` and `page` as query param on endpoints that specify `paginated`. Default `limit` is 30.

Endpoints that support pagination will return a success response containing the following:

Expand Down
3 changes: 2 additions & 1 deletion accounts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
AccountSerializer,
PaginatedAccountsResponseSerializer,
)
from api.pagination import ResultPagination


class DonorsAPI(APIView, PageNumberPagination):
Expand Down Expand Up @@ -87,7 +88,7 @@ def get(self, request: Request, *args, **kwargs):
return self.get_paginated_response(serializer.data)


class AccountsListAPI(APIView, PageNumberPagination):
class AccountsListAPI(APIView, ResultPagination):

@extend_schema(
responses={
Expand Down
6 changes: 6 additions & 0 deletions api/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from rest_framework.pagination import PageNumberPagination

class ResultPagination(PageNumberPagination):
page_size = 30
page_size_query_param = 'limit'
max_page_size = 200
2 changes: 1 addition & 1 deletion base/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework import serializers


class TwoDecimalStringField(serializers.DecimalField):
class ResultPagination(serializers.DecimalField):
def to_representation(self, value):
if value is None:
return value
Expand Down
3 changes: 1 addition & 2 deletions base/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
DEFAULT_PAGE_SIZE = 30

REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"DEFAULT_PAGINATION_CLASS": "api.pagination.ResultPagination",
"PAGE_SIZE": DEFAULT_PAGE_SIZE,
"DEFAULT_THROTTLE_CLASSES": [
# "rest_framework.throttling.UserRateThrottle",
Expand Down Expand Up @@ -166,7 +166,6 @@
"https://alpha.potlock.xyz",
"https://alpha.potlock.app", # regex matching might not be advisable.
"http://dev.local",
"https://dev.local",
]

# REDIS / CACHE CONFIGS
Expand Down
6 changes: 3 additions & 3 deletions pots/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
from rest_framework.serializers import ModelSerializer, SerializerMethodField

from accounts.serializers import SIMPLE_ACCOUNT_EXAMPLE, AccountSerializer
from base.serializers import TwoDecimalStringField
from base.serializers import ResultPagination
from tokens.serializers import SIMPLE_TOKEN_EXAMPLE, TokenSerializer

from .models import Pot, PotApplication, PotPayout


class PotSerializer(ModelSerializer):
total_matching_pool_usd = TwoDecimalStringField(max_digits=20, decimal_places=2)
total_public_donations_usd = TwoDecimalStringField(max_digits=20, decimal_places=2)
total_matching_pool_usd = ResultPagination(max_digits=20, decimal_places=2)
total_public_donations_usd = ResultPagination(max_digits=20, decimal_places=2)

class Meta:
model = Pot
Expand Down

0 comments on commit 59dc627

Please sign in to comment.