From 92fc92ba4080a806bd3900d03e561b7f7b54e245 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 7 Feb 2020 00:12:00 +0100 Subject: [PATCH] Add note models in API --- apps/api/urls.py | 27 +++++++++---- apps/note/serializers.py | 83 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 apps/note/serializers.py diff --git a/apps/api/urls.py b/apps/api/urls.py index 97e4ebe7..cca07d80 100644 --- a/apps/api/urls.py +++ b/apps/api/urls.py @@ -7,11 +7,13 @@ from django.contrib.auth.models import User from rest_framework import routers, serializers, viewsets from member.serializers import ProfileViewSet, ClubViewSet, RoleViewSet, MembershipViewSet from activity.serializers import ActivityTypeViewSet, ActivityViewSet, GuestViewSet +from note.serializers import NoteViewSet, NoteClubViewSet, NoteUserViewSet, NoteSpecialViewSet, \ + TransactionViewSet, TransactionTemplateViewSet, MembershipTransactionViewSet class UserSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = User - fields = ['url', 'username', 'first_name', 'last_name', 'email', 'is_staff'] + fields = ('username', 'first_name', 'last_name', 'email', 'is_staff',) class UserViewSet(viewsets.ModelViewSet): queryset = User.objects.all() @@ -21,14 +23,23 @@ class UserViewSet(viewsets.ModelViewSet): router = routers.DefaultRouter() router.register(r'users', UserViewSet) -router.register(r'members/profiles', ProfileViewSet) -router.register(r'members/clubs', ClubViewSet) -router.register(r'members/roles', RoleViewSet) -router.register(r'members/memberships', MembershipViewSet) +router.register(r'members/profile', ProfileViewSet) +router.register(r'members/club', ClubViewSet) +router.register(r'members/role', RoleViewSet) +router.register(r'members/membership', MembershipViewSet) -router.register(r'activity/activity_types', ActivityTypeViewSet) -router.register(r'activity/activities', ActivityViewSet) -router.register(r'activity/guests', GuestViewSet) +router.register(r'activity/activity', ActivityViewSet) +router.register(r'activity/type', ActivityTypeViewSet) +router.register(r'activity/guest', GuestViewSet) + +router.register(r'note/note', NoteViewSet) +router.register(r'note/club', NoteClubViewSet) +router.register(r'note/user', NoteUserViewSet) +router.register(r'note/special', NoteSpecialViewSet) + +router.register(r'note/transaction', TransactionViewSet) +router.register(r'note/transaction/template', TransactionTemplateViewSet) +router.register(r'note/transaction/membership', MembershipTransactionViewSet) # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. diff --git a/apps/note/serializers.py b/apps/note/serializers.py new file mode 100644 index 00000000..39ce835a --- /dev/null +++ b/apps/note/serializers.py @@ -0,0 +1,83 @@ +# -*- mode: python; coding: utf-8 -*- +# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay +# SPDX-License-Identifier: GPL-3.0-or-later + +from .models.notes import Note, NoteClub, NoteSpecial, NoteUser +from .models.transactions import TransactionTemplate, Transaction, MembershipTransaction +from rest_framework import serializers, viewsets + +class NoteSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Note + fields = ('balance', 'is_active', 'display_image', 'created_at',) + + +class NoteViewSet(viewsets.ModelViewSet): + queryset = Note.objects.all() + serializer_class = NoteSerializer + + +class NoteClubSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = NoteClub + fields = ('balance', 'is_active', 'display_image', 'created_at', 'club',) + + +class NoteClubViewSet(viewsets.ModelViewSet): + queryset = NoteClub.objects.all() + serializer_class = NoteClubSerializer + + +class NoteSpecialSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = NoteSpecial + fields = ('balance', 'is_active', 'display_image', 'created_at', 'club', 'special_type',) + + +class NoteSpecialViewSet(viewsets.ModelViewSet): + queryset = NoteSpecial.objects.all() + serializer_class = NoteSpecialSerializer + + +class NoteUserSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = NoteUser + fields = ('balance', 'is_active', 'display_image', 'created_at', 'user',) + + +class NoteUserViewSet(viewsets.ModelViewSet): + queryset = NoteUser.objects.all() + serializer_class = NoteUserSerializer + + +class TransactionTemplateSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = TransactionTemplate + fields = '__all__' + + +class TransactionTemplateViewSet(viewsets.ModelViewSet): + queryset = TransactionTemplate.objects.all() + serializer_class = TransactionTemplateSerializer + + +class TransactionSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Transaction + fields = '__all__' + + +class TransactionViewSet(viewsets.ModelViewSet): + queryset = Transaction.objects.all() + serializer_class = TransactionSerializer + + +class MembershipTransactionSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = MembershipTransaction + fields = '__all__' + + +class MembershipTransactionViewSet(viewsets.ModelViewSet): + queryset = MembershipTransaction.objects.all() + serializer_class = MembershipTransactionSerializer