-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify cyberstorm community APIs implementation
Simplify how the cyberstorm commmunity API endpoints are implemented, mostly by relying on existing logic from django rest framework where possible. Main changes include: - Removing most queryset filtering logic from views (replaced by DRF built-in functionalities) - Removing most queryset ordering logic from views (replaced by DRF built-in functionalities + a small custom class) - Removed the complex download/package count aggregate query from the views, as that's a task better suited for background jobs that should be implemented separately. - Removed tests related to the download/package count calculation, as those are the responsibility of the background job (once implemented) and not directly related to the API here. These changes slightly alter the API spec (e.g. how pagination works), but that should be alright given the complexity cost it saves us on the backend. Refs TS-1682
- Loading branch information
1 parent
c00c7ed
commit f17155c
Showing
9 changed files
with
120 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1 @@ | ||
from .community import ( | ||
CommunityListQueryParameterSerializerCyberstorm, | ||
CommunityListSerializerCyberstorm, | ||
CommunitySerializerCyberstorm, | ||
) | ||
|
||
__all__ = [ | ||
"CommunitySerializerCyberstorm", | ||
"CommunityListQueryParameterSerializerCyberstorm", | ||
"CommunityListSerializerCyberstorm", | ||
] | ||
from .community import CyberstormCommunitySerializer |
24 changes: 5 additions & 19 deletions
24
django/thunderstore/api/cyberstorm/serializers/community.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,11 @@ | ||
from rest_framework import serializers | ||
|
||
|
||
class CommunitySerializerCyberstorm(serializers.Serializer): | ||
class CyberstormCommunitySerializer(serializers.Serializer): | ||
name = serializers.CharField() | ||
identifier = serializers.CharField() | ||
download_count = serializers.IntegerField(min_value=0, default=0) | ||
package_count = serializers.IntegerField(min_value=0, default=0) | ||
background_image_url = serializers.CharField() | ||
total_download_count = serializers.IntegerField() | ||
total_package_count = serializers.IntegerField() | ||
background_image_url = serializers.CharField(required=False) | ||
description = serializers.CharField() | ||
discord_link = serializers.CharField(required=False) | ||
|
||
|
||
class CommunityListQueryParameterSerializerCyberstorm(serializers.Serializer): | ||
page_size = serializers.IntegerField(default=50, min_value=1, max_value=50) | ||
ordering = serializers.ChoiceField(required=False, choices=["name"]) | ||
page = serializers.IntegerField(default=1, min_value=1) | ||
|
||
|
||
class CommunityListSerializerCyberstorm(serializers.Serializer): | ||
current = serializers.IntegerField() | ||
final = serializers.IntegerField() | ||
total = serializers.IntegerField() | ||
count = serializers.IntegerField() | ||
results = CommunitySerializerCyberstorm(many=True) | ||
discord_url = serializers.CharField(required=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.