|
|
|
@ -81,8 +81,30 @@ class CountryView(APIView): |
|
|
|
permission_classes = [AllowAny] |
|
|
|
|
|
|
|
@swagger_auto_schema( |
|
|
|
operation_description="List of optimized countries with codes and names", |
|
|
|
responses={200: openapi.Response(description="Countries list")} |
|
|
|
operation_description="List of optimized countries with codes and names. Supports locale translation based on request header (Accept-Language).", |
|
|
|
responses={ |
|
|
|
200: openapi.Response( |
|
|
|
description="List of countries sorted alphabetically by name", |
|
|
|
schema=openapi.Schema( |
|
|
|
type=openapi.TYPE_ARRAY, |
|
|
|
items=openapi.Schema( |
|
|
|
type=openapi.TYPE_OBJECT, |
|
|
|
properties={ |
|
|
|
'code': openapi.Schema(type=openapi.TYPE_STRING, description="ISO 3166-1 alpha-2 country code", example="IR"), |
|
|
|
'name': openapi.Schema(type=openapi.TYPE_STRING, description="Localized country name", example="Iran (Islamic Republic of)") |
|
|
|
} |
|
|
|
) |
|
|
|
), |
|
|
|
examples={ |
|
|
|
"application/json": [ |
|
|
|
{"code": "CN", "name": "China"}, |
|
|
|
{"code": "IR", "name": "Iran (Islamic Republic of)"}, |
|
|
|
{"code": "RU", "name": "Russian Federation (the)"}, |
|
|
|
{"code": "TR", "name": "Türkiye"} |
|
|
|
] |
|
|
|
} |
|
|
|
) |
|
|
|
} |
|
|
|
) |
|
|
|
def get(self, request): |
|
|
|
try: |
|
|
|
@ -108,19 +130,48 @@ class CityListView(APIView): |
|
|
|
permission_classes = [AllowAny] |
|
|
|
|
|
|
|
@swagger_auto_schema( |
|
|
|
operation_description="List of cities based on country code", |
|
|
|
operation_description="List of cities filtered by country code. Supports locale translation based on request header (Accept-Language).", |
|
|
|
manual_parameters=[ |
|
|
|
openapi.Parameter( |
|
|
|
name='country_code', |
|
|
|
in_=openapi.IN_QUERY, |
|
|
|
description='Two-letter country code (e.g. IR, CN, TR)', |
|
|
|
type=openapi.TYPE_STRING, |
|
|
|
required=True |
|
|
|
required=True, |
|
|
|
example="IR" |
|
|
|
) |
|
|
|
], |
|
|
|
responses={ |
|
|
|
200: openapi.Response(description="List of city names"), |
|
|
|
400: openapi.Response(description="Country code is required or invalid") |
|
|
|
200: openapi.Response( |
|
|
|
description="List of city names sorted alphabetically", |
|
|
|
schema=openapi.Schema( |
|
|
|
type=openapi.TYPE_ARRAY, |
|
|
|
items=openapi.Schema(type=openapi.TYPE_STRING, description="City name", example="Abadan") |
|
|
|
), |
|
|
|
examples={ |
|
|
|
"application/json": [ |
|
|
|
"Abadan", |
|
|
|
"Abadeh", |
|
|
|
"Abhar", |
|
|
|
"Ahvaz", |
|
|
|
"Tehran" |
|
|
|
] |
|
|
|
} |
|
|
|
), |
|
|
|
400: openapi.Response( |
|
|
|
description="Bad Request - country_code missing or invalid", |
|
|
|
schema=openapi.Schema( |
|
|
|
type=openapi.TYPE_OBJECT, |
|
|
|
properties={ |
|
|
|
'error': openapi.Schema(type=openapi.TYPE_STRING, description="Error message description", example="country_code query parameter is required") |
|
|
|
} |
|
|
|
), |
|
|
|
examples={ |
|
|
|
"application/json": { |
|
|
|
"error": "country_code query parameter is required" |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
} |
|
|
|
) |
|
|
|
def get(self, request): |
|
|
|
|