37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
|
from api.commonForAllServices import get_base_url
|
||
|
from rest_framework.decorators import api_view, permission_classes
|
||
|
from rest_framework.permissions import IsAuthenticated
|
||
|
from django.http import JsonResponse
|
||
|
from django.views.decorators.csrf import csrf_exempt
|
||
|
import os
|
||
|
import requests
|
||
|
|
||
|
@api_view(['GET'])
|
||
|
@permission_classes([IsAuthenticated])
|
||
|
@csrf_exempt
|
||
|
def testCustomApi(request):
|
||
|
try:
|
||
|
headers = {
|
||
|
'gateway-key': os.getenv("GATEWAY_KEY"),
|
||
|
'Content-Type': 'application/json',
|
||
|
}
|
||
|
# Step 2: Fetch the shift using the shift API
|
||
|
test_address_url = f"{get_base_url('testService')}api/v1/testAddress/"
|
||
|
test_address_response = requests.get(test_address_url, headers=headers)
|
||
|
if test_address_response.status_code != 200:
|
||
|
return JsonResponse({'error': 'address not found'}, status=404)
|
||
|
testAddresses = test_address_response.json()
|
||
|
|
||
|
filtered_addresses = [address for address in testAddresses if address.get('city') == 'anand']
|
||
|
|
||
|
if not filtered_addresses:
|
||
|
return JsonResponse({'error': 'No addresses found in the specified city'}, status=404)
|
||
|
|
||
|
response_data = {
|
||
|
'address': testAddresses,
|
||
|
'anand address':filtered_addresses,
|
||
|
}
|
||
|
return JsonResponse(response_data, status=200)
|
||
|
|
||
|
except Exception as e:
|
||
|
return JsonResponse({'error': str(e)}, status=500)
|