Skip to content

Commit

Permalink
Add package and categories list
Browse files Browse the repository at this point in the history
  • Loading branch information
nihaals committed Mar 7, 2021
1 parent 2bccca6 commit 696e376
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
Empty file.
23 changes: 23 additions & 0 deletions django/thunderstore/community/api/experimental/serializers.py
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",
)
19 changes: 19 additions & 0 deletions django/thunderstore/community/api/experimental/urls.py
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",
),
]
32 changes: 32 additions & 0 deletions django/thunderstore/community/api/experimental/views.py
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,
},
)
16 changes: 14 additions & 2 deletions django/thunderstore/core/api_urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
from django.urls import include, path

from thunderstore.repository.api.experimental.urls import urls as experimental_urls
from thunderstore.community.api.experimental.urls import (
urls as community_experimental_urls,
)
from thunderstore.repository.api.experimental.urls import (
urls as repository_experimental_urls,
)
from thunderstore.repository.api.v1.urls import urls as v1_urls

api_experimental_urls = [
path(
"",
include((experimental_urls, "api-experimental"), namespace="api-experimental"),
include(
(repository_experimental_urls, "api-experimental"),
namespace="api-experimental",
),
),
path(
"",
include(community_experimental_urls),
),
]

Expand Down

0 comments on commit 696e376

Please sign in to comment.