Skip to content
This repository has been archived by the owner on Dec 24, 2024. It is now read-only.

Commit

Permalink
feat: replace users list with a dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
1995parham committed Mar 19, 2024
1 parent d87f68c commit 91b7ec5
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions app/services/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,39 @@
from app import domain


class DuplicateEntry(Exception):
"""
Duplicate user identification.
"""

def __init__(self, user_id: str):
self.user_id = user_id

super().__init__()

def __str__(self):
return f"duplicate user ({self.user_id})"


class Storage:
"""
In memory storage for users.
"""

storage: list[domain.User] = []
storage: dict[str, domain.User] = {}

def __init__(self):
pass

def append(self, user: domain.User):
self.storage.append(user)
"""
Register new user.
"""
if user.id not in self.storage:
self.storage[user.id] = user

def all(self) -> list[domain.User]:
return self.storage
"""
Return all the registered users.
"""
return list(self.storage.values())

0 comments on commit 91b7ec5

Please sign in to comment.