Skip to content

Commit bf57538

Browse files
authored
Merge pull request #62 from febus982/add_events_support
Add events support
2 parents caa2a48 + 0918fe4 commit bf57538

37 files changed

+627
-180
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[run]
22
branch = True
3-
source = http_app, grpc_app, domains, storage
3+
source = http_app, grpc_app, domains, gateways
44
omit = grpc_app/generated/*
55
concurrency = multiprocessing
66
parallel = true

.idea/bootstrap-fastapi-service.iml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ COPY --chown=nonroot:nonroot pyproject.toml .
6565
COPY --chown=nonroot:nonroot poetry.lock .
6666
COPY --chown=nonroot:nonroot alembic ./alembic
6767
COPY --chown=nonroot:nonroot domains ./domains
68-
COPY --chown=nonroot:nonroot storage ./storage
68+
COPY --chown=nonroot:nonroot gateways ./gateways
6969
COPY --chown=nonroot:nonroot config.py .
7070
COPY --chown=nonroot:nonroot di_container.py .
7171
COPY --chown=nonroot:nonroot alembic.ini .

alembic/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from alembic import context
77
from config import AppConfig, init_logger
8-
from storage.SQLAlchemy import init_tables
8+
from gateways.storage.SQLAlchemy import init_tables
99

1010
USE_TWOPHASE = False
1111

architecture.png

8.17 KB
Loading

architecture.puml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,44 @@ package http_app {
77
}
88

99
package grpc_app {
10-
package services #DDDDDD
10+
package servicers #DDDDDD
1111
}
1212

1313
package domains #DDDDDD {
1414
package books {
1515
class Book
1616
class BookService
17-
protocol BookRepositoryInterface
18-
class BookModel
17+
18+
package entities {
19+
class BookModel
20+
}
21+
22+
package data_access_interface {
23+
protocol BookRepositoryInterface
24+
protocol BookEventGatewayInterface
25+
}
1926
}
2027
}
2128

22-
package storage #DDDDDD {
23-
package Repositories {
24-
class SQLAlchemyRepository
25-
}
29+
package gateways #DDDDDD {
30+
class SQLAlchemyRepository
31+
class NullEventGateway
2632
}
2733

34+
2835
'links framework - domains
2936
routes --> BookService
3037
routes --> Book
31-
services --> BookService
32-
services --> Book
38+
servicers --> BookService
39+
servicers --> Book
3340

3441
'links internal to books domain
3542
BookService -l-> Book
36-
BookService --> BookModel
37-
BookService --> BookRepositoryInterface
38-
BookRepositoryInterface -l-> BookModel
43+
BookService --> entities
44+
BookService -r-> data_access_interface
45+
data_access_interface --> entities
46+
47+
'links domains - gateways
48+
gateways --|> data_access_interface: implements >
3949

40-
'links domains - storage
41-
SQLAlchemyRepository --d-|> BookRepositoryInterface: implements >
4250
@enduml

di_container.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
from sqlalchemy_bind_manager._repository import SQLAlchemyAsyncRepository
55

66
from config import AppConfig
7-
from domains.books._data_access_interfaces import BookRepositoryInterface
8-
from domains.books._models import BookModel
7+
from domains.books._data_access_interfaces import (
8+
BookEventGatewayInterface,
9+
BookRepositoryInterface,
10+
)
11+
from domains.books.models import BookModel
12+
from gateways.event import NullEventGateway
913

1014

1115
class Container(DeclarativeContainer):
@@ -17,7 +21,7 @@ class Container(DeclarativeContainer):
1721

1822
wiring_config = WiringConfiguration(
1923
packages=[
20-
"storage",
24+
"gateways",
2125
"domains",
2226
]
2327
)
@@ -61,3 +65,6 @@ def function(
6165
bind=SQLAlchemyBindManager.provided.get_bind.call(),
6266
model_class=BookModel,
6367
)
68+
BookEventGatewayInterface: Factory[BookEventGatewayInterface] = Factory(
69+
NullEventGateway
70+
)

domains/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ def inject_book_repository(f):
2727
@wraps(f)
2828
def wrapper(*args, **kwds):
2929
if "book_repository" not in kwds.keys():
30-
from storage.repositories.book_repository import BookRepository
31-
kwds["book_repository"] = BookRepository() # Here we'll have to pass any required dependency for the repository
30+
from gateways.storage import BookRepository
31+
kwds[
32+
"book_repository"] = BookRepository() # Here we'll have to pass any required dependency for the repository
3233
elif not isinstance(kwds["book_repository"], BookRepositoryInterface):
3334
import warnings
3435
warnings.warn(
@@ -52,6 +53,6 @@ def book_repository_factory(sa_manager: SQLAlchemyBindManager) -> BookRepository
5253
Returns:
5354
The book repository.
5455
"""
55-
from storage.repositories.book_repository import BookRepository
56+
from gateways.storage import BookRepository
5657
return BookRepository(sa_manager=sa_manager)
5758
```

domains/books/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
from ._dto import Book, BookData
2-
from ._service import BookService

domains/books/_data_access_interfaces.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
from sqlalchemy_bind_manager.repository import SortDirection
55

6-
from ._models import BookModel
6+
from domains.books.models import BookModel
7+
from domains.cloudevent_base import BaseEvent
78

89

910
class BookRepositoryInterface(Protocol):
@@ -16,3 +17,8 @@ async def find(
1617
order_by: Union[None, Iterable[Union[str, Tuple[str, SortDirection]]]] = None,
1718
) -> List[BookModel]:
1819
...
20+
21+
22+
class BookEventGatewayInterface(Protocol):
23+
async def emit(self, event: BaseEvent) -> None:
24+
...

0 commit comments

Comments
 (0)