Skip to content

Commit

Permalink
Added the system report
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Nader committed Aug 21, 2021
1 parent 95f3ba3 commit 0af416b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
5 changes: 3 additions & 2 deletions backend/banksystem/bank/urls.py
Original file line number Diff line number Diff line change
@@ -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'),
]
45 changes: 45 additions & 0 deletions backend/banksystem/bank/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

"""
Expand Down Expand Up @@ -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,
})
Binary file modified backend/banksystem/db.sqlite3
Binary file not shown.
3 changes: 2 additions & 1 deletion backend/banksystem/funds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://[email protected]/ahmednader42/bank.git

0 comments on commit 0af416b

Please sign in to comment.