- Users table with email/bcrypt-hashed password; register and login via /auth/ endpoints - JWT tokens (30-day expiry) stored in localStorage; all API routes require Bearer auth - All data (varieties, batches, settings, notification logs) scoped to the authenticated user - Login/register screen overlays the app; sidebar shows user email and logout button - Scheduler sends daily ntfy summaries for every configured user - DB schema rewritten for multi-user; SECRET_KEY added to env Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
150 lines
3.4 KiB
Python
150 lines
3.4 KiB
Python
from __future__ import annotations
|
|
from datetime import date, datetime
|
|
from typing import Optional, List
|
|
from pydantic import BaseModel, EmailStr
|
|
from models import Category, SunRequirement, WaterNeeds, BatchStatus
|
|
|
|
|
|
# --- Auth ---
|
|
|
|
class UserCreate(BaseModel):
|
|
email: EmailStr
|
|
password: str
|
|
|
|
|
|
class UserLogin(BaseModel):
|
|
email: EmailStr
|
|
password: str
|
|
|
|
|
|
class UserOut(BaseModel):
|
|
id: int
|
|
email: str
|
|
created_at: Optional[datetime] = None
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class Token(BaseModel):
|
|
access_token: str
|
|
token_type: str
|
|
|
|
|
|
# --- 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
|
|
ntfy_username: Optional[str] = None
|
|
ntfy_password: Optional[str] = None
|
|
ntfy_api_key: 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]
|