Source code for cadrumo.adapters.persistence.profile.profile_path_values
"""Persistence adapter for the application profile path projection."""from__future__importannotationsfromcollections.abcimportMappingfromtypingimportoverridefrompydanticimportValidationErrorfrom....application.persistence_errorsimportPersistenceDegradationErrorfrom....application.user_profile.profile_read_portsimportProfilePathValuesReadPortfrom....application.user_profile.profile_record_repositoryimportProfileRecordRepositoryfrom....application.user_profile.projectionsimportrecord_to_path_valuesfrom....domain.user_profile.errorsimportProfileNotFoundError,UserProfileErrorfrom..storage.errorsimportStorageError
[docs]classProfilePathValuesPersistenceAdapter(ProfilePathValuesReadPort):"""Translate the authenticated profile-record repository into path values."""def__init__(self,*,repository:ProfileRecordRepository)->None:"""Bind the already composed, session-bound profile record authority."""self._repository=repository
[docs]@overridedefload_path_values(self,*,bucket_id:str)->Mapping[str,str]|None:"""Read one profile projection and translate persistence failures inward."""try:record=self._repository.load(bucket_id)exceptProfileNotFoundError:returnNoneexcept(StorageError,OSError,UserProfileError,ValidationError,UnicodeDecodeError)asexc:raisePersistenceDegradationError("profile_path_values_load")fromexcreturnrecord_to_path_values(record)