auto-claude: subtask-6-4 - Add /api/it-audit/matches/<company_id> endpoint fo
Add API endpoint for getting IT audit collaboration matches for a company. - Admin-only access (matches are not visible to regular users per spec) - Returns all matches where company is either party A or B - Includes partner company info, match type/score/reason, status - Follows existing API patterns (login_required, try/finally, jsonify) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
b6a3411e43
commit
36272307fb
90
app.py
90
app.py
@ -5557,6 +5557,96 @@ def _parse_it_audit_form_data(data: dict) -> dict:
|
||||
return audit_data
|
||||
|
||||
|
||||
@app.route('/api/it-audit/matches/<int:company_id>')
|
||||
@login_required
|
||||
def api_it_audit_matches(company_id):
|
||||
"""
|
||||
API: Get IT audit collaboration matches for a company.
|
||||
|
||||
Returns all collaboration matches where the specified company
|
||||
is either company_a or company_b in the match pair.
|
||||
|
||||
This endpoint is admin-only as collaboration matches
|
||||
are not visible to regular users.
|
||||
|
||||
Args:
|
||||
company_id: Company ID to get matches for
|
||||
|
||||
Returns:
|
||||
JSON with list of matches including:
|
||||
- match_id, match_type, match_score, status
|
||||
- partner company info (id, name, slug)
|
||||
- match_reason and shared_attributes
|
||||
"""
|
||||
# Only admins can view collaboration matches
|
||||
if not current_user.is_admin:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': 'Brak uprawnień. Tylko administrator może przeglądać dopasowania.'
|
||||
}), 403
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
from it_audit_service import ITAuditService
|
||||
from database import ITCollaborationMatch
|
||||
|
||||
# Verify company exists
|
||||
company = db.query(Company).filter_by(id=company_id).first()
|
||||
if not company:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': 'Firma nie znaleziona'
|
||||
}), 404
|
||||
|
||||
# Get matches for this company
|
||||
service = ITAuditService(db)
|
||||
matches = service.get_matches_for_company(company_id)
|
||||
|
||||
# Format matches for JSON response
|
||||
matches_data = []
|
||||
for match in matches:
|
||||
# Determine partner company (the other company in the match)
|
||||
if match.company_a_id == company_id:
|
||||
partner = match.company_b
|
||||
else:
|
||||
partner = match.company_a
|
||||
|
||||
matches_data.append({
|
||||
'id': match.id,
|
||||
'match_type': match.match_type,
|
||||
'match_type_label': match.match_type_label,
|
||||
'match_score': match.match_score,
|
||||
'match_reason': match.match_reason,
|
||||
'status': match.status,
|
||||
'status_label': match.status_label,
|
||||
'shared_attributes': match.shared_attributes,
|
||||
'created_at': match.created_at.isoformat() if match.created_at else None,
|
||||
'partner': {
|
||||
'id': partner.id if partner else None,
|
||||
'name': partner.name if partner else None,
|
||||
'slug': partner.slug if partner else None,
|
||||
}
|
||||
})
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'company_id': company_id,
|
||||
'company_name': company.name,
|
||||
'matches_count': len(matches_data),
|
||||
'matches': matches_data
|
||||
}), 200
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching IT audit matches for company {company_id}: {e}")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': f'Błąd podczas pobierania dopasowań: {str(e)}'
|
||||
}), 500
|
||||
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
# ============================================================
|
||||
# ERROR HANDLERS
|
||||
# ============================================================
|
||||
|
||||
Loading…
Reference in New Issue
Block a user