diff --git a/django/thunderstore/community/api/experimental/__init__.py b/django/thunderstore/community/api/experimental/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/django/thunderstore/community/api/experimental/serializers.py b/django/thunderstore/community/api/experimental/serializers.py new file mode 100644 index 000000000..3eba925e7 --- /dev/null +++ b/django/thunderstore/community/api/experimental/serializers.py @@ -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", + ) diff --git a/django/thunderstore/community/api/experimental/urls.py b/django/thunderstore/community/api/experimental/urls.py new file mode 100644 index 000000000..85078fbce --- /dev/null +++ b/django/thunderstore/community/api/experimental/urls.py @@ -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//category/", + PackageCategoriesExperimentalApiView.as_view(), + name="categories", + ), +] diff --git a/django/thunderstore/community/api/experimental/views.py b/django/thunderstore/community/api/experimental/views.py new file mode 100644 index 000000000..88f1a2ee7 --- /dev/null +++ b/django/thunderstore/community/api/experimental/views.py @@ -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, + }, + ) diff --git a/django/thunderstore/core/api_urls.py b/django/thunderstore/core/api_urls.py index 1af56c1af..625bb0d2e 100644 --- a/django/thunderstore/core/api_urls.py +++ b/django/thunderstore/core/api_urls.py @@ -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), ), ]