chore(quality): apply ruff autofixes and formatting (29 fixes, 41 files reformatted)
This commit is contained in:
+32
-17
@@ -3,9 +3,9 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
||||
from sqlalchemy import select, func, or_
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import joinedload, selectinload
|
||||
from sqlalchemy.orm import 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, Crew, CrewAvailability
|
||||
from app.schemas.crew import (
|
||||
@@ -24,6 +24,7 @@ avail_router = APIRouter(prefix="/crew-availabilities", tags=["crew-availabiliti
|
||||
|
||||
# ===== Crew Endpoints =====
|
||||
|
||||
|
||||
@router.get("", response_model=CrewListResponse)
|
||||
async def list_crew(
|
||||
page: int = Query(1, ge=1),
|
||||
@@ -55,8 +56,7 @@ async def list_crew(
|
||||
total = (await session.execute(count_q)).scalar() or 0
|
||||
|
||||
q = (
|
||||
base_q
|
||||
.options(selectinload(Crew.availabilities))
|
||||
base_q.options(selectinload(Crew.availabilities))
|
||||
.order_by(Crew.last_name, Crew.first_name)
|
||||
.offset((page - 1) * size)
|
||||
.limit(size)
|
||||
@@ -102,7 +102,9 @@ async def get_crew(
|
||||
)
|
||||
member = result.unique().scalars().first()
|
||||
if not member:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Crew member not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Crew member not found"
|
||||
)
|
||||
return CrewResponse.model_validate(member)
|
||||
|
||||
|
||||
@@ -122,7 +124,9 @@ async def update_crew(
|
||||
)
|
||||
member = result.unique().scalars().first()
|
||||
if not member:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Crew member not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Crew member not found"
|
||||
)
|
||||
|
||||
update_data = body.model_dump(exclude_unset=True)
|
||||
for field, value in update_data.items():
|
||||
@@ -146,7 +150,9 @@ async def delete_crew(
|
||||
)
|
||||
member = result.scalars().first()
|
||||
if not member:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Crew member not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Crew member not found"
|
||||
)
|
||||
|
||||
await session.delete(member)
|
||||
await session.commit()
|
||||
@@ -155,6 +161,7 @@ async def delete_crew(
|
||||
|
||||
# ===== CrewAvailability Endpoints =====
|
||||
|
||||
|
||||
@avail_router.get("", response_model=CrewAvailabilityListResponse)
|
||||
async def list_availabilities(
|
||||
page: int = Query(1, ge=1),
|
||||
@@ -166,11 +173,7 @@ async def list_availabilities(
|
||||
):
|
||||
"""List availabilities with filters."""
|
||||
account_id = current_user.account_id
|
||||
base_q = (
|
||||
select(CrewAvailability)
|
||||
.join(Crew)
|
||||
.where(Crew.account_id == account_id)
|
||||
)
|
||||
base_q = select(CrewAvailability).join(Crew).where(Crew.account_id == account_id)
|
||||
|
||||
if crew_id:
|
||||
base_q = base_q.where(CrewAvailability.crew_id == crew_id)
|
||||
@@ -180,7 +183,11 @@ async def list_availabilities(
|
||||
count_q = select(func.count()).select_from(base_q.subquery())
|
||||
total = (await session.execute(count_q)).scalar() or 0
|
||||
|
||||
q = base_q.order_by(CrewAvailability.start_date.desc()).offset((page - 1) * size).limit(size)
|
||||
q = (
|
||||
base_q.order_by(CrewAvailability.start_date.desc())
|
||||
.offset((page - 1) * size)
|
||||
.limit(size)
|
||||
)
|
||||
result = await session.execute(q)
|
||||
items = result.scalars().all()
|
||||
|
||||
@@ -192,7 +199,9 @@ async def list_availabilities(
|
||||
)
|
||||
|
||||
|
||||
@avail_router.post("", response_model=CrewAvailabilityResponse, status_code=status.HTTP_201_CREATED)
|
||||
@avail_router.post(
|
||||
"", response_model=CrewAvailabilityResponse, status_code=status.HTTP_201_CREATED
|
||||
)
|
||||
async def create_availability(
|
||||
body: CrewAvailabilityCreateRequest,
|
||||
current_user: User = Depends(require_permission("crew:write")),
|
||||
@@ -207,7 +216,9 @@ async def create_availability(
|
||||
)
|
||||
)
|
||||
if not crew_result.scalars().first():
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Crew member not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Crew member not found"
|
||||
)
|
||||
|
||||
avail = CrewAvailability(**body.model_dump())
|
||||
session.add(avail)
|
||||
@@ -234,7 +245,9 @@ async def update_availability(
|
||||
)
|
||||
avail = result.scalars().first()
|
||||
if not avail:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Availability not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Availability not found"
|
||||
)
|
||||
|
||||
update_data = body.model_dump(exclude_unset=True)
|
||||
for field, value in update_data.items():
|
||||
@@ -262,7 +275,9 @@ async def delete_availability(
|
||||
)
|
||||
avail = result.scalars().first()
|
||||
if not avail:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Availability not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Availability not found"
|
||||
)
|
||||
|
||||
await session.delete(avail)
|
||||
await session.commit()
|
||||
|
||||
Reference in New Issue
Block a user