From 530243ed750bb9c056dfab8e70997475aa16945d Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Nov 2023 16:23:44 -0500 Subject: [PATCH] Exposing conditions. --- api_v2/serializers/__init__.py | 4 +++- api_v2/serializers/condition.py | 14 ++++++++++++++ api_v2/views/__init__.py | 4 +++- api_v2/views/condition.py | 16 ++++++++++++++++ server/urls.py | 9 +++++---- 5 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 api_v2/serializers/condition.py create mode 100644 api_v2/views/condition.py diff --git a/api_v2/serializers/__init__.py b/api_v2/serializers/__init__.py index fe0a218e..ec1addde 100644 --- a/api_v2/serializers/__init__.py +++ b/api_v2/serializers/__init__.py @@ -26,4 +26,6 @@ from .language import LanguageSerializer -from .alignment import AlignmentSerializer \ No newline at end of file +from .alignment import AlignmentSerializer + +from .condition import ConditionSerializer \ No newline at end of file diff --git a/api_v2/serializers/condition.py b/api_v2/serializers/condition.py new file mode 100644 index 00000000..70c95ebe --- /dev/null +++ b/api_v2/serializers/condition.py @@ -0,0 +1,14 @@ +"""Serializer for the Condition model.""" + +from rest_framework import serializers + +from api_v2 import models + +from .abstracts import GameContentSerializer + +class ConditionSerializer(GameContentSerializer): + key = serializers.ReadOnlyField() + + class Meta: + model = models.Condition + fields = '__all__' diff --git a/api_v2/views/__init__.py b/api_v2/views/__init__.py index b206f400..c924d1be 100644 --- a/api_v2/views/__init__.py +++ b/api_v2/views/__init__.py @@ -23,4 +23,6 @@ from .language import LanguageFilterSet, LanguageViewSet -from .alignment import AlignmentFilterSet, AlignmentViewSet \ No newline at end of file +from .alignment import AlignmentFilterSet, AlignmentViewSet + +from .condition import ConditionViewSet \ No newline at end of file diff --git a/api_v2/views/condition.py b/api_v2/views/condition.py new file mode 100644 index 00000000..e76e2df2 --- /dev/null +++ b/api_v2/views/condition.py @@ -0,0 +1,16 @@ +from rest_framework import viewsets + +from api_v2 import models +from api_v2 import serializers + + +class ConditionViewSet(viewsets.ReadOnlyModelViewSet): + """ + list: API endpoint for returning a list of conditions. + retrieve: API endpoint for returning a particular condition. + """ + queryset = models.Condition.objects.all().order_by('pk') + serializer_class = serializers.ConditionSerializer + + + diff --git a/server/urls.py b/server/urls.py index 9db6d9e2..a643319b 100644 --- a/server/urls.py +++ b/server/urls.py @@ -64,10 +64,11 @@ router_v2.register(r'feats',views_v2.FeatViewSet) router_v2.register(r'races',views_v2.RaceViewSet) router_v2.register(r'creatures',views_v2.CreatureViewSet) - router_v2.register(r'creaturetype',views_v2.CreatureTypeViewSet) - router_v2.register(r'damagetype',views_v2.DamageTypeViewSet) - router_v2.register(r'language',views_v2.LanguageViewSet) - router_v2.register(r'alignment',views_v2.AlignmentViewSet) + router_v2.register(r'creaturetypes',views_v2.CreatureTypeViewSet) + router_v2.register(r'damagetypes',views_v2.DamageTypeViewSet) + router_v2.register(r'languages',views_v2.LanguageViewSet) + router_v2.register(r'alignments',views_v2.AlignmentViewSet) + router_v2.register(r'conditions',views_v2.ConditionViewSet) # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API.