From 9359aa760612dfbedf4a912ffe0511ad0503873d Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 29 Mar 2021 15:41:20 +0200 Subject: [PATCH] Add API views for participation app --- apps/api/urls.py | 4 ++ apps/participation/api/__init__.py | 2 + apps/participation/api/serializers.py | 56 +++++++++++++++++++++++++++ apps/participation/api/urls.py | 19 +++++++++ apps/participation/api/views.py | 48 +++++++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 apps/participation/api/__init__.py create mode 100644 apps/participation/api/serializers.py create mode 100644 apps/participation/api/urls.py create mode 100644 apps/participation/api/views.py diff --git a/apps/api/urls.py b/apps/api/urls.py index 410fa86..c196e80 100644 --- a/apps/api/urls.py +++ b/apps/api/urls.py @@ -16,6 +16,10 @@ if "logs" in settings.INSTALLED_APPS: from logs.api.urls import register_logs_urls register_logs_urls(router, "logs") +if "participation" in settings.INSTALLED_APPS: + from participation.api.urls import register_participation_urls + register_participation_urls(router, "participation") + app_name = 'api' # Wire up our API using automatic URL routing. diff --git a/apps/participation/api/__init__.py b/apps/participation/api/__init__.py new file mode 100644 index 0000000..4e945ad --- /dev/null +++ b/apps/participation/api/__init__.py @@ -0,0 +1,2 @@ +# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay +# SPDX-License-Identifier: GPL-3.0-or-later diff --git a/apps/participation/api/serializers.py b/apps/participation/api/serializers.py new file mode 100644 index 0000000..f82b31f --- /dev/null +++ b/apps/participation/api/serializers.py @@ -0,0 +1,56 @@ +# Copyright (C) 2020 by Animath +# SPDX-License-Identifier: GPL-3.0-or-later + +from rest_framework import serializers + +from ..models import Note, Participation, Passage, Pool, Solution, Synthesis, Team, Tournament + + +class NoteSerializer(serializers.ModelSerializer): + class Meta: + model = Note + fields = '__all__' + + +class ParticipationSerializer(serializers.ModelSerializer): + class Meta: + model = Participation + fields = '__all__' + + +class PassageSerializer(serializers.ModelSerializer): + class Meta: + model = Passage + fields = '__all__' + + +class PoolSerializer(serializers.ModelSerializer): + class Meta: + model = Pool + fields = '__all__' + + +class SolutionSerializer(serializers.ModelSerializer): + class Meta: + model = Solution + fields = '__all__' + + +class SynthesisSerializer(serializers.ModelSerializer): + class Meta: + model = Synthesis + fields = '__all__' + + +class TeamSerializer(serializers.ModelSerializer): + class Meta: + model = Team + fields = '__all__' + + +class TournamentSerializer(serializers.ModelSerializer): + teams = serializers.ListSerializer() + + class Meta: + model = Tournament + fields = '__all__' diff --git a/apps/participation/api/urls.py b/apps/participation/api/urls.py new file mode 100644 index 0000000..fd27494 --- /dev/null +++ b/apps/participation/api/urls.py @@ -0,0 +1,19 @@ +# Copyright (C) 2020 by Animath +# SPDX-License-Identifier: GPL-3.0-or-later + +from .views import NoteViewSet, ParticipationViewSet, PassageViewSet, PoolViewSet, \ + SolutionViewSet, SynthesisViewSet, TeamViewSet, TournamentViewSet + + +def register_participation_urls(router, path): + """ + Configure router for participation REST API. + """ + router.register(path + "/note", NoteViewSet) + router.register(path + "/participation", ParticipationViewSet) + router.register(path + "/passage", PassageViewSet) + router.register(path + "/pool", PoolViewSet) + router.register(path + "/solution", SolutionViewSet) + router.register(path + "/synthesis", SynthesisViewSet) + router.register(path + "/team", TeamViewSet) + router.register(path + "/tournament", TournamentViewSet) diff --git a/apps/participation/api/views.py b/apps/participation/api/views.py new file mode 100644 index 0000000..33b8aa9 --- /dev/null +++ b/apps/participation/api/views.py @@ -0,0 +1,48 @@ +# Copyright (C) 2020 by Animath +# SPDX-License-Identifier: GPL-3.0-or-later + +from rest_framework.viewsets import ModelViewSet + +from .serializers import NoteSerializer, ParticipationSerializer, PassageSerializer, PoolSerializer, \ + SolutionSerializer, SynthesisSerializer, TeamSerializer, TournamentSerializer +from ..models import Note, Participation, Passage, Pool, Solution, Synthesis, Team, Tournament + + +class NoteViewSet(ModelViewSet): + queryset = Note.objects.all() + serializer_class = NoteSerializer + + +class ParticipationViewSet(ModelViewSet): + queryset = Participation.objects.all() + serializer_class = ParticipationSerializer + + +class PassageViewSet(ModelViewSet): + queryset = Passage.objects.all() + serializer_class = PassageSerializer + + +class PoolViewSet(ModelViewSet): + queryset = Pool.objects.all() + serializer_class = PoolSerializer + + +class SolutionViewSet(ModelViewSet): + queryset = Solution.objects.all() + serializer_class = SolutionSerializer + + +class SynthesisViewSet(ModelViewSet): + queryset = Synthesis.objects.all() + serializer_class = SynthesisSerializer + + +class TeamViewSet(ModelViewSet): + queryset = Team.objects.all() + serializer_class = TeamSerializer + + +class TournamentViewSet(ModelViewSet): + queryset = Tournament.objects.all() + serializer_class = TournamentSerializer