diff --git a/backend/banksystem/bank/urls.py b/backend/banksystem/bank/urls.py index 1dae7ac..8f4c266 100644 --- a/backend/banksystem/bank/urls.py +++ b/backend/banksystem/bank/urls.py @@ -1,7 +1,8 @@ from django.urls import path -from .views import get_total_amount +from .views import get_total_amount, system_report urlpatterns = [ - path('bank-balance/', get_total_amount, name='get_total_amount') + path('bank-balance/', get_total_amount, name='get_total_amount'), + path('system-report/', system_report, name='system_report'), ] diff --git a/backend/banksystem/bank/views.py b/backend/banksystem/bank/views.py index 44732b7..c23325d 100644 --- a/backend/banksystem/bank/views.py +++ b/backend/banksystem/bank/views.py @@ -6,6 +6,9 @@ from rest_framework.exceptions import PermissionDenied from users.models import User +from funds.models import Fund +from loans.models import Loan + # Create your views here. """ @@ -45,3 +48,45 @@ def get_total_amount(request): serializer = BankSerializer(bank) # Return the total amount for the balance return Response(serializer.data) + + +""" + Make sure only a Banker can view the total_amount of balance in the Bank. +""" + + +@api_view(['GET']) +def system_report(request): + # Make sure the user is a Banker. + if request.user.user_type != User.BANKER: + raise PermissionDenied() + + pending_funds = Fund.objects.all().filter(status=Fund.PENDING).count() + approved_funds = Fund.objects.all().filter(status=Fund.APPROVED).count() + denied_funds = Fund.objects.all().filter(status=Fund.DENIED).count() + + pending_loans = Loan.objects.all().filter(status=Loan.PENDING).count() + approved_loans = Loan.objects.all().filter(status=Loan.APPROVED).count() + denied_loans = Loan.objects.all().filter(status=Loan.DENIED).count() + + number_of_bankers = User.objects.all().filter(user_type=User.BANKER).count() + number_of_customers = User.objects.all().filter(user_type=User.CUSTOMER).count() + number_of_funders = User.objects.all().filter(user_type=User.FUNDER).count() + + # Return the total amount for the balance + return Response({ + "total_number_of_funds": pending_funds + approved_funds + denied_funds, + "pending_funds": pending_funds, + "approved_funds": approved_funds, + "denied_funds": denied_funds, + + "total_number_of_loans": pending_loans + approved_loans + denied_loans, + "pending_loans": pending_loans, + "approved_loans": approved_loans, + "denied_loans": denied_loans, + + "total_number_of_users": number_of_funders + number_of_customers + number_of_bankers, + "bankers": number_of_bankers, + "customer": number_of_customers, + "funders": number_of_funders, + }) diff --git a/backend/banksystem/db.sqlite3 b/backend/banksystem/db.sqlite3 index fd03bef..0e3bdb4 100644 Binary files a/backend/banksystem/db.sqlite3 and b/backend/banksystem/db.sqlite3 differ diff --git a/backend/banksystem/funds/views.py b/backend/banksystem/funds/views.py index 9d1c059..42709c8 100644 --- a/backend/banksystem/funds/views.py +++ b/backend/banksystem/funds/views.py @@ -195,4 +195,5 @@ def view_pending_funds(request): queryset = Fund.objects.all().filter(status=Fund.PENDING) serializer = FundSerializer(queryset, many=True) return Response(serializer.data) -# git remote add origin https://[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]@github.com/ahmednader42/bank-frontend.git + +# git remote add origin https://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@github.com/ahmednader42/bank.git