1414"""Service for managing Affiliation data."""
1515import datetime
1616import re
17- from typing import Dict , List
17+ from dataclasses import asdict
18+ from typing import Dict , List , Optional
1819
1920from flask import current_app
2021from requests .exceptions import HTTPError
2930from auth_api .models .contact_link import ContactLink
3031from auth_api .models .dataclass import Activity
3132from auth_api .models .dataclass import Affiliation as AffiliationData
32- from auth_api .models .dataclass import DeleteAffiliationRequest
33+ from auth_api .models .dataclass import AffiliationSearchDetails , DeleteAffiliationRequest
3334from auth_api .models .entity import Entity
3435from auth_api .models .membership import Membership as MembershipModel
3536from auth_api .schemas import AffiliationSchema
@@ -453,17 +454,24 @@ def _affiliation_details_url(affiliation: AffiliationModel) -> str:
453454 return current_app .config .get ("LEAR_AFFILIATION_DETAILS_URL" )
454455
455456 @staticmethod
456- async def get_affiliation_details (affiliations : List [AffiliationModel ], org_id ) -> List :
457+ async def get_affiliation_details (
458+ affiliations : List [AffiliationModel ], search_details : AffiliationSearchDetails , org_id
459+ ) -> List :
457460 """Return affiliation details by calling the source api."""
458461 url_identifiers = {} # i.e. turns into { url: [identifiers...] }
462+ search_dict = asdict (search_details )
459463 for affiliation in affiliations :
460464 url = Affiliation ._affiliation_details_url (affiliation )
461- url_identifiers .setdefault (url , [affiliation .entity .business_identifier ]).append (
462- affiliation .entity .business_identifier
463- )
464-
465+ url_identifiers .setdefault (url , []).append (affiliation .entity .business_identifier )
465466 call_info = [
466- {"url" : url , "payload" : {"identifiers" : identifiers }} for url , identifiers in url_identifiers .items ()
467+ {
468+ "url" : url ,
469+ "payload" : {
470+ "identifiers" : identifiers ,
471+ ** search_dict ,
472+ },
473+ }
474+ for url , identifiers in url_identifiers .items ()
467475 ]
468476
469477 token = RestService .get_service_account_token (
@@ -488,7 +496,7 @@ def sort_key(item):
488496 return combined
489497 except ServiceUnavailableException as err :
490498 logger .debug (err )
491- logger .debug ("Failed to get affiliations details: %s" , affiliations )
499+ logger .debug ("Failed to get affiliations details: %s" , affiliations )
492500 raise ServiceUnavailableException ("Failed to get affiliation details" ) from err
493501
494502 @staticmethod
@@ -560,7 +568,6 @@ def _get_nr_details(nr_number: str):
560568 except (HTTPError , ServiceUnavailableException ) as e :
561569 logger .info (e )
562570 raise BusinessException (Error .DATA_NOT_FOUND , None ) from e
563-
564571 return get_nr_response .json ()
565572
566573 @staticmethod
0 commit comments