Backend (FastAPI): - REST API: auth, plants, beds, plantings - CRUD layer with CRUDBase - Pydantic v2 schemas for all entities - Alembic migration: complete schema + all enums - Seed data: 28 global plants + 15 compatibilities Frontend (Vue 3 + PrimeVue): - Axios client with JWT interceptor + auto-refresh - Pinia stores: auth, beds, plants - Views: Login, Beds, BedDetail, PlantLibrary - Components: AppLayout, BedForm, PlantingForm, PlantForm Docker: - docker-compose.yml (production) - docker-compose.dev.yml (development with hot-reload) - Nginx config with SPA fallback + API proxy - Multi-stage frontend Dockerfile - .env.example, .gitignore Version: 1.0.0-alpha
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
from uuid import UUID
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.orm import selectinload
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.bed import Bed
|
|
from app.schemas.bed import BedCreate, BedUpdate
|
|
|
|
|
|
class CRUDBed(CRUDBase[Bed, BedCreate, BedUpdate]):
|
|
async def get(self, db: AsyncSession, *, id: UUID) -> Bed | None:
|
|
result = await db.execute(
|
|
select(Bed)
|
|
.options(
|
|
selectinload(Bed.plantings).selectinload(
|
|
__import__("app.models.planting", fromlist=["BedPlanting"]).BedPlanting.plant
|
|
).selectinload(
|
|
__import__("app.models.plant", fromlist=["Plant"]).Plant.family
|
|
)
|
|
)
|
|
.where(Bed.id == id)
|
|
)
|
|
return result.scalar_one_or_none()
|
|
|
|
async def get_multi_for_tenant(
|
|
self, db: AsyncSession, *, tenant_id: UUID, skip: int = 0, limit: int = 100
|
|
) -> list[Bed]:
|
|
result = await db.execute(
|
|
select(Bed)
|
|
.where(Bed.tenant_id == tenant_id, Bed.is_active == True) # noqa: E712
|
|
.order_by(Bed.name)
|
|
.offset(skip)
|
|
.limit(limit)
|
|
)
|
|
return list(result.scalars().all())
|
|
|
|
async def get_with_plantings(self, db: AsyncSession, *, id: UUID) -> Bed | None:
|
|
from app.models.planting import BedPlanting
|
|
from app.models.plant import Plant
|
|
|
|
result = await db.execute(
|
|
select(Bed)
|
|
.options(
|
|
selectinload(Bed.plantings)
|
|
.selectinload(BedPlanting.plant)
|
|
.selectinload(Plant.family)
|
|
)
|
|
.where(Bed.id == id)
|
|
)
|
|
return result.scalar_one_or_none()
|
|
|
|
async def create_for_tenant(
|
|
self, db: AsyncSession, *, obj_in: BedCreate, tenant_id: UUID
|
|
) -> Bed:
|
|
return await self.create(db, obj_in=obj_in, tenant_id=tenant_id)
|
|
|
|
|
|
crud_bed = CRUDBed(Bed)
|