diff --git a/app/routers/filters.py b/app/routers/filters.py index fcaf46d..362b7ef 100644 --- a/app/routers/filters.py +++ b/app/routers/filters.py @@ -1,4 +1,5 @@ from fastapi import APIRouter, Depends, HTTPException +from sqlalchemy import func from sqlalchemy.orm import Session import logging @@ -52,10 +53,20 @@ def create_filter(data: FilterRuleCreate, db: Session = Depends(get_db)): if not account: raise HTTPException(404, "Konto nicht gefunden") + if data.priority is None: + # Ans Ende einsortieren: max(priority) + 10 für dieses Konto. Falls noch + # keine Regel existiert, starten wir bei 10. + current_max = db.query(func.max(FilterRule.priority)).filter( + FilterRule.account_id == data.account_id + ).scalar() + priority = (current_max + 10) if current_max is not None else 10 + else: + priority = data.priority + rule = FilterRule( account_id=data.account_id, name=data.name, - priority=data.priority, + priority=priority, enabled=data.enabled, stop_processing=data.stop_processing, source_folder=data.source_folder, diff --git a/app/schemas/schemas.py b/app/schemas/schemas.py index c935f7b..1f501b3 100644 --- a/app/schemas/schemas.py +++ b/app/schemas/schemas.py @@ -41,7 +41,7 @@ class FilterActionResponse(FilterActionCreate): class FilterRuleCreate(BaseModel): name: str account_id: int - priority: int = 100 + priority: int | None = None # None → automatisch ans Ende einsortieren (max+10) enabled: bool = True stop_processing: bool = False source_folder: str = "INBOX" diff --git a/app/templates/filters.html b/app/templates/filters.html index 22e6719..34cee8a 100644 --- a/app/templates/filters.html +++ b/app/templates/filters.html @@ -29,8 +29,8 @@