Adding AttachmentPointNames

This commit is contained in:
Ian Roddis committed 2026-07-02 13:57:03 -03:00
1 parent ae50ec7049
commit 2767fb1c8e
14 files changed
+406 -3

No files matched your search

+92
View File
@@ -0,0 +1,92 @@
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.database import get_db
from app.crud import attachment_point_name as apn_crud
from app.crud import audit as audit_crud
from app.deps import require_permission
from app.models.user import User
from app.schemas.attachment_point_name import (
AttachmentPointNameCreate,
AttachmentPointNameRead,
AttachmentPointNameUpdate,
)
router = APIRouter()
@router.get("", response_model=list[AttachmentPointNameRead])
async def list_attachment_point_names(
skip: int = 0,
limit: int = 100,
db: AsyncSession = Depends(get_db),
_: User = Depends(require_permission("attachment_point_names:read")),
):
return await apn_crud.list_all(db, skip=skip, limit=limit)
@router.post(
"", response_model=AttachmentPointNameRead, status_code=status.HTTP_201_CREATED
)
async def create_attachment_point_name(
payload: AttachmentPointNameCreate,
db: AsyncSession = Depends(get_db),
actor: User = Depends(require_permission("attachment_point_names:write")),
):
apn = await apn_crud.create(db, name=payload.name)
await audit_crud.log(
db, actor=actor, action="create", resource_type="AttachmentPointName",
resource_id=apn.id,
description=audit_crud.describe_create("AttachmentPointName", apn.id, apn.name),
)
return apn
@router.get("/{apn_id}", response_model=AttachmentPointNameRead)
async def get_attachment_point_name(
apn_id: int,
db: AsyncSession = Depends(get_db),
_: User = Depends(require_permission("attachment_point_names:read")),
):
apn = await apn_crud.get(db, apn_id)
if apn is None:
raise HTTPException(status_code=404, detail="Attachment point name not found")
return apn
@router.patch("/{apn_id}", response_model=AttachmentPointNameRead)
async def update_attachment_point_name(
apn_id: int,
payload: AttachmentPointNameUpdate,
db: AsyncSession = Depends(get_db),
actor: User = Depends(require_permission("attachment_point_names:write")),
):
apn = await apn_crud.get(db, apn_id)
if apn is None:
raise HTTPException(status_code=404, detail="Attachment point name not found")
changes = payload.model_dump(exclude_unset=True)
apn = await apn_crud.update(db, apn, changes)
await audit_crud.log(
db, actor=actor, action="update", resource_type="AttachmentPointName",
resource_id=apn.id,
description=audit_crud.describe_update("AttachmentPointName", apn.id, changes),
)
return apn
@router.delete("/{apn_id}", status_code=status.HTTP_204_NO_CONTENT)
async def delete_attachment_point_name(
apn_id: int,
db: AsyncSession = Depends(get_db),
actor: User = Depends(require_permission("attachment_point_names:delete")),
):
apn = await apn_crud.get(db, apn_id)
if apn is None:
raise HTTPException(status_code=404, detail="Attachment point name not found")
name = apn.name
await apn_crud.delete(db, apn)
await audit_crud.log(
db, actor=actor, action="delete", resource_type="AttachmentPointName",
resource_id=apn_id,
description=audit_crud.describe_delete("AttachmentPointName", apn_id, name),
)
+2 -1
View File
@@ -1,6 +1,6 @@
from fastapi import APIRouter
from app.api import audit_log, augmented_parts, auth, clamp_connections, imported_parts, iso_threads, manufacturers, part_colours, part_types, roles, scope_models, static_connections, sub_part_types, unc_threads, users
from app.api import attachment_point_names, audit_log, augmented_parts, auth, clamp_connections, imported_parts, iso_threads, manufacturers, part_colours, part_types, roles, scope_models, static_connections, sub_part_types, unc_threads, users
api_router = APIRouter()
api_router.include_router(auth.router, prefix="/auth", tags=["auth"])
@@ -15,6 +15,7 @@ api_router.include_router(part_types.router, prefix="/part-types", tags=["part-t
api_router.include_router(sub_part_types.router, prefix="/sub-part-types", tags=["sub-part-types"])
api_router.include_router(static_connections.router, prefix="/static-connections", tags=["static-connections"])
api_router.include_router(clamp_connections.router, prefix="/clamp-connections", tags=["clamp-connections"])
api_router.include_router(attachment_point_names.router, prefix="/attachment-point-names", tags=["attachment-point-names"])
api_router.include_router(imported_parts.router, prefix="/imported-parts", tags=["imported-parts"])
api_router.include_router(augmented_parts.router, prefix="/augmented-parts", tags=["augmented-parts"])
api_router.include_router(audit_log.router, prefix="/audit-log", tags=["audit-log"])