This commit is contained in:
2024-03-10 18:11:14 -04:00
parent 039ecde461
commit 31830844a4
3 changed files with 37 additions and 22 deletions

View File

@@ -56,4 +56,37 @@ class AnimalShelter(object):
data = self.collection.find(criteria)
return data
except Exception as e:
raise Exception(f"Error: {e}")
raise Exception(f"Error: {e}")
def update(self, *args, **kwargs):
criteria = kwargs.get('criteria', None)
update_one = kwargs.get('once', False)
update_type = kwargs.get('update_type', None)
data = kwargs.get('data', None)
if update_one:
try:
self.collection.update_one(criteria, {f'${update_type}': data})
except Exception as e:
raise Exception(f"Error: {e}")
else:
try:
self.collection.update_many(criteria, {f'${update_type}': data})
except Exception as e:
raise Exception(f'Error: {e}')
def delete(self, *args, **kwargs):
criteria = kwargs.get('criteria', None)
delete_one = kwargs.get('once', False)
if delete_one:
try:
self.collection.delete_one(criteria)
except Exception as e:
raise Exception(f'Error: {e}')
else:
try:
self.collection.delete_many(criteria)
except Exception as e:
raise Exception(f'Error: {e}')