Skip to content

Commit

Permalink
get all list registrations for an account (#68)
Browse files Browse the repository at this point in the history
* get all list registrations for an account

* update readme

* remove category filter
  • Loading branch information
Prometheo authored Jul 29, 2024
1 parent cf5ced4 commit 8e4a8b0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ enum PotApplicationStatus {
}
```

#### ✅ Get registrations to lists by account: `GET /accounts/{ACCOUNT_ID}/list-registrations` (paginated)

Can specify status to filter by using `status` query param if desired, e.g. `status=Approved`

### `List` endpoints

#### ✅ Get all lists: `GET /lists` (paginated)
Expand Down
50 changes: 50 additions & 0 deletions accounts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
DonationSerializer,
PaginatedDonationsResponseSerializer,
)
from lists.models import ListRegistration, ListRegistrationStatus
from lists.serializers import PAGINATED_LIST_REGISTRATION_EXAMPLE, ListRegistrationSerializer, PaginatedListRegistrationsResponseSerializer
from pots.models import Pot, PotApplication, PotApplicationStatus, PotPayout
from pots.serializers import (
PAGINATED_PAYOUT_EXAMPLE,
Expand Down Expand Up @@ -391,3 +393,51 @@ def get(self, request: Request, *args, **kwargs):
results = self.paginate_queryset(payouts, request, view=self)
serializer = PotPayoutSerializer(results, many=True)
return self.get_paginated_response(serializer.data)


class AccountListRegistrationsAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
OpenApiParameter("account_id", str, OpenApiParameter.PATH),
*pagination_parameters,
],
responses={
200: OpenApiResponse(
response=PaginatedListRegistrationsResponseSerializer,
description="Returns List registrations for the account provided",
examples=[
OpenApiExample(
"example-1",
summary="Simple registration example",
description="Example response for list registrations",
value=PAGINATED_LIST_REGISTRATION_EXAMPLE,
response_only=True,
),
],
),
404: OpenApiResponse(description="Account not found"),
500: OpenApiResponse(description="Internal server error"),
},
)
@method_decorator(cache_page(60 * 5))
def get(self, request: Request, *args, **kwargs):
account_id = kwargs.get("account_id")
try:
account = Account.objects.get(id=account_id)
except Account.DoesNotExist:
return Response(
{"message": f"Account with ID {account_id} not found."}, status=404
)

registrations = ListRegistration.objects.filter(registrant=account)
status_param = request.query_params.get("status")
if status_param:
if status_param not in ListRegistrationStatus.values:
return Response(
{"message": f"Invalid status value: {status_param}"}, status=400
)
registrations = registrations.filter(status=status_param)
results = self.paginate_queryset(registrations, request, view=self)
serializer = ListRegistrationSerializer(results, many=True)
return self.get_paginated_response(serializer.data)
6 changes: 6 additions & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
AccountDetailAPI,
AccountDonationsReceivedAPI,
AccountDonationsSentAPI,
AccountListRegistrationsAPI,
AccountPayoutsReceivedAPI,
AccountPotApplicationsAPI,
AccountsListAPI,
Expand Down Expand Up @@ -76,6 +77,11 @@
AccountPayoutsReceivedAPI.as_view(),
name="accounts_api_by_id_payouts_received",
),
path(
"v1/accounts/<str:account_id>/list-registrations",
AccountListRegistrationsAPI.as_view(),
name="accounts_api_by_id_registrations",
),
# donate contract config
path(
"v1/donate_contract_config",
Expand Down

0 comments on commit 8e4a8b0

Please sign in to comment.