Skip to content

Commit

Permalink
Merge branch 'sugestor-de-componentes-#52' of https://github.com/ES2-…
Browse files Browse the repository at this point in the history
…UFPI/WiseBuilder into sugestor-de-componentes-#52
  • Loading branch information
wesleyvitor11000 committed Mar 23, 2023
2 parents 68bd3b2 + 70430d8 commit 9115f68
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/framework/domain/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List

from .entity import Entity
from .exception import KnapsackBurst

__all__ = [
"Component",
Expand Down Expand Up @@ -220,6 +221,20 @@ class PSUComponent(Component):
modularity: EPSUModularity


@dataclass
class Knapsack(Entity):
components: list[Component]
max_price: Money
current_price: Money

def push(self, component: Component, price: Money):
if self.current_price + price > self.max_price:
raise KnapsackBurst()

# TODO checar restrições
self.components.append(component)


component_cls_idx = [
Component,
MotherboardComponent,
Expand Down
10 changes: 10 additions & 0 deletions src/framework/domain/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ class DomainException(Exception):

def __repr__(self):
return f"{self.__class__.__name__}: {self._message}"


@dataclass
class KnapsackBurst(DomainException):
_message: str = "A bolsa atingiu o limite de preço."


@dataclass
class CurrencyNotEqual(DomainException):
_message: str = "As moedas são diferentes"
6 changes: 6 additions & 0 deletions src/framework/domain/value_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Tuple

from .rule import Rule, BussinessAssertionExtension
from .exception import CurrencyNotEqual

__all__ = ["UUID", "UUIDv4", "UUIDv5", "ValueObject", "Money", "URL"]

Expand All @@ -32,6 +33,11 @@ def __eq__(self, oMoney: "Money") -> bool:
def __lt__(self, oMoney: "Money") -> bool:
return self.currency == oMoney.currency and self.amount < oMoney.amount

def __add__(self, oMoney: "Money") -> "Money":
if self.currency != oMoney.currency:
raise CurrencyNotEqual()
return Money(self.amount + oMoney.amount)

def __repr__(self):
return f"{self.currency} {self.amount:.2f}"

Expand Down

0 comments on commit 9115f68

Please sign in to comment.