chore(quality): apply ruff autofixes and formatting (29 fixes, 41 files reformatted)
This commit is contained in:
@@ -1,22 +1,20 @@
|
||||
"""EquipmentGroup (Bundle) CRUD endpoints."""
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
||||
from sqlalchemy import select, func, or_
|
||||
from sqlalchemy import select, func
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import joinedload, selectinload
|
||||
|
||||
from app.api.deps import get_current_user, require_permission
|
||||
from app.api.deps import require_permission
|
||||
from app.db.session import get_async_session
|
||||
from app.models import User, EquipmentGroup, Equipment, StockLocation
|
||||
from app.models import User, EquipmentGroup, Equipment
|
||||
from app.models.equipment_group import equipment_group_items
|
||||
from app.schemas.equipment_group import (
|
||||
EquipmentGroupCreateRequest,
|
||||
EquipmentGroupUpdateRequest,
|
||||
EquipmentGroupResponse,
|
||||
EquipmentGroupListResponse,
|
||||
EquipmentGroupItem as EquipmentGroupItemSchema,
|
||||
)
|
||||
from app.schemas.equipment import LocationRef
|
||||
|
||||
router = APIRouter(prefix="/equipment-groups", tags=["equipment-groups"])
|
||||
|
||||
@@ -48,8 +46,10 @@ async def list_equipment_groups(
|
||||
total = (await session.execute(count_q)).scalar() or 0
|
||||
|
||||
q = (
|
||||
base_q
|
||||
.options(joinedload(EquipmentGroup.default_location), selectinload(EquipmentGroup.items))
|
||||
base_q.options(
|
||||
joinedload(EquipmentGroup.default_location),
|
||||
selectinload(EquipmentGroup.items),
|
||||
)
|
||||
.order_by(EquipmentGroup.name)
|
||||
.offset((page - 1) * size)
|
||||
.limit(size)
|
||||
@@ -65,7 +65,9 @@ async def list_equipment_groups(
|
||||
)
|
||||
|
||||
|
||||
@router.post("", response_model=EquipmentGroupResponse, status_code=status.HTTP_201_CREATED)
|
||||
@router.post(
|
||||
"", response_model=EquipmentGroupResponse, status_code=status.HTTP_201_CREATED
|
||||
)
|
||||
async def create_equipment_group(
|
||||
body: EquipmentGroupCreateRequest,
|
||||
current_user: User = Depends(require_permission("equipment:write")),
|
||||
@@ -110,7 +112,10 @@ async def create_equipment_group(
|
||||
# Reload with relationships
|
||||
await session.execute(
|
||||
select(EquipmentGroup)
|
||||
.options(joinedload(EquipmentGroup.default_location), selectinload(EquipmentGroup.items))
|
||||
.options(
|
||||
joinedload(EquipmentGroup.default_location),
|
||||
selectinload(EquipmentGroup.items),
|
||||
)
|
||||
.where(EquipmentGroup.id == group.id)
|
||||
)
|
||||
await session.refresh(group)
|
||||
@@ -128,12 +133,17 @@ async def get_equipment_group(
|
||||
account_id = current_user.account_id
|
||||
result = await session.execute(
|
||||
select(EquipmentGroup)
|
||||
.options(joinedload(EquipmentGroup.default_location), selectinload(EquipmentGroup.items))
|
||||
.options(
|
||||
joinedload(EquipmentGroup.default_location),
|
||||
selectinload(EquipmentGroup.items),
|
||||
)
|
||||
.where(EquipmentGroup.id == group_id, EquipmentGroup.account_id == account_id)
|
||||
)
|
||||
group = result.unique().scalars().first()
|
||||
if not group:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Equipment group not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Equipment group not found"
|
||||
)
|
||||
return EquipmentGroupResponse.model_validate(group)
|
||||
|
||||
|
||||
@@ -148,12 +158,17 @@ async def update_equipment_group(
|
||||
account_id = current_user.account_id
|
||||
result = await session.execute(
|
||||
select(EquipmentGroup)
|
||||
.options(joinedload(EquipmentGroup.default_location), selectinload(EquipmentGroup.items))
|
||||
.options(
|
||||
joinedload(EquipmentGroup.default_location),
|
||||
selectinload(EquipmentGroup.items),
|
||||
)
|
||||
.where(EquipmentGroup.id == group_id, EquipmentGroup.account_id == account_id)
|
||||
)
|
||||
group = result.unique().scalars().first()
|
||||
if not group:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Equipment group not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Equipment group not found"
|
||||
)
|
||||
|
||||
update_data = body.model_dump(exclude_unset=True, exclude={"items"})
|
||||
for field, value in update_data.items():
|
||||
@@ -201,7 +216,9 @@ async def delete_equipment_group(
|
||||
)
|
||||
group = result.scalars().first()
|
||||
if not group:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Equipment group not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Equipment group not found"
|
||||
)
|
||||
|
||||
await session.delete(group)
|
||||
await session.commit()
|
||||
|
||||
Reference in New Issue
Block a user