Make all private variables actually private and provide them as properties instead

This commit is contained in:
Emily Doherty 2024-12-08 18:13:48 -08:00
parent dd97d9b1f9
commit e7a9466092

View File

@ -15,13 +15,13 @@ class Alert:
self, alert: pdb.AlertType, flavor: Flavor, region: Region, price: int = 0 self, alert: pdb.AlertType, flavor: Flavor, region: Region, price: int = 0
) -> None: ) -> None:
# AlertType is the Primary Key # AlertType is the Primary Key
self.alert_type: pdb.AlertType = alert self._alert_type: pdb.AlertType = alert
# Flavor (Retail, Classic) is the Sort Key # Flavor (Retail, Classic) is the Sort Key
self.flavor: Flavor = flavor self._flavor: Flavor = flavor
self.region: Region = region self._region: Region = region
self.price: int = price self._price: int = price
self._loaded: bool = False self._loaded: bool = False
self.users: List[pdb.User] = [] self._users: List[pdb.User] = []
@classmethod @classmethod
def from_item(cls, primary_key: int, sort_key: str, users: List[int]) -> "Alert": def from_item(cls, primary_key: int, sort_key: str, users: List[int]) -> "Alert":
@ -66,6 +66,26 @@ class Alert:
self.sort_key_name: self.sort_key, self.sort_key_name: self.sort_key,
} }
@property
def alert_type(self) -> pdb.AlertType:
return self._alert_type
@property
def flavor(self) -> Flavor:
return self._flavor
@property
def region(self) -> Region:
return self._region
@property
def price(self) -> int:
return self._price
@property
def users(self) -> List[pdb.User]:
return self._users
def __str__(self): def __str__(self):
return f"{self.alert_type.value}-{self.flavor.value}-{self.region.value}-{self.price}" return f"{self.alert_type.value}-{self.flavor.value}-{self.region.value}-{self.price}"
@ -110,7 +130,7 @@ class Alert:
response = await table.get_item(key=self.key, consistent_read=consistent) response = await table.get_item(key=self.key, consistent_read=consistent)
except ItemNotFound: except ItemNotFound:
return False return False
self.users = [pdb.User(int(user_id)) for user_id in response["users"]] self._users = [pdb.User(int(user_id)) for user_id in response["users"]]
self._loaded = True self._loaded = True
return True return True