Fakultas Ilmu Komputer UI

Commit cd003520 authored by Dave Nathanael's avatar Dave Nathanael
Browse files

[GREEN] Implement age filter with status on export case data

parent a0c00ef7
Pipeline #47960 failed with stages
in 25 minutes and 17 seconds
from django.http import JsonResponse
from django.db.models import Max
from rest_framework import status
from rest_framework import status, serializers
from rest_framework.response import Response
from rest_framework.views import APIView
......@@ -95,13 +95,30 @@ class ExportInvestigationCaseView(APIView):
def get(self, request, format=None):
cases = InvestigationCase.objects.all()
query_is_male = self.request.query_params.get('is_male', None)
query_age = self.request.query_params.get('age', None)
query_min_age = self.request.query_params.get('min_age', None)
query_max_age = self.request.query_params.get('max_age', None)
query_district = self.request.query_params.get('district', None)
if query_is_male is not None:
cases = cases.filter(case_subject__is_male=(query_is_male.lower() == 'true'))
if query_age is not None:
cases = cases.filter(case_subject__age=int(query_age))
query_is_male = query_is_male.lower()
if query_is_male not in ['true', 'false']:
raise serializers.ValidationError(
'is_male query param must be either "true" or "false"')
cases = cases.filter(case_subject__is_male=(query_is_male == 'true'))
if (query_min_age is not None) and (query_max_age is not None):
try:
query_min_age = int(query_min_age)
except ValueError:
raise serializers.ValidationError('min_age query param must be an integer')
try:
query_max_age = int(query_max_age)
except ValueError:
raise serializers.ValidationError('min_age query param must be an integer')
cases = cases.filter(case_subject__age__range=(query_min_age, query_max_age))
if query_district is not None:
cases = cases.filter(case_subject__district=query_district)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment