Adding ability to update / patch by sku, adding uniqueness constraint violation checks
This commit is contained in:
1 parent
af5343da0c
commit
d8db87c13e
13 files changed
+541
-13
No files matched your search
@@ -33,6 +33,10 @@ async def create_attachment_point_name(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(require_permission("attachment_point_names:write")),
|
||||
):
|
||||
if await apn_crud.get_by_name(db, payload.name):
|
||||
raise HTTPException(
|
||||
status_code=409, detail="Attachment point name already exists"
|
||||
)
|
||||
apn = await apn_crud.create(db, name=payload.name)
|
||||
await audit_crud.log(
|
||||
db,
|
||||
@@ -68,6 +72,12 @@ async def update_attachment_point_name(
|
||||
if apn is None:
|
||||
raise HTTPException(status_code=404, detail="Attachment point name not found")
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
if "name" in changes:
|
||||
existing = await apn_crud.get_by_name(db, changes["name"])
|
||||
if existing is not None and existing.id != apn.id:
|
||||
raise HTTPException(
|
||||
status_code=409, detail="Attachment point name already exists"
|
||||
)
|
||||
apn = await apn_crud.update(db, apn, changes)
|
||||
await audit_crud.log(
|
||||
db,
|
||||
|
||||
Reference in new issue
Block a user