Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions legal-api/src/legal_api/services/search_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from operator import and_
from typing import Final, Optional

from flask import current_app
from requests import Request
from sqlalchemy import func

Expand Down Expand Up @@ -137,7 +138,7 @@ def separate_legal_types(legal_types: list[str]) -> tuple[list[str], list[str]]:
invalid_types = [t for t in input_normalized if not BusinessSearchService.try_parse_legal_type(t)]
return valid_types, invalid_types

# pylint: disable=too-many-locals
# pylint: disable=too-many-locals # pylint: disable=too-many-branches # pylint: disable=too-many-statements
@staticmethod
def get_search_filtered_businesses_results(business_json,
identifiers=None,
Expand Down Expand Up @@ -182,15 +183,26 @@ def get_search_filtered_businesses_results(business_json,
bus_query = db.session.query(Business).filter(*filters).limit(limit+1).offset(offset).all()
bus_results = []
for business in bus_query[:limit]:
business_json = business.json(slim=True)

if business.legal_type in (
Business.LegalTypes.SOLE_PROP,
Business.LegalTypes.PARTNERSHIP
):
business_json["alternateNames"] = business.get_alternate_names()

bus_results.append(business_json)
try:
business_json = business.json(slim=True)
if business.legal_type in (
Business.LegalTypes.SOLE_PROP,
Business.LegalTypes.PARTNERSHIP
):
business_json["alternateNames"] = business.get_alternate_names()
bus_results.append(business_json)
except Exception as e:
current_app. logger.error(
"Error serializing business %s: %s", business.identifier, e
)
bus_results. append({
"identifier": business.identifier,
"legalName": getattr(business, "legal_name", None),
"goodStanding": getattr(business, "good_standing", None),
"legalType": getattr(business, "legal_type", None),
"state": getattr(business, "state", None),
"error": "Unable to retrieve full details for this business."
})
has_more = len(bus_query) > limit
return bus_results, has_more

Expand Down