Initial commit: Sproutly plant tracking app
This commit is contained in:
121
backend/schemas.py
Normal file
121
backend/schemas.py
Normal file
@@ -0,0 +1,121 @@
|
||||
from __future__ import annotations
|
||||
from datetime import date, datetime
|
||||
from typing import Optional, List
|
||||
from pydantic import BaseModel
|
||||
from models import Category, SunRequirement, WaterNeeds, BatchStatus
|
||||
|
||||
|
||||
# --- Variety ---
|
||||
|
||||
class VarietyBase(BaseModel):
|
||||
name: str
|
||||
variety_name: Optional[str] = None
|
||||
category: Category = Category.vegetable
|
||||
weeks_to_start: Optional[int] = None
|
||||
weeks_to_greenhouse: Optional[int] = None
|
||||
weeks_to_garden: Optional[int] = None
|
||||
days_to_germinate: int = 7
|
||||
direct_sow_ok: bool = False
|
||||
frost_tolerant: bool = False
|
||||
sun_requirement: SunRequirement = SunRequirement.full_sun
|
||||
water_needs: WaterNeeds = WaterNeeds.medium
|
||||
color: str = "#52b788"
|
||||
notes: Optional[str] = None
|
||||
|
||||
|
||||
class VarietyCreate(VarietyBase):
|
||||
pass
|
||||
|
||||
|
||||
class VarietyUpdate(VarietyBase):
|
||||
pass
|
||||
|
||||
|
||||
class VarietyOut(VarietyBase):
|
||||
id: int
|
||||
created_at: Optional[datetime] = None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
# --- Batch ---
|
||||
|
||||
class BatchBase(BaseModel):
|
||||
variety_id: int
|
||||
label: Optional[str] = None
|
||||
quantity: int = 1
|
||||
sow_date: Optional[date] = None
|
||||
germination_date: Optional[date] = None
|
||||
greenhouse_date: Optional[date] = None
|
||||
garden_date: Optional[date] = None
|
||||
status: BatchStatus = BatchStatus.planned
|
||||
notes: Optional[str] = None
|
||||
|
||||
|
||||
class BatchCreate(BatchBase):
|
||||
pass
|
||||
|
||||
|
||||
class BatchUpdate(BatchBase):
|
||||
pass
|
||||
|
||||
|
||||
class BatchOut(BatchBase):
|
||||
id: int
|
||||
created_at: Optional[datetime] = None
|
||||
variety: Optional[VarietyOut] = None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
# --- Settings ---
|
||||
|
||||
class SettingsUpdate(BaseModel):
|
||||
last_frost_date: Optional[date] = None
|
||||
first_frost_fall_date: Optional[date] = None
|
||||
ntfy_topic: Optional[str] = None
|
||||
ntfy_server: Optional[str] = "https://ntfy.sh"
|
||||
notification_time: Optional[str] = "07:00"
|
||||
timezone: Optional[str] = "UTC"
|
||||
location_name: Optional[str] = None
|
||||
|
||||
|
||||
class SettingsOut(SettingsUpdate):
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
# --- Dashboard ---
|
||||
|
||||
class Task(BaseModel):
|
||||
type: str # "start_seeds", "pot_up", "transplant", "check_batch"
|
||||
title: str
|
||||
detail: str
|
||||
due_date: date
|
||||
days_away: int # negative = overdue
|
||||
urgency: str # "overdue", "today", "week", "month"
|
||||
variety_color: str
|
||||
batch_id: Optional[int] = None
|
||||
variety_id: Optional[int] = None
|
||||
|
||||
|
||||
class TimelineEntry(BaseModel):
|
||||
variety_id: int
|
||||
name: str
|
||||
full_name: str
|
||||
color: str
|
||||
start_day: Optional[int] = None # day of year
|
||||
greenhouse_day: Optional[int] = None
|
||||
garden_day: Optional[int] = None
|
||||
end_day: Optional[int] = None # approx harvest / end of season
|
||||
|
||||
|
||||
class DashboardOut(BaseModel):
|
||||
tasks_overdue: List[Task]
|
||||
tasks_today: List[Task]
|
||||
tasks_week: List[Task]
|
||||
tasks_month: List[Task]
|
||||
active_batches: List[BatchOut]
|
||||
timeline: List[TimelineEntry]
|
||||
stats: dict
|
||||
last_frost_date: Optional[date]
|
||||
location_name: Optional[str]
|
||||
Reference in New Issue
Block a user