Files
takeyourmeds/server/schemas.py
T
Frank Schwenk 88bdf6f34b feat: overhaul with modular API, agent endpoints, migrations, backup and tests
- Split monolithic app.py into server/api/ routers
- Add Pydantic schemas for input validation
- Add /agent/* API with separate AGENT_TOKEN auth
- Replace static schema.sql with versioned migrations (datenerhaltend)
- Add tools/backup_db.py for SQLite backups
- Add Dockerfile HEALTHCHECK and compose.yml AGENT_TOKEN env
- Add pytest tests for user and agent API
- Update README with API docs and deployment safety notes
- Bump version to 1.2.0
2026-09-21 12:46:44 +02:00

56 lines
1.3 KiB
Python

from __future__ import annotations
from datetime import date
from enum import Enum
from pydantic import BaseModel, Field, field_validator
class LogStatus(str, Enum):
taken = "taken"
missed = "missed"
snoozed = "snoozed"
class PinLogin(BaseModel):
pin: str = Field(..., min_length=3, max_length=12)
class LogEntry(BaseModel):
slot_id: str = Field(..., min_length=1, max_length=64)
status: LogStatus = LogStatus.taken
day: date | None = None
logged_at: str | None = None
source: str = "app"
class SnoozeRequest(BaseModel):
slot_id: str = Field(..., min_length=1, max_length=64)
minutes: int = Field(...)
@field_validator("minutes")
@classmethod
def allowed_snooze(cls, v: int) -> int:
if v not in (15, 30):
raise ValueError("minutes must be 15 or 30")
return v
class PushSubscribe(BaseModel):
subscription: dict
class AgentLogEntry(BaseModel):
slot_id: str = Field(..., min_length=1, max_length=64)
status: LogStatus = LogStatus.taken
day: date | None = None
logged_at: str | None = None
source: str = "agent"
class AgentNotifyRequest(BaseModel):
title: str = Field(..., min_length=1, max_length=120)
body: str = Field(..., min_length=1, max_length=512)
slot_id: str | None = None
tag: str | None = None