Add snapshot, account and category endpoints

This commit is contained in:
Edgar P. Burkhart 2023-04-14 15:42:49 +02:00
parent 887d2074dc
commit cba2358c0b
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
2 changed files with 26 additions and 2 deletions

View File

@ -3,5 +3,8 @@ from django.urls import path
from . import views
urlpatterns = [
path("transactions", views.TransactionListView.as_view(), name="index"),
path("transactions", views.TransactionListView.as_view(), name="transactions"),
path("categories", views.CategoryListView.as_view(), name="categories"),
path("accounts", views.AccountListView.as_view(), name="accounts"),
path("snapshots", views.SnapshotListView.as_view(), name="snapshots"),
]

View File

@ -2,7 +2,7 @@ from django.http import JsonResponse
from django.views import View
from django.views.generic.list import MultipleObjectMixin
from main.models import Transaction
from main.models import Account, Category, Snapshot, Transaction
from main.views import UserMixin
@ -11,3 +11,24 @@ class TransactionListView(UserMixin, MultipleObjectMixin, View):
def get(self, request, *args, **kwargs):
return JsonResponse({"transactions": list(self.get_queryset().values())})
class CategoryListView(UserMixin, MultipleObjectMixin, View):
model = Category
def get(self, request, *args, **kwargs):
return JsonResponse({"categories": list(self.get_queryset().values())})
class AccountListView(UserMixin, MultipleObjectMixin, View):
model = Account
def get(self, request, *args, **kwargs):
return JsonResponse({"accounts": list(self.get_queryset().values())})
class SnapshotListView(UserMixin, MultipleObjectMixin, View):
model = Snapshot
def get(self, request, *args, **kwargs):
return JsonResponse({"snapshots": list(self.get_queryset().values())})