From 408475f15985f6c97eb39a70a42c3df8f3071233 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Thu, 23 Jul 2026 21:42:39 -0400 Subject: [PATCH] Add videogame API and register ViewSets for scrobble relationships VideoGame was missing from the API router, causing HyperlinkedModelSerializer to fail when generating URLs for scrobble relationships. Changes: - Create videogames/api/ with serializers and views - Register VideoGameViewSet at /api/v1/videogames/ - Register VideoGameCollectionViewSet at /api/v1/videogame-collections/ - Register VideoGamePlatformViewSet at /api/v1/videogame-platforms/ --- vrobbler/apps/videogames/api/__init__.py | 0 vrobbler/apps/videogames/api/serializers.py | 20 ++++++++++++++++++++ vrobbler/apps/videogames/api/views.py | 21 +++++++++++++++++++++ vrobbler/urls.py | 8 ++++++++ 4 files changed, 49 insertions(+) create mode 100644 vrobbler/apps/videogames/api/__init__.py create mode 100644 vrobbler/apps/videogames/api/serializers.py create mode 100644 vrobbler/apps/videogames/api/views.py diff --git a/vrobbler/apps/videogames/api/__init__.py b/vrobbler/apps/videogames/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/vrobbler/apps/videogames/api/serializers.py b/vrobbler/apps/videogames/api/serializers.py new file mode 100644 index 0000000..965ed59 --- /dev/null +++ b/vrobbler/apps/videogames/api/serializers.py @@ -0,0 +1,20 @@ +from rest_framework import serializers +from videogames.models import VideoGame, VideoGameCollection, VideoGamePlatform + + +class VideoGameSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = VideoGame + fields = "__all__" + + +class VideoGameCollectionSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = VideoGameCollection + fields = "__all__" + + +class VideoGamePlatformSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = VideoGamePlatform + fields = "__all__" diff --git a/vrobbler/apps/videogames/api/views.py b/vrobbler/apps/videogames/api/views.py new file mode 100644 index 0000000..317c44a --- /dev/null +++ b/vrobbler/apps/videogames/api/views.py @@ -0,0 +1,21 @@ +from rest_framework import permissions, viewsets +from videogames.api import serializers +from videogames import models + + +class VideoGameViewSet(viewsets.ModelViewSet): + queryset = models.VideoGame.objects.all().order_by("-created") + serializer_class = serializers.VideoGameSerializer + permission_classes = [permissions.IsAuthenticated] + + +class VideoGameCollectionViewSet(viewsets.ModelViewSet): + queryset = models.VideoGameCollection.objects.all().order_by("-created") + serializer_class = serializers.VideoGameCollectionSerializer + permission_classes = [permissions.IsAuthenticated] + + +class VideoGamePlatformViewSet(viewsets.ModelViewSet): + queryset = models.VideoGamePlatform.objects.all().order_by("-created") + serializer_class = serializers.VideoGamePlatformSerializer + permission_classes = [permissions.IsAuthenticated] diff --git a/vrobbler/urls.py b/vrobbler/urls.py index 5fc8da7..5a34864 100644 --- a/vrobbler/urls.py +++ b/vrobbler/urls.py @@ -89,6 +89,11 @@ from vrobbler.apps.trails import urls as trails_urls from vrobbler.apps.trails.api.views import TrailViewSet from vrobbler.apps.trends import urls as trends_urls from vrobbler.apps.videogames import urls as videogame_urls +from vrobbler.apps.videogames.api.views import ( + VideoGameCollectionViewSet, + VideoGamePlatformViewSet, + VideoGameViewSet, +) from vrobbler.apps.videos import urls as video_urls from vrobbler.apps.videos.api.views import ( ChannelViewSet, @@ -151,6 +156,9 @@ router.register(r"puzzle-manufacturers", PuzzleManufacturerViewSet) router.register(r"puzzles", PuzzleViewSet) router.register(r"bricksets", BrickSetViewSet) router.register(r"lifeevents", LifeEventViewSet) +router.register(r"videogames", VideoGameViewSet) +router.register(r"videogame-collections", VideoGameCollectionViewSet) +router.register(r"videogame-platforms", VideoGamePlatformViewSet) router.register(r"birds", BirdViewSet) router.register(r"birding-locations", BirdingLocationViewSet)