Adding Part Types

This commit is contained in:
Ian Roddis committed 2026-06-25 10:56:46 -03:00
1 parent b7ad517174
commit fe6f9cca05
14 files changed
+350 -2

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.part_type import PartType
async def get(db: AsyncSession, part_type_id: int) -> PartType | None:
return await db.get(PartType, part_type_id)
async def get_by_name(db: AsyncSession, name: str) -> PartType | None:
result = await db.execute(select(PartType).where(PartType.name == name))
return result.scalar_one_or_none()
async def list_all(
db: AsyncSession, skip: int = 0, limit: int = 100
) -> list[PartType]:
result = await db.execute(
select(PartType).order_by(PartType.name).offset(skip).limit(limit)
)
return list(result.scalars().all())
async def create(db: AsyncSession, *, name: str) -> PartType:
pt = PartType(name=name)
db.add(pt)
await db.commit()
await db.refresh(pt)
return pt
async def update(db: AsyncSession, part_type: PartType, data: dict) -> PartType:
for field, value in data.items():
setattr(part_type, field, value)
await db.commit()
await db.refresh(part_type)
return part_type
async def delete(db: AsyncSession, part_type: PartType) -> None:
await db.delete(part_type)
await db.commit()