feat: add RequestToPublish to ClassifiedAd with state management
This commit is contained in:
@@ -2,8 +2,12 @@ from dataclasses import dataclass, field
|
||||
from decimal import Decimal
|
||||
|
||||
from domain.marketplace.classified_ad_id import ClassifiedAdId
|
||||
from domain.marketplace.classified_ad_state import ClassifiedAdState
|
||||
from domain.marketplace.classified_ad_text import ClassifiedAdText
|
||||
from domain.marketplace.classified_ad_title import ClassifiedAdTitle
|
||||
from domain.marketplace.invalid_entity_state_exception import (
|
||||
InvalidEntityStateException,
|
||||
)
|
||||
from domain.marketplace.price import Price
|
||||
from domain.marketplace.user_id import UserId
|
||||
|
||||
@@ -15,3 +19,27 @@ class ClassifiedAd:
|
||||
title: ClassifiedAdTitle
|
||||
text: ClassifiedAdText
|
||||
price: Price = field(default_factory=lambda: Price(amount=Decimal("0.00")))
|
||||
state: ClassifiedAdState | None = None
|
||||
|
||||
def request_to_publish(self):
|
||||
errors = []
|
||||
if not self.title.title:
|
||||
errors.append("title")
|
||||
if not self.text.text:
|
||||
errors.append("text")
|
||||
if self.price.amount <= 0:
|
||||
errors.append("price")
|
||||
|
||||
if errors:
|
||||
raise InvalidEntityStateException(
|
||||
f"Cannot publish classified ad with missing or invalid: {', '.join(errors)}"
|
||||
)
|
||||
|
||||
return ClassifiedAd(
|
||||
id=self.id,
|
||||
_ownerId=self._ownerId,
|
||||
title=self.title,
|
||||
text=self.text,
|
||||
price=self.price,
|
||||
state=ClassifiedAdState.PendingReview,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user