Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pgorecki committed May 24, 2021
0 parents commit f4a8744
Show file tree
Hide file tree
Showing 18 changed files with 293 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
.vscode
203 changes: 203 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.poetry]
name = "python-ddd"
version = "0.1.0"
description = ""
authors = ["Przemysław Górecki <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.9"
pytest = "^6.2.4"
pydantic = "^1.8.2"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Empty file added src/conftest.py
Empty file.
1 change: 1 addition & 0 deletions src/modules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains all modules related to bounded contexts.
5 changes: 5 additions & 0 deletions src/modules/listing/domain/entities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from seedwork.domain.entities import Entity


class AuctionItem(Entity):
pass
7 changes: 7 additions & 0 deletions src/modules/listing/domain/events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from seedwork.domain.events import DomainEvent


class DraftCreatedEvent(DomainEvent):
pass


9 changes: 9 additions & 0 deletions src/modules/listing/domain/rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from seedwork.domain.rules import BusinessRule
from seedwork.domain.value_objects import Currency

class AuctionItemPriceMustBeGreaterThanZero(BusinessRule):
message = "Price must be greater that zero"
price: Currency

def is_broken(self) -> bool:
return self.price <= 0
11 changes: 11 additions & 0 deletions src/modules/listing/tests/domain/test_rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from modules.listing.domain.rules import AuctionItemPriceMustBeGreaterThanZero


def test_AuctionItemPriceMustBeGreaterThanZero_rule():
rule = AuctionItemPriceMustBeGreaterThanZero(price=1)
assert not rule.is_broken()


def test_AuctionItemPriceMustBeGreaterThanZero_rule_is_broken():
rule = AuctionItemPriceMustBeGreaterThanZero(price=0)
assert rule.is_broken()
Empty file added src/pytest.ini
Empty file.
6 changes: 6 additions & 0 deletions src/seedwork/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
A **framework** is supposed to be a part-baked application that you extend in controlled ways to provide what you need. A **seedwork** is some minimal functionality that you modify however you like to get what you need. Of course this means that there's no way for you to get common updates to the seedwork, once you grow it you own it.


References:

- https://martinfowler.com/bliki/Seedwork.html
5 changes: 5 additions & 0 deletions src/seedwork/application/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pydantic import BaseModel


class Command(BaseModel):
pass
2 changes: 2 additions & 0 deletions src/seedwork/domain/entities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Entity:
pass
5 changes: 5 additions & 0 deletions src/seedwork/domain/events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pydantic import BaseModel


class DomainEvent(BaseModel):
pass
6 changes: 6 additions & 0 deletions src/seedwork/domain/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class DomainException(Exception):
pass


class BusinessRuleValidationException(DomainException):
pass
11 changes: 11 additions & 0 deletions src/seedwork/domain/rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pydantic import BaseModel


class BusinessRule(BaseModel):
message: str = "This is an error message for broken business rule"

def get_message(self) -> str:
return self.message

def is_broken(self) -> bool:
pass
2 changes: 2 additions & 0 deletions src/seedwork/domain/value_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Currency(int):
pass
2 changes: 2 additions & 0 deletions src/seedwork/infrastructure/repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Repository:
pass

0 comments on commit f4a8744

Please sign in to comment.