From 1d76b529deb61bc3675b35a6c538094245ee408f Mon Sep 17 00:00:00 2001 From: vivekmaru36 <110764790+vivekmaru36@users.noreply.github.com> Date: Sun, 31 Dec 2023 22:17:06 +0530 Subject: [PATCH] Implement user addition in UserService online_chat.py --- .../object_oriented_design/online_chat/online_chat.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/solutions/object_oriented_design/online_chat/online_chat.py b/solutions/object_oriented_design/online_chat/online_chat.py index 7063ca04..ae469484 100644 --- a/solutions/object_oriented_design/online_chat/online_chat.py +++ b/solutions/object_oriented_design/online_chat/online_chat.py @@ -8,7 +8,13 @@ class UserService(object): self.users_by_id = {} # key: user id, value: User def add_user(self, user_id, name, pass_hash): - pass + if user_id not in self.users_by_id: + new_user = User(user_id, name, pass_hash) + self.users_by_id[user_id] = new_user + return new_user + else: + # User with this ID already exists + return None def remove_user(self, user_id): pass