Skip to content

Commit

Permalink
fix: use explicit cruds arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumetavernier committed Mar 15, 2024
1 parent 859c969 commit f877982
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 11 additions & 2 deletions app/modules/loan/cruds_loan.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from typing import Sequence

from sqlalchemy import delete, func, select, update
Expand Down Expand Up @@ -191,10 +192,18 @@ async def update_loan(
async def update_loan_returned_status(
loan_id: str,
db: AsyncSession,
values: dict[str, object],
returned: bool,
returned_date: datetime,
):
await db.execute(
update(models_loan.Loan).where(models_loan.Loan.id == loan_id).values(values)
update(models_loan.Loan)
.where(models_loan.Loan.id == loan_id)
.values(
{
"returned": returned,
"returned_date": returned_date,
}
)
)
await db.commit()

Expand Down
9 changes: 3 additions & 6 deletions app/modules/loan/endpoints_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,12 +793,9 @@ async def return_loan(
detail=f"Invalid loan content {loan.id}, {item.id}",
)

values = {
"returned": True,
"returned_date": datetime.now(timezone.utc),
}

await cruds_loan.update_loan_returned_status(loan_id=loan_id, db=db, values=values)
await cruds_loan.update_loan_returned_status(
loan_id=loan_id, db=db, returned=True, returned_date=datetime.now(timezone.utc)
)


@module.router.post(
Expand Down

0 comments on commit f877982

Please sign in to comment.