Files
aurum/backend/app/schemas/category.py
ZProger 09a0e383e0 feat: idle cash alert and category hierarchy (subcategories)
Two of the four ideas picked from the Maybe/Sure feature audit:

- Idle cash: a 5th proactive alert flags a depository account (checking/
  savings/cash) sitting at or above a configurable balance with no
  transaction touching it for a configurable number of days.
- Category hierarchy: categories can now have one level of subcategories
  (Groceries -> Alcohol). Dashboard/report aggregations roll a
  subcategory's spending into its parent's slice.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 02:27:46 +03:00

37 lines
1.1 KiB
Python

from pydantic import BaseModel, ConfigDict, Field
from app.models.enums import CategoryKind
class CategoryBase(BaseModel):
name: str = Field(min_length=1, max_length=100)
kind: CategoryKind
icon: str | None = None
color: str = Field(pattern=r"^#[0-9a-fA-F]{6}$")
sort_order: int = 0
# Subcategory parent, one level deep only — routes/categories.py rejects
# a parent that itself already has a parent.
parent_id: int | None = None
class CategoryCreate(CategoryBase):
pass
class CategoryUpdate(BaseModel):
name: str | None = Field(default=None, min_length=1, max_length=100)
icon: str | None = None
color: str | None = Field(default=None, pattern=r"^#[0-9a-fA-F]{6}$")
sort_order: int | None = None
# The route uses exclude_unset=True, so sending parent_id explicitly as
# null (as opposed to omitting the field) is what turns a subcategory
# back into a top-level category.
parent_id: int | None = None
class CategoryRead(CategoryBase):
model_config = ConfigDict(from_attributes=True)
id: int
is_default: bool