Skip to content

Commit de8e330

Browse files
committed
replace seedwork Application with lato Application
1 parent 53b7041 commit de8e330

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1527
-671
lines changed

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.10.0
1+
3.11

diary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_route_controller(request, module):
2929
3030
3131
def post_route_controller(request, module):
32-
result = module.execute_command(MyCommand(
32+
result = module.execute(MyCommand(
3333
foo=request.POST.foo,
3434
bar=request.POST.bar,
3535
))

docs/architecture_decision_log/005_separate_commands_and_queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get_route_controller(request, module):
2020
2121
2222
def post_route_controller(request, module):
23-
result = module.execute_command(MyCommand(
23+
result = module.execute(MyCommand(
2424
foo=request.POST.foo,
2525
bar=request.POST.bar,
2626
))

poetry.lock

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

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ authors = ["Przemysław Górecki <[email protected]>"]
66

77
[tool.poetry.dependencies]
88
python = "^3.10.0"
9-
pytest = "^6.2.4"
10-
pydantic = "^1.8.2"
119
black = "^21.5b1"
12-
fastapi = "^0.95.2"
1310
uvicorn = "^0.14.0"
1411
starlette-context = "^0.3.3"
1512
SQLAlchemy = "^1.4.22"
@@ -29,6 +26,9 @@ httpx = "^0.23.1"
2926
requests = "^2.28.1"
3027
bcrypt = "^4.0.1"
3128
mypy = "^1.4.1"
29+
fastapi = "^0.110.0"
30+
lato = "^0.10.0"
31+
pydantic-settings = "^2.2.1"
3232

3333
[tool.poetry.dev-dependencies]
3434
poethepoet = "^0.10.0"

src/api/dependencies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from modules.iam.application.services import IamService
77
from modules.iam.domain.entities import User
8-
from seedwork.application import Application, TransactionContext
8+
from lato import Application, TransactionContext
99

1010
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
1111

@@ -28,5 +28,5 @@ async def get_authenticated_user(
2828
access_token: Annotated[str, Depends(oauth2_scheme)],
2929
ctx: Annotated[TransactionContext, Depends(get_transaction_context)],
3030
) -> User:
31-
current_user = ctx.get_service(IamService).find_user_by_access_token(access_token)
31+
current_user = ctx[IamService].find_user_by_access_token(access_token)
3232
return current_user

src/api/main.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from api.dependencies import oauth2_scheme # noqa
77
from api.routers import bidding, catalog, diagnostics, iam
88
from config.api_config import ApiConfig
9-
from config.container import TopLevelContainer
9+
from config.container import create_application, ApplicationContainer
1010
from seedwork.domain.exceptions import DomainException, EntityNotFoundException
1111
from seedwork.infrastructure.database import Base
1212
from seedwork.infrastructure.logging import LoggerFactory, logger
@@ -15,29 +15,30 @@
1515
LoggerFactory.configure(logger_name="api")
1616

1717
# dependency injection container
18-
container = TopLevelContainer()
19-
container.config.from_pydantic(ApiConfig())
18+
config = ApiConfig()
19+
container = ApplicationContainer(config=config)
20+
db_engine = container.db_engine()
21+
logger.info(f"using db engine {db_engine}, creating tables")
22+
Base.metadata.create_all(db_engine)
23+
logger.info("setup complete")
2024

21-
app = FastAPI(debug=container.config.DEBUG)
25+
app = FastAPI(debug=config.DEBUG)
2226

2327
app.include_router(catalog.router)
2428
app.include_router(bidding.router)
2529
app.include_router(iam.router)
2630
app.include_router(diagnostics.router)
2731
app.container = container
2832

29-
db_engine = container.db_engine()
30-
logger.info(f"using db engine {db_engine}, creating tables")
31-
Base.metadata.create_all(db_engine)
32-
logger.info("setup complete")
33+
3334

3435
try:
3536
import uuid
3637

3738
from modules.iam.application.services import IamService
3839

3940
with app.container.application().transaction_context() as ctx:
40-
iam_service = ctx.get_service(IamService)
41+
iam_service = ctx[IamService]
4142
iam_service.create_user(
4243
user_id=uuid.UUID(int=1),
4344

src/api/models/bidding.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,24 @@ class BidReadModel(BaseModel):
1010
currency: str
1111
bidder_id: GenericUUID
1212
bidder_username: str
13+
14+
class Config:
15+
arbitrary_types_allowed = True
1316

1417

1518
class BiddingResponse(BaseModel):
1619
listing_id: GenericUUID
1720
auction_status: str = "active" # active, ended
1821
auction_end_date: datetime
1922
bids: list[BidReadModel]
23+
24+
class Config:
25+
arbitrary_types_allowed = True
2026

2127

2228
class PlaceBidRequest(BaseModel):
2329
bidder_id: GenericUUID
2430
amount: float
31+
32+
class Config:
33+
arbitrary_types_allowed = True

src/api/routers/bidding.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from config.container import inject
88
from modules.bidding.application.command import PlaceBidCommand, RetractBidCommand
99
from modules.bidding.application.query.get_bidding_details import GetBiddingDetails
10-
from seedwork.application import Application
10+
from lato import Application
1111

1212
router = APIRouter()
1313

@@ -25,12 +25,11 @@ async def get_bidding_details_of_listing(
2525
Shows listing details
2626
"""
2727
query = GetBiddingDetails(listing_id=listing_id)
28-
query_result = app.execute_query(query)
29-
payload = query_result.payload
28+
result = app.execute(query)
3029
return BiddingResponse(
31-
listing_id=str(payload.id),
32-
auction_end_date=payload.ends_at,
33-
bids=payload.bids,
30+
listing_id=result.id,
31+
auction_end_date=result.ends_at,
32+
bids=result.bids,
3433
)
3534

3635

@@ -53,15 +52,14 @@ async def place_bid(
5352
bidder_id=request_body.bidder_id,
5453
amount=request_body.amount,
5554
)
56-
result = app.execute_command(command)
55+
app.execute(command)
5756

5857
query = GetBiddingDetails(listing_id=listing_id)
59-
query_result = app.execute_query(query)
60-
payload = query_result.payload
58+
result = app.execute(query)
6159
return BiddingResponse(
62-
listing_id=str(payload.id),
63-
auction_end_date=payload.ends_at,
64-
bids=payload.bids,
60+
listing_id=result.id,
61+
auction_end_date=result.ends_at,
62+
bids=result.bids,
6563
)
6664

6765

@@ -81,7 +79,7 @@ async def retract_bid(
8179
listing_id=listing_id,
8280
bidder_id="",
8381
)
84-
app.execute_command(command)
82+
app.execute(command)
8583

8684
query = GetBiddingDetails(listing_id=listing_id)
8785
query_result = app.execute_query(query)

src/api/routers/catalog.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323

2424
@router.get("/catalog", tags=["catalog"], response_model=ListingIndexModel)
2525
@inject
26-
async def get_all_listings(app: Annotated[Application, Depends(get_application)]):
26+
def get_all_listings(app: Annotated[Application, Depends(get_application)]):
2727
"""
2828
Shows all published listings in the catalog
2929
"""
3030
query = GetAllListings()
31-
query_result = app.execute_query(query)
32-
return dict(data=query_result.payload)
31+
result = app.execute(query)
32+
return dict(data=result)
3333

3434

3535
@router.get("/catalog/{listing_id}", tags=["catalog"], response_model=ListingReadModel)
@@ -64,7 +64,7 @@ async def create_listing(
6464
ask_price=Money(request_body.ask_price_amount, request_body.ask_price_currency),
6565
seller_id=current_user.id,
6666
)
67-
app.execute_command(command)
67+
app.execute(command)
6868

6969
query = GetListingDetails(listing_id=command.listing_id)
7070
query_result = app.execute_query(query)
@@ -87,7 +87,7 @@ async def delete_listing(
8787
listing_id=listing_id,
8888
seller_id=current_user.id,
8989
)
90-
app.execute_command(command)
90+
app.execute(command)
9191

9292

9393
@router.post(
@@ -109,8 +109,8 @@ async def publish_listing(
109109
listing_id=listing_id,
110110
seller_id=current_user.id,
111111
)
112-
app.execute_command(command)
112+
app.execute(command)
113113

114114
query = GetListingDetails(listing_id=listing_id)
115-
query_result = app.execute_query(query)
116-
return dict(query_result.payload)
115+
response = app.execute(query)
116+
return response

0 commit comments

Comments
 (0)