-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
23 changes: 23 additions & 0 deletions
23
django/thunderstore/community/api/experimental/serializers.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from rest_framework import serializers | ||
|
||
from thunderstore.community.models import Community, PackageCategory | ||
|
||
|
||
class CommunitySerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Community | ||
fields = ( | ||
"identifier", | ||
"name", | ||
"discord_url", | ||
"wiki_url", | ||
) | ||
|
||
|
||
class PackageCategorySerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = PackageCategory | ||
fields = ( | ||
"name", | ||
"slug", | ||
) |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.urls import path | ||
|
||
from thunderstore.community.api.experimental.views import ( | ||
CommunitiesExperimentalApiView, | ||
PackageCategoriesExperimentalApiView, | ||
) | ||
|
||
urls = [ | ||
path( | ||
"community/", | ||
CommunitiesExperimentalApiView.as_view(), | ||
name="communities", | ||
), | ||
path( | ||
"community/<slug:community>/category/", | ||
PackageCategoriesExperimentalApiView.as_view(), | ||
name="categories", | ||
), | ||
] |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from thunderstore.community.api.experimental.serializers import ( | ||
CommunitySerializer, | ||
PackageCategorySerializer, | ||
) | ||
from thunderstore.community.models import Community | ||
|
||
|
||
class CommunitiesExperimentalApiView(APIView): | ||
def get(self, request, format=None): | ||
communities = CommunitySerializer(Community.objects.listed(), many=True) | ||
return Response( | ||
{ | ||
"communities": communities.data, | ||
}, | ||
) | ||
|
||
|
||
class PackageCategoriesExperimentalApiView(APIView): | ||
def get(self, request, format=None, **kwargs): | ||
community_identifier = kwargs["community"] | ||
community = Community.objects.filter(identifier=community_identifier).first() | ||
if not community: | ||
return Response({"error": "Community not found"}, 404) | ||
communities = PackageCategorySerializer(community.package_categories, many=True) | ||
return Response( | ||
{ | ||
"packageCategories": communities.data, | ||
}, | ||
) |
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