mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-26 05:51:29 +00:00
refactor(tokens-repo): detach preparing a dict before a model cast
This commit is contained in:
parent
e504585437
commit
3cb7f29593
|
@ -76,18 +76,22 @@ class RedisTokensRepository(AbstractTokensRepository):
|
||||||
"""Retrieves new device key that is already stored."""
|
"""Retrieves new device key that is already stored."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _prepare_model_dict(d: dict):
|
||||||
|
for date in [
|
||||||
|
"created_at",
|
||||||
|
]:
|
||||||
|
if d[date] != "None":
|
||||||
|
d[date] = datetime.fromisoformat(d[date])
|
||||||
|
for key in d.keys():
|
||||||
|
if d[key] == "None":
|
||||||
|
d[key] = None
|
||||||
|
|
||||||
def _token_from_hash(self, redis_key: str) -> Token:
|
def _token_from_hash(self, redis_key: str) -> Token:
|
||||||
r = self.connection
|
r = self.connection
|
||||||
if r.exists(redis_key):
|
if r.exists(redis_key):
|
||||||
token_dict = r.hgetall(redis_key)
|
token_dict = r.hgetall(redis_key)
|
||||||
for date in [
|
RedisTokensRepository._prepare_model_dict(token_dict)
|
||||||
"created_at",
|
|
||||||
]:
|
|
||||||
if token_dict[date] != "None":
|
|
||||||
token_dict[date] = datetime.fromisoformat(token_dict[date])
|
|
||||||
for key in token_dict.keys():
|
|
||||||
if token_dict[key] == "None":
|
|
||||||
token_dict[key] = None
|
|
||||||
|
|
||||||
return Token(**token_dict)
|
return Token(**token_dict)
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in a new issue