Spaces:
Sleeping
Sleeping
unknown commited on
Commit ·
fa66fbc
1
Parent(s): 047c991
feat: add endpoint get all visa photo metadata
Browse files- app/util/db_utils.py +23 -0
- server.py +14 -0
app/util/db_utils.py
CHANGED
|
@@ -69,6 +69,29 @@ class DBManager:
|
|
| 69 |
return None
|
| 70 |
|
| 71 |
# --- NEW METHOD ADDED ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
def get_destination_country(self, application_id: int) -> str | None:
|
| 73 |
"""
|
| 74 |
Gets the official destination country name for the application.
|
|
|
|
| 69 |
return None
|
| 70 |
|
| 71 |
# --- NEW METHOD ADDED ---
|
| 72 |
+
def get_visa_photo_metadata_per_service(self) -> Dict[int, Dict[str, Any]]:
|
| 73 |
+
"""
|
| 74 |
+
Retrieves visa photo specifications for each service.
|
| 75 |
+
Returns a dictionary mapping service_id to its photo specifications.
|
| 76 |
+
"""
|
| 77 |
+
query = """
|
| 78 |
+
select s."name", metadata from service_document sd
|
| 79 |
+
join service s on s.id = sd.service_id
|
| 80 |
+
join document d on d.id = sd.document_id
|
| 81 |
+
where d.metadata is not null and s.is_active = true and s.has_limited_discoverability = False;
|
| 82 |
+
"""
|
| 83 |
+
df = self._execute_query(query)
|
| 84 |
+
result = {}
|
| 85 |
+
for _, row in df.iterrows():
|
| 86 |
+
service_name = row['name']
|
| 87 |
+
metadata = row['metadata']
|
| 88 |
+
try:
|
| 89 |
+
metadata_dict = json.loads(metadata)
|
| 90 |
+
result[service_name] = metadata_dict
|
| 91 |
+
except json.JSONDecodeError:
|
| 92 |
+
logging.warning(f"Invalid JSON metadata for service {service_name}")
|
| 93 |
+
return result
|
| 94 |
+
|
| 95 |
def get_destination_country(self, application_id: int) -> str | None:
|
| 96 |
"""
|
| 97 |
Gets the official destination country name for the application.
|
server.py
CHANGED
|
@@ -314,6 +314,20 @@ def create_app() -> Flask:
|
|
| 314 |
except Exception as e:
|
| 315 |
print(f"Passport Error: {e}")
|
| 316 |
return jsonify({"error": str(e)}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
@app.route('/', methods=['GET'])
|
| 318 |
def hello_world():
|
| 319 |
return "Flask server is running.", 200
|
|
|
|
| 314 |
except Exception as e:
|
| 315 |
print(f"Passport Error: {e}")
|
| 316 |
return jsonify({"error": str(e)}), 500
|
| 317 |
+
|
| 318 |
+
@app.route('/photo-metadata', methods=['GET'])
|
| 319 |
+
def photo_metadata():
|
| 320 |
+
"""
|
| 321 |
+
Endpoint to get visa photo metadata per service.
|
| 322 |
+
"""
|
| 323 |
+
try:
|
| 324 |
+
from app.util.db_utils import DBUtils
|
| 325 |
+
db_utils = DBUtils()
|
| 326 |
+
metadata = db_utils.get_visa_photo_metadata_per_service()
|
| 327 |
+
return jsonify(metadata), 200
|
| 328 |
+
except Exception as e:
|
| 329 |
+
logging.error(f"Error in /photo-metadata: {e}", exc_info=True)
|
| 330 |
+
return jsonify({"error": str(e)}),
|
| 331 |
@app.route('/', methods=['GET'])
|
| 332 |
def hello_world():
|
| 333 |
return "Flask server is running.", 200
|