mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 15:12:08 +01:00
Update 7project/backend/app/api/transactions.py
Better error message Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -116,13 +116,16 @@ async def update_transaction(
|
||||
# Preload categories to avoid async lazy-load during assignment
|
||||
await session.refresh(tx, attribute_names=["categories"])
|
||||
if payload.category_ids:
|
||||
# Check for duplicate category IDs in the payload
|
||||
if len(payload.category_ids) != len(set(payload.category_ids)):
|
||||
raise HTTPException(status_code=400, detail="Duplicate category IDs in payload")
|
||||
res = await session.execute(
|
||||
select(Category).where(
|
||||
Category.user_id == user.id, Category.id.in_(payload.category_ids)
|
||||
)
|
||||
)
|
||||
categories = list(res.scalars())
|
||||
if len(categories) != len(set(payload.category_ids)):
|
||||
if len(categories) != len(payload.category_ids):
|
||||
raise HTTPException(status_code=400, detail="One or more categories not found")
|
||||
tx.categories = categories
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user