auto-assign filter priority (max+10) on create
New filter rules no longer default to priority 100. Server picks max(priority)+10 per account when client sends priority=None (or 10 if the account has no rules yet), and the UI pre-fills the input with the next value instead of a fixed 100. Avoids ambiguous ordering when multiple rules end up with the same priority. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+12
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user