diff --git a/server/server/api/serializers.py b/server/server/api/serializers.py index e6d7f61..187fb57 100644 --- a/server/server/api/serializers.py +++ b/server/server/api/serializers.py @@ -1,7 +1,27 @@ from django.contrib.auth.models import User, Group from rest_framework import serializers +from server.api import models class UserSerializer(serializers.ModelSerializer): class Meta: model = User fields = ['username', 'email', 'groups'] + +class TransactionSerializer(serializers.ModelSerializer): + class Meta: + model = models.Transaction + fields = '__all__' + +class StackSerializer(serializers.ModelSerializer): + transactions = TransactionSerializer(many=True, read_only=True) + + class Meta: + model = models.Stack + fields = '__all__' + +class AccountSerializer(serializers.ModelSerializer): + stacks = StackSerializer(many=True, read_only=True) + + class Meta: + model = models.Account + fields = '__all__' diff --git a/server/server/api/views.py b/server/server/api/views.py index 524cfa2..b64dca7 100644 --- a/server/server/api/views.py +++ b/server/server/api/views.py @@ -1,9 +1,24 @@ from django.contrib.auth.models import User, Group from rest_framework import viewsets from rest_framework import permissions -from server.api import serializers +from server.api import serializers, models class UserViewSet(viewsets.ModelViewSet): queryset = User.objects.all().order_by('-date_joined') serializer_class = serializers.UserSerializer permission_classes = [permissions.IsAuthenticated] + +class AccountViewSet(viewsets.ModelViewSet): + queryset = models.Account.objects.all() + serializer_class = serializers.AccountSerializer + permission_classes = [permissions.IsAuthenticated] + +class StackViewSet(viewsets.ModelViewSet): + queryset = models.Stack.objects.all() + serializer_class = serializers.StackSerializer + permission_classes = [permissions.IsAuthenticated] + +class TransactionViewSet(viewsets.ModelViewSet): + queryset = models.Transaction.objects.all() + serializer_class = serializers.TransactionSerializer + permission_classes = [permissions.IsAuthenticated] diff --git a/server/server/urls.py b/server/server/urls.py index f4f2c34..764d4b5 100644 --- a/server/server/urls.py +++ b/server/server/urls.py @@ -6,6 +6,9 @@ from .api import views router = routers.DefaultRouter() router.register(r'users', views.UserViewSet) +router.register(r'accounts', views.AccountViewSet) +router.register(r'stacks', views.StackViewSet) +router.register(r'transactions', views.TransactionViewSet) urlpatterns = [ path('', include(router.urls)),