refactor: rename apply_event to apply

This commit is contained in:
2026-07-29 10:44:12 -04:00
parent 511a66ab66
commit fa65782059
5 changed files with 26 additions and 17 deletions

View File

@@ -8,8 +8,10 @@ from domain.marketplace.domain_event import DomainEvent
class Entity(ABC):
_changes: tuple[DomainEvent, ...] = ()
def apply_event(self, event: DomainEvent) -> Self:
return replace(self, _changes=(*self._changes, event))
def apply(self, event: DomainEvent) -> Self:
result = self.when(event)
result._ensure_valid_state()
return replace(result, _changes=(*result._changes, event))
def get_changes(self) -> tuple[DomainEvent, ...]:
return self._changes

View File

@@ -57,27 +57,27 @@ class ClassifiedAd(Entity):
self._ensure_valid_state()
updated = replace(self, state=ClassifiedAdState.PendingReview)
return updated.apply_event(
return updated.apply(
ClassifiedAdSentForReview(id=self.id.value)
)
def set_title(self, title: ClassifiedAdTitle) -> ClassifiedAd:
updated = replace(self, title=title)
updated._ensure_valid_state()
return updated.apply_event(
return updated.apply(
ClassifiedAdTitleChanged(id=self.id.value, title=title.title)
)
def update_text(self, text: ClassifiedAdText) -> ClassifiedAd:
updated = replace(self, text=text)
updated._ensure_valid_state()
return updated.apply_event(
return updated.apply(
ClassifiedAdTextUpdated(id=self.id.value, ad_text=text.text)
)
def update_price(self, price: Price) -> ClassifiedAd:
updated = replace(self, price=price)
updated._ensure_valid_state()
return updated.apply_event(
return updated.apply(
ClassifiedAdPriceUpdated(id=self.id.value, price=price.amount)
)