backend-development-course/app/local_db.py

45 lines
936 B
Python
Raw Normal View History

2024-10-28 17:19:47 +02:00
import uuid
class LocalDB:
def __init__(self):
self.users = {}
self.categories = {}
self.records = {}
def get_users(self):
return self.users
def get_user(self, uid):
if uid in self.users:
return {
'uuid': uid,
'name': self.users[uid]
}
else:
return {}
def add_user(self, name):
if not name:
return {}
if name in set(self.users.values()):
return {}
new_uuid = uuid.uuid4().hex
self.users[new_uuid] = name
return {
'uuid': new_uuid,
'name': name
}
def del_user(self, uid):
if uid in self.users:
name = self.users[uid]
del self.users[uid]
return {
'uuid': uid,
'name': name
}
else:
return {}