From 0af416bc5479920ffb43806336110150be9d59d3 Mon Sep 17 00:00:00 2001 From: Ahmed Nader Date: Sat, 21 Aug 2021 23:08:40 +0200 Subject: [PATCH] Added the system report --- backend/banksystem/bank/urls.py | 5 ++-- backend/banksystem/bank/views.py | 45 ++++++++++++++++++++++++++++++ backend/banksystem/db.sqlite3 | Bin 303104 -> 303104 bytes backend/banksystem/funds/views.py | 3 +- 4 files changed, 50 insertions(+), 3 deletions(-) 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 fd03bef9ffca80ffe2cfb101e72e2ef3a277e51f..0e3bdb49e1c9378a363bfcb09d4a3fa3324e40ed 100644 GIT binary patch delta 6460 zcmb7I3ve69c|P17@gN=xJt#_+WYaQbiKGba-uoaw2$BFu@cjS@!j?(A2@o%mAVG2@ zL$anFx1BhymG+vnP1TN_Hd8xxtFe%_GmbrVCT%ipr6dzKwr8qZok&hScG5{wPdd|f z_rPaOD=u#Mad+{5yZ_$)`|ZED@cP~hukU^K9!K2-MNt9#r+5h~yXXSCRao%a=}{ zG&nE6c-n0QjSRyZF5j^1yZS$;>)?ZR;5`cb68sE&2=0LQz?XJ^uI{<;p5wBu@JteW zl%)4#oT2w&4AXltj?;TE4$@AHJv6}BNjoq;MB6b+v<)Mqtr%PBdW_AqrH(Ne?1ywb zsAHp!2Xt(Bs(7tvV4;lxA8vT}Ue$TU@Lf>B^m}c@frHk4#2DyA$2yVp-U?U>d;vTI zo(4~WbKp974ZH}J@g%H(`yx*zyJ2XF%cxWGwpOn(`F3BC^A z1wQ~qkO6V<1PFmqM-@Ms_=@2~_32j(=NuI>yd$GyTE|%(Q#vLIf`pE79b-C1b&TjZ zqvN!WPY`T4tK;K3KBi+>$0;2{1nrXqtrK;PU7dC z0kRjnHU}cnCvG2PpOramSRbH~l-D~yK+5YKH;}E+YBFl3Ci(%+HfFom`l0nT>oe9# z>%sbW>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jiy?x#a@3*07{>g({Ts&pDPNQbj;DlD+X>=GhIH2`4((*&=r_i!0 zzJ^X%Up#|$qly4LyL<+fqXrDEH_pHt6+URS-UrVrylbr*0b12(;5h%|(+JyFPM6a@ z4qH6%9A?}V=pWuFc71ACYnMi|*3xOT6ScV4I7f@l-^@hgvDWT|bb$jG5qq4n(jtni zjE>Jvwhj|YO#{bMjO_+d_J+)CocIfJW@Bb)!V|H&jhEy*4?yMxZ36TIEb zQ&^jlnwy!OoJdbIJiEh7Fy4n5(8TbDQLcvxbb`G|j;d@t2Nnw_|k zhkIMzg+9rID!C%+h6nv73#xP!QGc@oEfEWnST2SN+-Cm&;Xp+O)X2ID-p+ptXD|QX Xt-X<1AIQ412B|J5g(#M1!>{}|dBewF 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