from typing import Annotated from anydi import Inject from fansifter_common.api.schemas import response_errors from fansifter_common.encrypter import Encrypter from fastapi import APIRouter, Query from preference_center.api import schemas from preference_center.songwhip.exceptions import ( SongwhipFanDoubleOptInConsentIdCheckError, ) from preference_center.songwhip.handlers import ( SongwhipFanDoubleOptInConsentConfirmHandler, SongwhipFanDoubleOptInConsentConfirmRequest, ) router = APIRouter() @router.post( "/songwhip/encrypt-fan-consent-id", tags=["songwhip"], response_model=schemas.EncryptSongwhipFanConsentIdOutput, ) def encrypt_songwhip_fan_consent_id( input_data: schemas.EncryptSongwhipFanConsentIdInput, encrypter: Annotated[Encrypter, Inject()], ) -> dict[str, str]: return { "encrypted": encrypter.encrypt(input_data.fan_consent_id).decode(), } @router.post( "/songwhip/fan-double-opt-in-consent-confirm", tags=["songwhip"], responses=response_errors( SongwhipFanDoubleOptInConsentIdCheckError, ), ) def songwhip_fan_double_opt_in_consent_confirm( fan_consent_id: Annotated[str, Query(alias="fanConsentId")], country: Annotated[str, Query()], handler: Annotated[SongwhipFanDoubleOptInConsentConfirmHandler, Inject()], ) -> None: return handler.handle( SongwhipFanDoubleOptInConsentConfirmRequest( fan_consent_id=fan_consent_id, country=country, ) )