Unify the way alerts and users are handled on the DB side

This commit is contained in:
2024-12-03 16:59:13 -08:00
parent 50f65abced
commit 9a36bb3f47
4 changed files with 39 additions and 22 deletions

View File

@@ -59,9 +59,6 @@ class User:
async def delete(self, table: Table) -> None:
if not self._loaded:
await self._lazy_load(table, consistent=True)
if self.subscribed_alerts:
for alert in self.subscribed_alerts:
await alert.remove_user(table, self)
await table.delete_item(
key={self.primary_key_name: self.primary_key},
)
@@ -80,3 +77,15 @@ class User:
self.subscribed_alerts.append(pdb.Alert.from_str(string_trinity))
self.region = Region(response['region'])
return True
async def add_alert(self, table: Table, alert: 'pdb.Alert', consistent: bool = False) -> None:
await self._lazy_load(table, consistent=consistent)
if alert not in self.subscribed_alerts:
self.subscribed_alerts.append(alert)
await self.put(table)
async def remove_alert(self, table: Table, alert: 'pdb.Alert', consistent: bool = True) -> None:
await self._lazy_load(table, consistent=consistent)
if alert in self.subscribed_alerts:
self.subscribed_alerts.remove(alert)
await self.put(table)