Adding ISOThread and UNC Thread

This commit is contained in:
Ian Roddis committed 2026-06-24 21:58:15 -03:00
1 parent 9285a021c0
commit 35e8a61b1d
22 files changed
+796 -3

No files matched your search

+71
View File
@@ -0,0 +1,71 @@
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.database import get_db
from app.crud import iso_thread as iso_thread_crud
from app.deps import require_permission
from app.models.user import User
from app.schemas.iso_thread import IsoThreadCreate, IsoThreadRead, IsoThreadUpdate
router = APIRouter()
@router.get("", response_model=list[IsoThreadRead])
async def list_iso_threads(
skip: int = 0,
limit: int = 100,
db: AsyncSession = Depends(get_db),
_: User = Depends(require_permission("iso_threads:read")),
):
return await iso_thread_crud.list_all(db, skip=skip, limit=limit)
@router.post("", response_model=IsoThreadRead, status_code=status.HTTP_201_CREATED)
async def create_iso_thread(
payload: IsoThreadCreate,
db: AsyncSession = Depends(get_db),
_: User = Depends(require_permission("iso_threads:write")),
):
return await iso_thread_crud.create(
db,
diameter_mm=payload.diameter_mm,
pitch_mm=payload.pitch_mm,
depth_mm=payload.depth_mm,
)
@router.get("/{iso_thread_id}", response_model=IsoThreadRead)
async def get_iso_thread(
iso_thread_id: int,
db: AsyncSession = Depends(get_db),
_: User = Depends(require_permission("iso_threads:read")),
):
thread = await iso_thread_crud.get(db, iso_thread_id)
if thread is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="ISO thread not found")
return thread
@router.patch("/{iso_thread_id}", response_model=IsoThreadRead)
async def update_iso_thread(
iso_thread_id: int,
payload: IsoThreadUpdate,
db: AsyncSession = Depends(get_db),
_: User = Depends(require_permission("iso_threads:write")),
):
thread = await iso_thread_crud.get(db, iso_thread_id)
if thread is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="ISO thread not found")
return await iso_thread_crud.update(db, thread, payload.model_dump(exclude_unset=True))
@router.delete("/{iso_thread_id}", status_code=status.HTTP_204_NO_CONTENT)
async def delete_iso_thread(
iso_thread_id: int,
db: AsyncSession = Depends(get_db),
_: User = Depends(require_permission("iso_threads:delete")),
):
thread = await iso_thread_crud.get(db, iso_thread_id)
if thread is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="ISO thread not found")
await iso_thread_crud.delete(db, thread)
+3 -1
View File
@@ -1,8 +1,10 @@
from fastapi import APIRouter
from app.api import auth, roles, users
from app.api import auth, iso_threads, roles, unc_threads, users
api_router = APIRouter()
api_router.include_router(auth.router, prefix="/auth", tags=["auth"])
api_router.include_router(users.router, prefix="/users", tags=["users"])
api_router.include_router(roles.router, prefix="/roles", tags=["roles"])
api_router.include_router(iso_threads.router, prefix="/iso-threads", tags=["iso-threads"])
api_router.include_router(unc_threads.router, prefix="/unc-threads", tags=["unc-threads"])
+72
View File
@@ -0,0 +1,72 @@
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.database import get_db
from app.crud import unc_thread as unc_thread_crud
from app.deps import require_permission
from app.models.user import User
from app.schemas.unc_thread import UncThreadCreate, UncThreadRead, UncThreadUpdate
router = APIRouter()
@router.get("", response_model=list[UncThreadRead])
async def list_unc_threads(
skip: int = 0,
limit: int = 100,
db: AsyncSession = Depends(get_db),
_: User = Depends(require_permission("unc_threads:read")),
):
return await unc_thread_crud.list_all(db, skip=skip, limit=limit)
@router.post("", response_model=UncThreadRead, status_code=status.HTTP_201_CREATED)
async def create_unc_thread(
payload: UncThreadCreate,
db: AsyncSession = Depends(get_db),
_: User = Depends(require_permission("unc_threads:write")),
):
return await unc_thread_crud.create(
db,
diameter_fraction=payload.diameter_fraction,
tpi=payload.tpi,
series=payload.series,
depth_in=payload.depth_in,
)
@router.get("/{unc_thread_id}", response_model=UncThreadRead)
async def get_unc_thread(
unc_thread_id: int,
db: AsyncSession = Depends(get_db),
_: User = Depends(require_permission("unc_threads:read")),
):
thread = await unc_thread_crud.get(db, unc_thread_id)
if thread is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="UNC thread not found")
return thread
@router.patch("/{unc_thread_id}", response_model=UncThreadRead)
async def update_unc_thread(
unc_thread_id: int,
payload: UncThreadUpdate,
db: AsyncSession = Depends(get_db),
_: User = Depends(require_permission("unc_threads:write")),
):
thread = await unc_thread_crud.get(db, unc_thread_id)
if thread is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="UNC thread not found")
return await unc_thread_crud.update(db, thread, payload.model_dump(exclude_unset=True))
@router.delete("/{unc_thread_id}", status_code=status.HTTP_204_NO_CONTENT)
async def delete_unc_thread(
unc_thread_id: int,
db: AsyncSession = Depends(get_db),
_: User = Depends(require_permission("unc_threads:delete")),
):
thread = await unc_thread_crud.get(db, unc_thread_id)
if thread is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="UNC thread not found")
await unc_thread_crud.delete(db, thread)