QRTR-2 Finalized v1 of api setup for storage and access.
This commit is contained in:
parent
a8acfd05ba
commit
033a3f9946
Binary file not shown.
Binary file not shown.
@ -1,3 +1,2 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
@ -1,15 +1,49 @@
|
||||
from django.contrib.auth.models import Group
|
||||
from django.contrib.auth import get_user_model
|
||||
from rest_framework import serializers
|
||||
from qrtr_account.models import Account, Bank, Institution, Transaction
|
||||
from connection.models import Connection
|
||||
|
||||
|
||||
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = ['url', 'username', 'email', 'groups']
|
||||
fields = ['url', 'username', 'email', 'groups', 'owned_accounts',
|
||||
'admin_accounts', 'view_accounts']
|
||||
|
||||
|
||||
class GroupSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Group
|
||||
fields = ['url', 'name']
|
||||
|
||||
|
||||
class AccountSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Account
|
||||
fields = ['url','owner', 'name', 'admin_users', 'view_users']
|
||||
|
||||
|
||||
class BankSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Bank
|
||||
fields = ['url','qrtr_account', 'connection', 'institution', 'nickname',
|
||||
'balance', 'ac_type', 'ac_subtype']
|
||||
|
||||
|
||||
class InstitutionSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Institution
|
||||
fields = ['url','name']
|
||||
|
||||
|
||||
class TransactionSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Transaction
|
||||
fields = ['url', 'datetime', 'Bank', 'details']
|
||||
|
||||
|
||||
class ConnectionSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Connection
|
||||
fields = ['url', 'name']
|
||||
@ -1,3 +1,6 @@
|
||||
from django.contrib import admin
|
||||
from .models import Connection
|
||||
|
||||
# Register your models here.
|
||||
@admin.register(Connection)
|
||||
class ConnectionAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
@ -1,3 +1,11 @@
|
||||
from django.db import models
|
||||
import jsonfield
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class Connection(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
connection_path = models.CharField(max_length=255)
|
||||
credentials = jsonfield.JSONField()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name}"
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -46,6 +46,9 @@ INSTALLED_APPS = [
|
||||
'rest_auth.registration',
|
||||
'api',
|
||||
'user',
|
||||
'connection',
|
||||
'qrtr_account',
|
||||
'corsheaders',
|
||||
]
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
||||
@ -54,6 +57,8 @@ SITE_ID = 1
|
||||
|
||||
|
||||
MIDDLEWARE = [
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
@ -63,6 +68,11 @@ MIDDLEWARE = [
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
CORS_ORIGIN_WHITELIST = [
|
||||
'http://localhost:3000',
|
||||
'https://localhost:3000'
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'core.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
|
||||
15
core/urls.py
15
core/urls.py
@ -16,11 +16,24 @@ Including another URLconf
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
from rest_framework import routers
|
||||
from user.views import UserViewSet, GroupViewSet
|
||||
from user.views import (UserViewSet,
|
||||
GroupViewSet,
|
||||
)
|
||||
from qrtr_account.views import (AccountViewSet,
|
||||
BankViewSet,
|
||||
InstitutionViewSet,
|
||||
TransactionViewSet,
|
||||
ConnectionViewSet)
|
||||
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'users', UserViewSet)
|
||||
router.register(r'groups', GroupViewSet)
|
||||
router.register(r'accounts',AccountViewSet)
|
||||
router.register(r'banks',BankViewSet)
|
||||
router.register(r'institutions',InstitutionViewSet)
|
||||
router.register(r'transactions',TransactionViewSet)
|
||||
router.register(r'connections',ConnectionViewSet)
|
||||
|
||||
# Wire up our API using automatic URL routing.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
|
||||
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
@ -1,21 +1,48 @@
|
||||
from django.db import models
|
||||
from user.models import User
|
||||
import jsonfield
|
||||
|
||||
|
||||
class Account(models.Model):
|
||||
owner = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
admin_users = models.ManyToManyField(User, related_name="admins")
|
||||
view_users = models.ManyToManyField(User, related_name="viewer")
|
||||
owner = models.ForeignKey(User, on_delete=models.CASCADE,
|
||||
related_name="owned_accounts")
|
||||
admin_users = models.ManyToManyField(User, related_name="admin_accounts",
|
||||
blank=True)
|
||||
view_users = models.ManyToManyField(User, related_name="view_accounts",
|
||||
blank=True)
|
||||
name = models.CharField(max_length=250)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.owner}"
|
||||
|
||||
class InstitutionAccount(models.Model):
|
||||
|
||||
class Institution(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name}"
|
||||
|
||||
|
||||
class Bank(models.Model):
|
||||
qrtr_account = models.ForeignKey(Account, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=250)
|
||||
id = models.CharField(max_length=150)
|
||||
balance = models.DecimalField()
|
||||
ac_type = models.CharField()
|
||||
ac_subtype = models.CharField()
|
||||
connection = models.ForeignKey('connection.Connection',
|
||||
on_delete=models.CASCADE)
|
||||
institution = models.ForeignKey(Institution, on_delete=models.CASCADE,
|
||||
related_name="banks")
|
||||
nickname = models.CharField(max_length=250)
|
||||
balance = models.DecimalField(decimal_places=3, max_digits=100)
|
||||
ac_type = models.CharField(max_length=250, blank=True)
|
||||
ac_subtype = models.CharField(max_length=250, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.nickname}"
|
||||
|
||||
|
||||
class Transaction(models.Model):
|
||||
pass
|
||||
datetime = models.DateTimeField()
|
||||
Bank = models.ForeignKey(Bank, on_delete=models.CASCADE,
|
||||
related_name='transactions')
|
||||
details = jsonfield.JSONField()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.Bank} - {self.datetime}"
|
||||
|
||||
@ -1,3 +1,39 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework import viewsets
|
||||
from .models import Account, Bank, Institution, Transaction
|
||||
from connection.models import Connection
|
||||
from api.serializers import (AccountSerializer,
|
||||
BankSerializer,
|
||||
InstitutionSerializer,
|
||||
TransactionSerializer,
|
||||
ConnectionSerializer)
|
||||
|
||||
# Create your views here.
|
||||
|
||||
class AccountViewSet(viewsets.ModelViewSet):
|
||||
"""API endpoint that allows accounts to be viewed or edited
|
||||
"""
|
||||
queryset = Account.objects.all()
|
||||
serializer_class = AccountSerializer
|
||||
|
||||
|
||||
class BankViewSet(viewsets.ModelViewSet):
|
||||
"""API endpoint that allows Banks to be viewed or edited
|
||||
"""
|
||||
queryset = Bank.objects.all()
|
||||
serializer_class = BankSerializer
|
||||
|
||||
class InstitutionViewSet(viewsets.ModelViewSet):
|
||||
"""API endpoint that allows Banks to be viewed or edited
|
||||
"""
|
||||
queryset = Institution.objects.all()
|
||||
serializer_class = InstitutionSerializer
|
||||
|
||||
class TransactionViewSet(viewsets.ModelViewSet):
|
||||
"""API endpoint that allows Banks to be viewed or edited
|
||||
"""
|
||||
queryset = Transaction.objects.all()
|
||||
serializer_class = TransactionSerializer
|
||||
|
||||
class ConnectionViewSet(viewsets.ModelViewSet):
|
||||
queryset = Connection.objects.all()
|
||||
serializer_class = ConnectionSerializer
|
||||
Loading…
Reference in New Issue
Block a user