|
|
@@ -1,6 +1,9 @@
|
|
|
+import coreschema
|
|
|
from django.http import Http404
|
|
|
from rest_framework import viewsets, mixins
|
|
|
from rest_framework import permissions
|
|
|
+import coreapi
|
|
|
+from rest_framework.schemas import AutoSchema
|
|
|
from rest_framework.response import Response
|
|
|
from .mixins import TransactionsMixin
|
|
|
from django.db.models import (Sum, F, Case, FloatField,
|
|
|
@@ -13,6 +16,43 @@ from django.contrib.auth import get_user_model
|
|
|
User = get_user_model()
|
|
|
|
|
|
|
|
|
+class CustomSchema(AutoSchema):
|
|
|
+ """
|
|
|
+ Custom Scheme for documentation
|
|
|
+ """
|
|
|
+
|
|
|
+ def __init__(self, manual_fields=None):
|
|
|
+ """
|
|
|
+ Parameters:
|
|
|
+
|
|
|
+ Add Manual Fields
|
|
|
+ """
|
|
|
+ super(AutoSchema, self).__init__()
|
|
|
+ self._manual_fields = [
|
|
|
+ coreapi.Field(
|
|
|
+ name='date_from',
|
|
|
+ location='query',
|
|
|
+ required=False,
|
|
|
+ schema=coreschema.Integer(title='date_from', description='Date Format: `YYYY-MM-DD`')
|
|
|
+ ),
|
|
|
+ coreapi.Field(
|
|
|
+ name='date_to',
|
|
|
+ location='query',
|
|
|
+ required=False,
|
|
|
+ schema=coreschema.Integer(title='date_from', description='Date Format: `YYYY-MM-DD`')
|
|
|
+ )
|
|
|
+ ]
|
|
|
+
|
|
|
+ def get_path_fields(self, path, method):
|
|
|
+ field = coreapi.Field(
|
|
|
+ name='user_id',
|
|
|
+ location='path',
|
|
|
+ required=True,
|
|
|
+ schema=coreschema.Integer(title='user_id', description='A unique integer value identifying this user.')
|
|
|
+ )
|
|
|
+ return [field]
|
|
|
+
|
|
|
+
|
|
|
class TransactionViewSet(mixins.CreateModelMixin,
|
|
|
viewsets.GenericViewSet):
|
|
|
"""
|
|
|
@@ -71,6 +111,7 @@ class AccountBalanceViewSet(viewsets.ViewSet, TransactionsMixin):
|
|
|
"""
|
|
|
permission_classes = []
|
|
|
lookup_field = 'user_id'
|
|
|
+ schema = CustomSchema()
|
|
|
|
|
|
def retrieve(self, request, format=None, user_id=None, *args, **kwargs):
|
|
|
try:
|
|
|
@@ -104,6 +145,7 @@ class CashflowViewSet(viewsets.ViewSet, TransactionsMixin):
|
|
|
/api/transactions/cashflow/1/?date_from=2020-01-10
|
|
|
|
|
|
"""
|
|
|
+ schema = CustomSchema()
|
|
|
permission_classes = []
|
|
|
lookup_field = 'user_id'
|
|
|
|