Merge branch 'main' of github.com:dank-inc/cash-stacks into main
This commit is contained in:
commit
c66e815810
|
@ -60,5 +60,6 @@ type Transaction = {
|
||||||
stack_id: string
|
stack_id: string
|
||||||
amount: integer // cents
|
amount: integer // cents
|
||||||
details: string
|
details: string
|
||||||
|
created_at: UTC datetime ie: 2021-04-15T00:06:21.852620Z
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
@ -28,3 +29,4 @@ class Transaction(models.Model):
|
||||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||||
details = models.TextField()
|
details = models.TextField()
|
||||||
amount = models.DecimalField(max_digits=12, decimal_places=2)
|
amount = models.DecimalField(max_digits=12, decimal_places=2)
|
||||||
|
created_at = models.DateTimeField(default=timezone.now)
|
||||||
|
|
|
@ -1,7 +1,27 @@
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from server.api import models
|
||||||
|
|
||||||
class UserSerializer(serializers.ModelSerializer):
|
class UserSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ['username', 'email', 'groups']
|
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__'
|
||||||
|
|
|
@ -1,9 +1,24 @@
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from rest_framework import permissions
|
from rest_framework import permissions
|
||||||
from server.api import serializers
|
from server.api import serializers, models
|
||||||
|
|
||||||
class UserViewSet(viewsets.ModelViewSet):
|
class UserViewSet(viewsets.ModelViewSet):
|
||||||
queryset = User.objects.all().order_by('-date_joined')
|
queryset = User.objects.all().order_by('-date_joined')
|
||||||
serializer_class = serializers.UserSerializer
|
serializer_class = serializers.UserSerializer
|
||||||
permission_classes = [permissions.IsAuthenticated]
|
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]
|
||||||
|
|
|
@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.1/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
@ -23,9 +24,20 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
SECRET_KEY = 'ayr0nbsni^%h!xbeplx_v#b^cuj^adjg2*z7t@+ht7c=7*1u$e'
|
SECRET_KEY = 'ayr0nbsni^%h!xbeplx_v#b^cuj^adjg2*z7t@+ht7c=7*1u$e'
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG_ENV = os.environ.get('DEBUG', False)
|
||||||
|
DEBUG = DEBUG_ENV or False
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['server']
|
PRODUCTION_HOST = 'example.com'
|
||||||
|
|
||||||
|
# production hosts
|
||||||
|
ALLOWED_HOSTS = [
|
||||||
|
'api.' + PRODUCTION_HOST,
|
||||||
|
]
|
||||||
|
|
||||||
|
if DEBUG:
|
||||||
|
ALLOWED_HOSTS += [
|
||||||
|
'*',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
|
@ -6,6 +6,9 @@ from .api import views
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
router.register(r'users', views.UserViewSet)
|
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 = [
|
urlpatterns = [
|
||||||
path('', include(router.urls)),
|
path('', include(router.urls)),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user