From 0ae7c43ebf2b11c6b7edb8ab9086d80f3cd88cdc Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 14 Dec 2022 18:45:12 +0000 Subject: [PATCH] refactor(tokens-repo): break out generic hash_as_model casting --- .../repositories/tokens/redis_tokens_repository.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/selfprivacy_api/repositories/tokens/redis_tokens_repository.py b/selfprivacy_api/repositories/tokens/redis_tokens_repository.py index 930b043..833679f 100644 --- a/selfprivacy_api/repositories/tokens/redis_tokens_repository.py +++ b/selfprivacy_api/repositories/tokens/redis_tokens_repository.py @@ -124,17 +124,17 @@ class RedisTokensRepository(AbstractTokensRepository): return token_dict return None - def _token_from_hash(self, redis_key: str) -> Optional[Token]: + def _hash_as_model(self, redis_key: str, model_class): token_dict = self._model_dict_from_hash(redis_key) if token_dict is not None: - return Token(**token_dict) + return model_class(**token_dict) return None + def _token_from_hash(self, redis_key: str) -> Optional[Token]: + return self._hash_as_model(redis_key, Token) + def _recovery_key_from_hash(self, redis_key: str) -> Optional[RecoveryKey]: - token_dict = self._model_dict_from_hash(redis_key) - if token_dict is not None: - return RecoveryKey(**token_dict) - return None + return self._hash_as_model(redis_key, RecoveryKey) def _store_model_as_hash(self, redis_key, model): r = self.connection