Files
paliad/internal/handlers/fristenrechner_followups.go
mAi 7ea415145f
Some checks failed
Paliad CI gate / build (push) Has been cancelled
Paliad CI gate / test-go (push) Has been cancelled
Paliad CI gate / deploy (push) Has been cancelled
feat(fristenrechner): Slice S1 — backend ?kind=events + /follow-ups (m/paliad#146)
Two additive endpoints behind the Fristenrechner overhaul (design
§6.1 + §6.2 in docs/design-fristenrechner-overhaul-2026-05-26.md):

1. GET /api/tools/fristenrechner/search?kind=events — returns
   procedural_events rows directly (not aggregated concept-cards),
   one hit per (event × proceeding_type) tuple. Trigram-ranked
   against name / name_en / code. Filters: jurisdiction, proc,
   event_kind, party. Powers Mode A's result list and Mode B's R4
   landing chips. Default search shape unchanged.

2. GET /api/tools/fristenrechner/follow-ups?event=...&trigger_date=...
   — given a trigger event (by code or uuid) + date, returns the
   immediate follow-up sequencing rules with computed due dates
   via litigationplanner.CalculateRule. Each row carries priority /
   primary_party / is_court_set / is_spawn / has_condition / legal
   source / spawn target so the result view can group into
   Mandatory / Recommended / Optional / Conditional with the
   SPAWNED badge. party=claimant|defendant filters keep "both"
   rules visible.

No schema changes — unified sequencing_rules already has every
column needed. Live-DB tests cover the SoC follow-up shape, party
narrowing, jurisdiction + event_kind filters, and the unknown-
event sentinel.
2026-05-26 22:01:10 +02:00

66 lines
2.1 KiB
Go

package handlers
import (
"errors"
"net/http"
"time"
"mgit.msbls.de/m/paliad/internal/services"
)
// GET /api/tools/fristenrechner/follow-ups — given a trigger event and
// a trigger date, return the immediate follow-up sequencing rules with
// their computed due dates (Fristenrechner overhaul S1, design §6.2).
//
// Query params:
// event - procedural_events.code OR procedural_events.id
// (uuid) OR sequencing_rules.id (uuid). Required.
// trigger_date - YYYY-MM-DD. Defaults to today when omitted, so the
// frontend can show a result preview before the user
// commits a date.
// party - "claimant" | "defendant" | "court" | "both".
// Optional; narrows follow-ups by primary_party
// (claimant/defendant filters keep "both" rules
// visible — they're bilateral procedural moves).
// court_id - paliad.courts.id (uuid); selects the holiday
// calendar for date adjustment. Optional.
func handleFristenrechnerFollowUps(w http.ResponseWriter, r *http.Request) {
if dbSvc == nil || dbSvc.fristenrechner == nil {
writeJSON(w, http.StatusServiceUnavailable, map[string]string{
"error": "Fristenrechner ist vorübergehend nicht verfügbar (keine Datenbank).",
})
return
}
q := r.URL.Query()
eventRef := q.Get("event")
if eventRef == "" {
writeJSON(w, http.StatusBadRequest, map[string]string{
"error": "event ist erforderlich (procedural_events.code oder id)",
})
return
}
triggerDate := q.Get("trigger_date")
if triggerDate == "" {
triggerDate = time.Now().Format("2006-01-02")
}
resp, err := dbSvc.fristenrechner.LookupFollowUps(
r.Context(),
eventRef,
triggerDate,
q.Get("party"),
q.Get("court_id"),
)
if err != nil {
if errors.Is(err, services.ErrUnknownProceduralEvent) {
writeJSON(w, http.StatusNotFound, map[string]string{
"error": "Unbekanntes Ereignis: " + eventRef,
})
return
}
writeJSON(w, http.StatusBadRequest, map[string]string{"error": err.Error()})
return
}
writeJSON(w, http.StatusOK, resp)
}