refactor: remove db.commit() from business services, callers use UnitOfWork (Tier 3)
This commit is contained in:
@@ -10,6 +10,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.database import get_db
|
||||
from app.dependencies.auth import get_current_user, require_any_role
|
||||
from app.domain.unit_of_work import UnitOfWork
|
||||
from app.models.user import User
|
||||
from app.services import worklog_service
|
||||
|
||||
@@ -57,17 +58,20 @@ def create(
|
||||
user: User = Depends(require_any_role("red_tech", "blue_tech", "red_lead", "blue_lead")),
|
||||
):
|
||||
"""Create a manually-logged worklog entry."""
|
||||
wl = worklog_service.create_worklog(
|
||||
db,
|
||||
entity_type=body.entity_type,
|
||||
entity_id=body.entity_id,
|
||||
user_id=user.id,
|
||||
activity_type=body.activity_type,
|
||||
started_at=body.started_at,
|
||||
ended_at=body.ended_at,
|
||||
duration_seconds=body.duration_seconds,
|
||||
description=body.description,
|
||||
)
|
||||
with UnitOfWork(db) as uow:
|
||||
wl = worklog_service.create_worklog(
|
||||
db,
|
||||
entity_type=body.entity_type,
|
||||
entity_id=body.entity_id,
|
||||
user_id=user.id,
|
||||
activity_type=body.activity_type,
|
||||
started_at=body.started_at,
|
||||
ended_at=body.ended_at,
|
||||
duration_seconds=body.duration_seconds,
|
||||
description=body.description,
|
||||
)
|
||||
uow.commit()
|
||||
db.refresh(wl)
|
||||
return wl
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user