Compare commits
8 Commits
mai/knuth/
...
mai/pike/p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fa7d90050 | ||
|
|
0fac764211 | ||
|
|
78c511bd1f | ||
|
|
ca572d3289 | ||
|
|
b2b3e04d05 | ||
|
|
5758e2c37f | ||
|
|
9bd8cc9e07 | ||
|
|
e53e1389f9 |
@@ -7,6 +7,7 @@ PORT=8080
|
|||||||
# Supabase (required for database access)
|
# Supabase (required for database access)
|
||||||
SUPABASE_URL=
|
SUPABASE_URL=
|
||||||
SUPABASE_ANON_KEY=
|
SUPABASE_ANON_KEY=
|
||||||
|
SUPABASE_SERVICE_KEY=
|
||||||
|
|
||||||
# Claude API (required for AI features)
|
# Claude API (required for AI features)
|
||||||
ANTHROPIC_API_KEY=
|
ANTHROPIC_API_KEY=
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func main() {
|
|||||||
defer database.Close()
|
defer database.Close()
|
||||||
|
|
||||||
authMW := auth.NewMiddleware(cfg.SupabaseJWTSecret, database)
|
authMW := auth.NewMiddleware(cfg.SupabaseJWTSecret, database)
|
||||||
handler := router.New(database, authMW)
|
handler := router.New(database, authMW, cfg)
|
||||||
|
|
||||||
log.Printf("Starting KanzlAI API server on :%s", cfg.Port)
|
log.Printf("Starting KanzlAI API server on :%s", cfg.Port)
|
||||||
if err := http.ListenAndServe(":"+cfg.Port, handler); err != nil {
|
if err := http.ListenAndServe(":"+cfg.Port, handler); err != nil {
|
||||||
|
|||||||
@@ -3,8 +3,14 @@ module mgit.msbls.de/m/KanzlAI-mGMT
|
|||||||
go 1.25.5
|
go 1.25.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/anthropics/anthropic-sdk-go v1.27.1 // indirect
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
|
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/jmoiron/sqlx v1.4.0 // indirect
|
github.com/jmoiron/sqlx v1.4.0 // indirect
|
||||||
github.com/lib/pq v1.12.0 // indirect
|
github.com/lib/pq v1.12.0 // indirect
|
||||||
|
github.com/tidwall/gjson v1.18.0 // indirect
|
||||||
|
github.com/tidwall/match v1.1.1 // indirect
|
||||||
|
github.com/tidwall/pretty v1.2.1 // indirect
|
||||||
|
github.com/tidwall/sjson v1.2.5 // indirect
|
||||||
|
golang.org/x/sync v0.16.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||||
|
github.com/anthropics/anthropic-sdk-go v1.27.1 h1:7DgMZ2Ng3C2mPzJGHA30NXQTZolcF07mHd0tGaLwfzk=
|
||||||
|
github.com/anthropics/anthropic-sdk-go v1.27.1/go.mod h1:qUKmaW+uuPB64iy1l+4kOSvaLqPXnHTTBKH6RVZ7q5Q=
|
||||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
|
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
||||||
@@ -10,3 +12,15 @@ github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
|||||||
github.com/lib/pq v1.12.0 h1:mC1zeiNamwKBecjHarAr26c/+d8V5w/u4J0I/yASbJo=
|
github.com/lib/pq v1.12.0 h1:mC1zeiNamwKBecjHarAr26c/+d8V5w/u4J0I/yASbJo=
|
||||||
github.com/lib/pq v1.12.0/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=
|
github.com/lib/pq v1.12.0/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
|
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||||
|
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
|
||||||
|
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||||
|
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||||
|
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||||
|
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||||
|
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
|
||||||
|
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||||
|
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
||||||
|
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||||
|
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
|
||||||
|
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Port string
|
Port string
|
||||||
DatabaseURL string
|
DatabaseURL string
|
||||||
SupabaseURL string
|
SupabaseURL string
|
||||||
SupabaseAnonKey string
|
SupabaseAnonKey string
|
||||||
|
SupabaseServiceKey string
|
||||||
SupabaseJWTSecret string
|
SupabaseJWTSecret string
|
||||||
AnthropicAPIKey string
|
AnthropicAPIKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load() (*Config, error) {
|
func Load() (*Config, error) {
|
||||||
@@ -19,7 +20,8 @@ func Load() (*Config, error) {
|
|||||||
Port: getEnv("PORT", "8080"),
|
Port: getEnv("PORT", "8080"),
|
||||||
DatabaseURL: os.Getenv("DATABASE_URL"),
|
DatabaseURL: os.Getenv("DATABASE_URL"),
|
||||||
SupabaseURL: os.Getenv("SUPABASE_URL"),
|
SupabaseURL: os.Getenv("SUPABASE_URL"),
|
||||||
SupabaseAnonKey: os.Getenv("SUPABASE_ANON_KEY"),
|
SupabaseAnonKey: os.Getenv("SUPABASE_ANON_KEY"),
|
||||||
|
SupabaseServiceKey: os.Getenv("SUPABASE_SERVICE_KEY"),
|
||||||
SupabaseJWTSecret: os.Getenv("SUPABASE_JWT_SECRET"),
|
SupabaseJWTSecret: os.Getenv("SUPABASE_JWT_SECRET"),
|
||||||
AnthropicAPIKey: os.Getenv("ANTHROPIC_API_KEY"),
|
AnthropicAPIKey: os.Getenv("ANTHROPIC_API_KEY"),
|
||||||
}
|
}
|
||||||
|
|||||||
115
backend/internal/handlers/ai.go
Normal file
115
backend/internal/handlers/ai.go
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
|
|
||||||
|
"mgit.msbls.de/m/KanzlAI-mGMT/internal/services"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AIHandler struct {
|
||||||
|
ai *services.AIService
|
||||||
|
db *sqlx.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAIHandler(ai *services.AIService, db *sqlx.DB) *AIHandler {
|
||||||
|
return &AIHandler{ai: ai, db: db}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExtractDeadlines handles POST /api/ai/extract-deadlines
|
||||||
|
// Accepts either multipart/form-data with a "file" PDF field, or JSON {"text": "..."}.
|
||||||
|
func (h *AIHandler) ExtractDeadlines(w http.ResponseWriter, r *http.Request) {
|
||||||
|
contentType := r.Header.Get("Content-Type")
|
||||||
|
|
||||||
|
var pdfData []byte
|
||||||
|
var text string
|
||||||
|
|
||||||
|
// Check if multipart (PDF upload)
|
||||||
|
if len(contentType) >= 9 && contentType[:9] == "multipart" {
|
||||||
|
if err := r.ParseMultipartForm(32 << 20); err != nil { // 32MB max
|
||||||
|
writeError(w, http.StatusBadRequest, "failed to parse multipart form")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
file, _, err := r.FormFile("file")
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusBadRequest, "missing 'file' field in multipart form")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
pdfData, err = io.ReadAll(file)
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusBadRequest, "failed to read uploaded file")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Assume JSON body
|
||||||
|
var body struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||||
|
writeError(w, http.StatusBadRequest, "invalid request body")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
text = body.Text
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(pdfData) == 0 && text == "" {
|
||||||
|
writeError(w, http.StatusBadRequest, "provide either a PDF file or text")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
deadlines, err := h.ai.ExtractDeadlines(r.Context(), pdfData, text)
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusInternalServerError, "AI extraction failed: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
|
"deadlines": deadlines,
|
||||||
|
"count": len(deadlines),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SummarizeCase handles POST /api/ai/summarize-case
|
||||||
|
// Accepts JSON {"case_id": "uuid"}.
|
||||||
|
func (h *AIHandler) SummarizeCase(w http.ResponseWriter, r *http.Request) {
|
||||||
|
tenantID, err := resolveTenant(r, h.db)
|
||||||
|
if err != nil {
|
||||||
|
handleTenantError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var body struct {
|
||||||
|
CaseID string `json:"case_id"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||||
|
writeError(w, http.StatusBadRequest, "invalid request body")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if body.CaseID == "" {
|
||||||
|
writeError(w, http.StatusBadRequest, "case_id is required")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
caseID, err := parseUUID(body.CaseID)
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusBadRequest, "invalid case_id")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
summary, err := h.ai.SummarizeCase(r.Context(), tenantID, caseID)
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusInternalServerError, "AI summarization failed: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeJSON(w, http.StatusOK, map[string]string{
|
||||||
|
"case_id": caseID.String(),
|
||||||
|
"summary": summary,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -203,14 +203,3 @@ func (h *AppointmentHandler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeJSON(w http.ResponseWriter, status int, v any) {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(status)
|
|
||||||
json.NewEncoder(w).Encode(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeError(w http.ResponseWriter, status int, msg string) {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(status)
|
|
||||||
json.NewEncoder(w).Encode(map[string]string{"error": msg})
|
|
||||||
}
|
|
||||||
|
|||||||
32
backend/internal/handlers/dashboard.go
Normal file
32
backend/internal/handlers/dashboard.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"mgit.msbls.de/m/KanzlAI-mGMT/internal/auth"
|
||||||
|
"mgit.msbls.de/m/KanzlAI-mGMT/internal/services"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DashboardHandler struct {
|
||||||
|
svc *services.DashboardService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDashboardHandler(svc *services.DashboardService) *DashboardHandler {
|
||||||
|
return &DashboardHandler{svc: svc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *DashboardHandler) Get(w http.ResponseWriter, r *http.Request) {
|
||||||
|
tenantID, ok := auth.TenantFromContext(r.Context())
|
||||||
|
if !ok {
|
||||||
|
writeError(w, http.StatusForbidden, "missing tenant")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := h.svc.Get(r.Context(), tenantID)
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeJSON(w, http.StatusOK, data)
|
||||||
|
}
|
||||||
@@ -39,6 +39,17 @@ func (h *DeadlineRuleHandlers) List(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJSON(w, http.StatusOK, rules)
|
writeJSON(w, http.StatusOK, rules)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListProceedingTypes handles GET /api/proceeding-types
|
||||||
|
func (h *DeadlineRuleHandlers) ListProceedingTypes(w http.ResponseWriter, r *http.Request) {
|
||||||
|
types, err := h.rules.ListProceedingTypes()
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusInternalServerError, "failed to list proceeding types")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeJSON(w, http.StatusOK, types)
|
||||||
|
}
|
||||||
|
|
||||||
// GetRuleTree handles GET /api/deadline-rules/{type}
|
// GetRuleTree handles GET /api/deadline-rules/{type}
|
||||||
// {type} is the proceeding type code (e.g., "INF", "REV")
|
// {type} is the proceeding type code (e.g., "INF", "REV")
|
||||||
func (h *DeadlineRuleHandlers) GetRuleTree(w http.ResponseWriter, r *http.Request) {
|
func (h *DeadlineRuleHandlers) GetRuleTree(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -20,6 +20,23 @@ func NewDeadlineHandlers(ds *services.DeadlineService, db *sqlx.DB) *DeadlineHan
|
|||||||
return &DeadlineHandlers{deadlines: ds, db: db}
|
return &DeadlineHandlers{deadlines: ds, db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListAll handles GET /api/deadlines
|
||||||
|
func (h *DeadlineHandlers) ListAll(w http.ResponseWriter, r *http.Request) {
|
||||||
|
tenantID, err := resolveTenant(r, h.db)
|
||||||
|
if err != nil {
|
||||||
|
handleTenantError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
deadlines, err := h.deadlines.ListAll(tenantID)
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusInternalServerError, "failed to list deadlines")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeJSON(w, http.StatusOK, deadlines)
|
||||||
|
}
|
||||||
|
|
||||||
// ListForCase handles GET /api/cases/{caseID}/deadlines
|
// ListForCase handles GET /api/cases/{caseID}/deadlines
|
||||||
func (h *DeadlineHandlers) ListForCase(w http.ResponseWriter, r *http.Request) {
|
func (h *DeadlineHandlers) ListForCase(w http.ResponseWriter, r *http.Request) {
|
||||||
tenantID, err := resolveTenant(r, h.db)
|
tenantID, err := resolveTenant(r, h.db)
|
||||||
|
|||||||
183
backend/internal/handlers/documents.go
Normal file
183
backend/internal/handlers/documents.go
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"mgit.msbls.de/m/KanzlAI-mGMT/internal/auth"
|
||||||
|
"mgit.msbls.de/m/KanzlAI-mGMT/internal/services"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
const maxUploadSize = 50 << 20 // 50 MB
|
||||||
|
|
||||||
|
type DocumentHandler struct {
|
||||||
|
svc *services.DocumentService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDocumentHandler(svc *services.DocumentService) *DocumentHandler {
|
||||||
|
return &DocumentHandler{svc: svc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *DocumentHandler) ListByCase(w http.ResponseWriter, r *http.Request) {
|
||||||
|
tenantID, ok := auth.TenantFromContext(r.Context())
|
||||||
|
if !ok {
|
||||||
|
writeError(w, http.StatusForbidden, "missing tenant")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
caseID, err := uuid.Parse(r.PathValue("id"))
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusBadRequest, "invalid case ID")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
docs, err := h.svc.ListByCase(r.Context(), tenantID, caseID)
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
|
"documents": docs,
|
||||||
|
"total": len(docs),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *DocumentHandler) Upload(w http.ResponseWriter, r *http.Request) {
|
||||||
|
tenantID, ok := auth.TenantFromContext(r.Context())
|
||||||
|
if !ok {
|
||||||
|
writeError(w, http.StatusForbidden, "missing tenant")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userID, _ := auth.UserFromContext(r.Context())
|
||||||
|
|
||||||
|
caseID, err := uuid.Parse(r.PathValue("id"))
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusBadRequest, "invalid case ID")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Body = http.MaxBytesReader(w, r.Body, maxUploadSize)
|
||||||
|
if err := r.ParseMultipartForm(maxUploadSize); err != nil {
|
||||||
|
writeError(w, http.StatusBadRequest, "file too large or invalid multipart form")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
file, header, err := r.FormFile("file")
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusBadRequest, "missing file field")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
title := r.FormValue("title")
|
||||||
|
if title == "" {
|
||||||
|
title = header.Filename
|
||||||
|
}
|
||||||
|
|
||||||
|
contentType := header.Header.Get("Content-Type")
|
||||||
|
if contentType == "" {
|
||||||
|
contentType = "application/octet-stream"
|
||||||
|
}
|
||||||
|
|
||||||
|
input := services.CreateDocumentInput{
|
||||||
|
Title: title,
|
||||||
|
DocType: r.FormValue("doc_type"),
|
||||||
|
Filename: header.Filename,
|
||||||
|
ContentType: contentType,
|
||||||
|
Size: int(header.Size),
|
||||||
|
Data: file,
|
||||||
|
}
|
||||||
|
|
||||||
|
doc, err := h.svc.Create(r.Context(), tenantID, caseID, userID, input)
|
||||||
|
if err != nil {
|
||||||
|
if err.Error() == "case not found" {
|
||||||
|
writeError(w, http.StatusNotFound, "case not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeJSON(w, http.StatusCreated, doc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *DocumentHandler) Download(w http.ResponseWriter, r *http.Request) {
|
||||||
|
tenantID, ok := auth.TenantFromContext(r.Context())
|
||||||
|
if !ok {
|
||||||
|
writeError(w, http.StatusForbidden, "missing tenant")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
docID, err := uuid.Parse(r.PathValue("docId"))
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusBadRequest, "invalid document ID")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
body, contentType, title, err := h.svc.Download(r.Context(), tenantID, docID)
|
||||||
|
if err != nil {
|
||||||
|
if err.Error() == "document not found" || err.Error() == "document has no file" {
|
||||||
|
writeError(w, http.StatusNotFound, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer body.Close()
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", contentType)
|
||||||
|
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, title))
|
||||||
|
io.Copy(w, body)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *DocumentHandler) GetMeta(w http.ResponseWriter, r *http.Request) {
|
||||||
|
tenantID, ok := auth.TenantFromContext(r.Context())
|
||||||
|
if !ok {
|
||||||
|
writeError(w, http.StatusForbidden, "missing tenant")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
docID, err := uuid.Parse(r.PathValue("docId"))
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusBadRequest, "invalid document ID")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
doc, err := h.svc.GetByID(r.Context(), tenantID, docID)
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if doc == nil {
|
||||||
|
writeError(w, http.StatusNotFound, "document not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeJSON(w, http.StatusOK, doc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *DocumentHandler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
|
tenantID, ok := auth.TenantFromContext(r.Context())
|
||||||
|
if !ok {
|
||||||
|
writeError(w, http.StatusForbidden, "missing tenant")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userID, _ := auth.UserFromContext(r.Context())
|
||||||
|
|
||||||
|
docID, err := uuid.Parse(r.PathValue("docId"))
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusBadRequest, "invalid document ID")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := h.svc.Delete(r.Context(), tenantID, docID, userID); err != nil {
|
||||||
|
writeError(w, http.StatusNotFound, "document not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
|
||||||
|
}
|
||||||
@@ -83,3 +83,8 @@ func handleTenantError(w http.ResponseWriter, err error) {
|
|||||||
func parsePathUUID(r *http.Request, key string) (uuid.UUID, error) {
|
func parsePathUUID(r *http.Request, key string) (uuid.UUID, error) {
|
||||||
return uuid.Parse(r.PathValue(key))
|
return uuid.Parse(r.PathValue(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parseUUID parses a UUID string
|
||||||
|
func parseUUID(s string) (uuid.UUID, error) {
|
||||||
|
return uuid.Parse(s)
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ import (
|
|||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
|
|
||||||
"mgit.msbls.de/m/KanzlAI-mGMT/internal/auth"
|
"mgit.msbls.de/m/KanzlAI-mGMT/internal/auth"
|
||||||
|
"mgit.msbls.de/m/KanzlAI-mGMT/internal/config"
|
||||||
"mgit.msbls.de/m/KanzlAI-mGMT/internal/handlers"
|
"mgit.msbls.de/m/KanzlAI-mGMT/internal/handlers"
|
||||||
"mgit.msbls.de/m/KanzlAI-mGMT/internal/services"
|
"mgit.msbls.de/m/KanzlAI-mGMT/internal/services"
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
|
func New(db *sqlx.DB, authMW *auth.Middleware, cfg *config.Config) http.Handler {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
@@ -23,10 +24,21 @@ func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
|
|||||||
deadlineSvc := services.NewDeadlineService(db)
|
deadlineSvc := services.NewDeadlineService(db)
|
||||||
deadlineRuleSvc := services.NewDeadlineRuleService(db)
|
deadlineRuleSvc := services.NewDeadlineRuleService(db)
|
||||||
calculator := services.NewDeadlineCalculator(holidaySvc)
|
calculator := services.NewDeadlineCalculator(holidaySvc)
|
||||||
|
storageCli := services.NewStorageClient(cfg.SupabaseURL, cfg.SupabaseServiceKey)
|
||||||
|
documentSvc := services.NewDocumentService(db, storageCli)
|
||||||
|
|
||||||
|
// AI service (optional — only if API key is configured)
|
||||||
|
var aiH *handlers.AIHandler
|
||||||
|
if cfg.AnthropicAPIKey != "" {
|
||||||
|
aiSvc := services.NewAIService(cfg.AnthropicAPIKey, db)
|
||||||
|
aiH = handlers.NewAIHandler(aiSvc, db)
|
||||||
|
}
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
tenantResolver := auth.NewTenantResolver(tenantSvc)
|
tenantResolver := auth.NewTenantResolver(tenantSvc)
|
||||||
|
|
||||||
|
dashboardSvc := services.NewDashboardService(db)
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
tenantH := handlers.NewTenantHandler(tenantSvc)
|
tenantH := handlers.NewTenantHandler(tenantSvc)
|
||||||
caseH := handlers.NewCaseHandler(caseSvc)
|
caseH := handlers.NewCaseHandler(caseSvc)
|
||||||
@@ -35,6 +47,8 @@ func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
|
|||||||
deadlineH := handlers.NewDeadlineHandlers(deadlineSvc, db)
|
deadlineH := handlers.NewDeadlineHandlers(deadlineSvc, db)
|
||||||
ruleH := handlers.NewDeadlineRuleHandlers(deadlineRuleSvc)
|
ruleH := handlers.NewDeadlineRuleHandlers(deadlineRuleSvc)
|
||||||
calcH := handlers.NewCalculateHandlers(calculator, deadlineRuleSvc)
|
calcH := handlers.NewCalculateHandlers(calculator, deadlineRuleSvc)
|
||||||
|
dashboardH := handlers.NewDashboardHandler(dashboardSvc)
|
||||||
|
docH := handlers.NewDocumentHandler(documentSvc)
|
||||||
|
|
||||||
// Public routes
|
// Public routes
|
||||||
mux.HandleFunc("GET /health", handleHealth(db))
|
mux.HandleFunc("GET /health", handleHealth(db))
|
||||||
@@ -67,6 +81,7 @@ func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
|
|||||||
scoped.HandleFunc("DELETE /api/parties/{partyId}", partyH.Delete)
|
scoped.HandleFunc("DELETE /api/parties/{partyId}", partyH.Delete)
|
||||||
|
|
||||||
// Deadlines
|
// Deadlines
|
||||||
|
scoped.HandleFunc("GET /api/deadlines", deadlineH.ListAll)
|
||||||
scoped.HandleFunc("GET /api/cases/{caseID}/deadlines", deadlineH.ListForCase)
|
scoped.HandleFunc("GET /api/cases/{caseID}/deadlines", deadlineH.ListForCase)
|
||||||
scoped.HandleFunc("POST /api/cases/{caseID}/deadlines", deadlineH.Create)
|
scoped.HandleFunc("POST /api/cases/{caseID}/deadlines", deadlineH.Create)
|
||||||
scoped.HandleFunc("PUT /api/deadlines/{deadlineID}", deadlineH.Update)
|
scoped.HandleFunc("PUT /api/deadlines/{deadlineID}", deadlineH.Update)
|
||||||
@@ -76,6 +91,7 @@ func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
|
|||||||
// Deadline rules (reference data)
|
// Deadline rules (reference data)
|
||||||
scoped.HandleFunc("GET /api/deadline-rules", ruleH.List)
|
scoped.HandleFunc("GET /api/deadline-rules", ruleH.List)
|
||||||
scoped.HandleFunc("GET /api/deadline-rules/{type}", ruleH.GetRuleTree)
|
scoped.HandleFunc("GET /api/deadline-rules/{type}", ruleH.GetRuleTree)
|
||||||
|
scoped.HandleFunc("GET /api/proceeding-types", ruleH.ListProceedingTypes)
|
||||||
|
|
||||||
// Deadline calculator
|
// Deadline calculator
|
||||||
scoped.HandleFunc("POST /api/deadlines/calculate", calcH.Calculate)
|
scoped.HandleFunc("POST /api/deadlines/calculate", calcH.Calculate)
|
||||||
@@ -86,8 +102,21 @@ func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
|
|||||||
scoped.HandleFunc("PUT /api/appointments/{id}", apptH.Update)
|
scoped.HandleFunc("PUT /api/appointments/{id}", apptH.Update)
|
||||||
scoped.HandleFunc("DELETE /api/appointments/{id}", apptH.Delete)
|
scoped.HandleFunc("DELETE /api/appointments/{id}", apptH.Delete)
|
||||||
|
|
||||||
// Placeholder routes for future phases
|
// Dashboard
|
||||||
scoped.HandleFunc("GET /api/documents", placeholder("documents"))
|
scoped.HandleFunc("GET /api/dashboard", dashboardH.Get)
|
||||||
|
|
||||||
|
// Documents
|
||||||
|
scoped.HandleFunc("GET /api/cases/{id}/documents", docH.ListByCase)
|
||||||
|
scoped.HandleFunc("POST /api/cases/{id}/documents", docH.Upload)
|
||||||
|
scoped.HandleFunc("GET /api/documents/{docId}", docH.Download)
|
||||||
|
scoped.HandleFunc("GET /api/documents/{docId}/meta", docH.GetMeta)
|
||||||
|
scoped.HandleFunc("DELETE /api/documents/{docId}", docH.Delete)
|
||||||
|
|
||||||
|
// AI endpoints
|
||||||
|
if aiH != nil {
|
||||||
|
scoped.HandleFunc("POST /api/ai/extract-deadlines", aiH.ExtractDeadlines)
|
||||||
|
scoped.HandleFunc("POST /api/ai/summarize-case", aiH.SummarizeCase)
|
||||||
|
}
|
||||||
|
|
||||||
// Wire: auth -> tenant routes go directly, scoped routes get tenant resolver
|
// Wire: auth -> tenant routes go directly, scoped routes get tenant resolver
|
||||||
api.Handle("/api/", tenantResolver.Resolve(scoped))
|
api.Handle("/api/", tenantResolver.Resolve(scoped))
|
||||||
@@ -109,12 +138,3 @@ func handleHealth(db *sqlx.DB) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func placeholder(resource string) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
json.NewEncoder(w).Encode(map[string]string{
|
|
||||||
"status": "not_implemented",
|
|
||||||
"resource": resource,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
283
backend/internal/services/ai_service.go
Normal file
283
backend/internal/services/ai_service.go
Normal file
@@ -0,0 +1,283 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/anthropics/anthropic-sdk-go"
|
||||||
|
"github.com/anthropics/anthropic-sdk-go/option"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
|
|
||||||
|
"mgit.msbls.de/m/KanzlAI-mGMT/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AIService struct {
|
||||||
|
client anthropic.Client
|
||||||
|
db *sqlx.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAIService(apiKey string, db *sqlx.DB) *AIService {
|
||||||
|
client := anthropic.NewClient(option.WithAPIKey(apiKey))
|
||||||
|
return &AIService{client: client, db: db}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExtractedDeadline represents a deadline extracted by AI from a document.
|
||||||
|
type ExtractedDeadline struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
DueDate *string `json:"due_date"`
|
||||||
|
DurationValue int `json:"duration_value"`
|
||||||
|
DurationUnit string `json:"duration_unit"`
|
||||||
|
Timing string `json:"timing"`
|
||||||
|
TriggerEvent string `json:"trigger_event"`
|
||||||
|
RuleReference string `json:"rule_reference"`
|
||||||
|
Confidence float64 `json:"confidence"`
|
||||||
|
SourceQuote string `json:"source_quote"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type extractDeadlinesToolInput struct {
|
||||||
|
Deadlines []ExtractedDeadline `json:"deadlines"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var deadlineExtractionTool = anthropic.ToolParam{
|
||||||
|
Name: "extract_deadlines",
|
||||||
|
Description: anthropic.String("Extract all legal deadlines found in the document. Return each deadline with its details."),
|
||||||
|
InputSchema: anthropic.ToolInputSchemaParam{
|
||||||
|
Properties: map[string]any{
|
||||||
|
"deadlines": map[string]any{
|
||||||
|
"type": "array",
|
||||||
|
"description": "List of extracted deadlines",
|
||||||
|
"items": map[string]any{
|
||||||
|
"type": "object",
|
||||||
|
"properties": map[string]any{
|
||||||
|
"title": map[string]any{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Short title describing the deadline (e.g. 'Statement of Defence', 'Reply to Counterclaim')",
|
||||||
|
},
|
||||||
|
"due_date": map[string]any{
|
||||||
|
"type": []string{"string", "null"},
|
||||||
|
"description": "Absolute due date in YYYY-MM-DD format if determinable, null otherwise",
|
||||||
|
},
|
||||||
|
"duration_value": map[string]any{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Numeric duration value (e.g. 3 for '3 months')",
|
||||||
|
},
|
||||||
|
"duration_unit": map[string]any{
|
||||||
|
"type": "string",
|
||||||
|
"enum": []string{"days", "weeks", "months"},
|
||||||
|
"description": "Unit of the duration period",
|
||||||
|
},
|
||||||
|
"timing": map[string]any{
|
||||||
|
"type": "string",
|
||||||
|
"enum": []string{"after", "before"},
|
||||||
|
"description": "Whether the deadline is before or after the trigger event",
|
||||||
|
},
|
||||||
|
"trigger_event": map[string]any{
|
||||||
|
"type": "string",
|
||||||
|
"description": "The event that triggers this deadline (e.g. 'service of the Statement of Claim')",
|
||||||
|
},
|
||||||
|
"rule_reference": map[string]any{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Legal rule reference (e.g. 'Rule 23 RoP', 'Rule 222 RoP', '§ 276 ZPO')",
|
||||||
|
},
|
||||||
|
"confidence": map[string]any{
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"description": "Confidence score from 0.0 to 1.0",
|
||||||
|
},
|
||||||
|
"source_quote": map[string]any{
|
||||||
|
"type": "string",
|
||||||
|
"description": "The exact quote from the document where this deadline was found",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": []string{"title", "duration_value", "duration_unit", "timing", "trigger_event", "rule_reference", "confidence", "source_quote"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"deadlines"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const extractionSystemPrompt = `You are a legal deadline extraction assistant for German and UPC (Unified Patent Court) patent litigation.
|
||||||
|
|
||||||
|
Your task is to extract all legal deadlines, time limits, and procedural time periods from the provided document.
|
||||||
|
|
||||||
|
For each deadline found, extract:
|
||||||
|
- A clear title describing the deadline
|
||||||
|
- The absolute due date if it can be determined from the document
|
||||||
|
- The duration (value + unit: days/weeks/months)
|
||||||
|
- Whether it runs before or after a trigger event
|
||||||
|
- The trigger event that starts the deadline
|
||||||
|
- The legal rule reference (e.g. Rule 23 RoP, § 276 ZPO)
|
||||||
|
- Your confidence level (0.0-1.0) in the extraction
|
||||||
|
- The exact source quote from the document
|
||||||
|
|
||||||
|
Be thorough: extract every deadline mentioned, including conditional ones. If a deadline references another deadline (e.g. "within 2 months of the defence"), capture that relationship in the trigger_event field.
|
||||||
|
|
||||||
|
If the document contains no deadlines, return an empty list.`
|
||||||
|
|
||||||
|
// ExtractDeadlines sends a document (PDF or text) to Claude for deadline extraction.
|
||||||
|
func (s *AIService) ExtractDeadlines(ctx context.Context, pdfData []byte, text string) ([]ExtractedDeadline, error) {
|
||||||
|
var contentBlocks []anthropic.ContentBlockParamUnion
|
||||||
|
|
||||||
|
if len(pdfData) > 0 {
|
||||||
|
encoded := base64.StdEncoding.EncodeToString(pdfData)
|
||||||
|
contentBlocks = append(contentBlocks, anthropic.ContentBlockParamUnion{
|
||||||
|
OfDocument: &anthropic.DocumentBlockParam{
|
||||||
|
Source: anthropic.DocumentBlockParamSourceUnion{
|
||||||
|
OfBase64: &anthropic.Base64PDFSourceParam{
|
||||||
|
Data: encoded,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
contentBlocks = append(contentBlocks, anthropic.NewTextBlock("Extract all legal deadlines from this document."))
|
||||||
|
} else if text != "" {
|
||||||
|
contentBlocks = append(contentBlocks, anthropic.NewTextBlock("Extract all legal deadlines from the following text:\n\n"+text))
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("either pdf_data or text must be provided")
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := s.client.Messages.New(ctx, anthropic.MessageNewParams{
|
||||||
|
Model: anthropic.ModelClaudeSonnet4_5,
|
||||||
|
MaxTokens: 4096,
|
||||||
|
System: []anthropic.TextBlockParam{
|
||||||
|
{Text: extractionSystemPrompt},
|
||||||
|
},
|
||||||
|
Messages: []anthropic.MessageParam{
|
||||||
|
anthropic.NewUserMessage(contentBlocks...),
|
||||||
|
},
|
||||||
|
Tools: []anthropic.ToolUnionParam{
|
||||||
|
{OfTool: &deadlineExtractionTool},
|
||||||
|
},
|
||||||
|
ToolChoice: anthropic.ToolChoiceParamOfTool("extract_deadlines"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("claude API call: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the tool_use block in the response
|
||||||
|
for _, block := range msg.Content {
|
||||||
|
if block.Type == "tool_use" && block.Name == "extract_deadlines" {
|
||||||
|
var input extractDeadlinesToolInput
|
||||||
|
if err := json.Unmarshal(block.Input, &input); err != nil {
|
||||||
|
return nil, fmt.Errorf("parsing tool output: %w", err)
|
||||||
|
}
|
||||||
|
return input.Deadlines, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("no tool_use block in response")
|
||||||
|
}
|
||||||
|
|
||||||
|
const summarizeSystemPrompt = `You are a legal case summary assistant for German and UPC patent litigation case management.
|
||||||
|
|
||||||
|
Given a case's details, recent events, and deadlines, produce a concise 2-3 sentence summary of what matters right now. Focus on:
|
||||||
|
- The most urgent upcoming deadline
|
||||||
|
- Recent significant events
|
||||||
|
- The current procedural stage
|
||||||
|
|
||||||
|
Write in clear, professional language suitable for a lawyer reviewing their case list. Be specific about dates and deadlines.`
|
||||||
|
|
||||||
|
// SummarizeCase generates an AI summary for a case and caches it in the database.
|
||||||
|
func (s *AIService) SummarizeCase(ctx context.Context, tenantID, caseID uuid.UUID) (string, error) {
|
||||||
|
// Load case
|
||||||
|
var c models.Case
|
||||||
|
err := s.db.GetContext(ctx, &c,
|
||||||
|
"SELECT * FROM cases WHERE id = $1 AND tenant_id = $2", caseID, tenantID)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("loading case: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load recent events
|
||||||
|
var events []models.CaseEvent
|
||||||
|
if err := s.db.SelectContext(ctx, &events,
|
||||||
|
"SELECT * FROM case_events WHERE case_id = $1 AND tenant_id = $2 ORDER BY created_at DESC LIMIT 10",
|
||||||
|
caseID, tenantID); err != nil {
|
||||||
|
return "", fmt.Errorf("loading events: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load active deadlines
|
||||||
|
var deadlines []models.Deadline
|
||||||
|
if err := s.db.SelectContext(ctx, &deadlines,
|
||||||
|
"SELECT * FROM deadlines WHERE case_id = $1 AND tenant_id = $2 AND status = 'active' ORDER BY due_date ASC LIMIT 10",
|
||||||
|
caseID, tenantID); err != nil {
|
||||||
|
return "", fmt.Errorf("loading deadlines: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build context text
|
||||||
|
caseInfo := fmt.Sprintf("Case: %s — %s\nStatus: %s", c.CaseNumber, c.Title, c.Status)
|
||||||
|
if c.Court != nil {
|
||||||
|
caseInfo += fmt.Sprintf("\nCourt: %s", *c.Court)
|
||||||
|
}
|
||||||
|
if c.CourtRef != nil {
|
||||||
|
caseInfo += fmt.Sprintf("\nCourt Reference: %s", *c.CourtRef)
|
||||||
|
}
|
||||||
|
if c.CaseType != nil {
|
||||||
|
caseInfo += fmt.Sprintf("\nType: %s", *c.CaseType)
|
||||||
|
}
|
||||||
|
|
||||||
|
eventText := "\n\nRecent Events:"
|
||||||
|
if len(events) == 0 {
|
||||||
|
eventText += "\nNo events recorded."
|
||||||
|
}
|
||||||
|
for _, e := range events {
|
||||||
|
eventText += fmt.Sprintf("\n- [%s] %s", e.CreatedAt.Format("2006-01-02"), e.Title)
|
||||||
|
if e.Description != nil {
|
||||||
|
eventText += fmt.Sprintf(": %s", *e.Description)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deadlineText := "\n\nUpcoming Deadlines:"
|
||||||
|
if len(deadlines) == 0 {
|
||||||
|
deadlineText += "\nNo active deadlines."
|
||||||
|
}
|
||||||
|
for _, d := range deadlines {
|
||||||
|
deadlineText += fmt.Sprintf("\n- %s: due %s (status: %s)", d.Title, d.DueDate, d.Status)
|
||||||
|
if d.Description != nil {
|
||||||
|
deadlineText += fmt.Sprintf(" — %s", *d.Description)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prompt := caseInfo + eventText + deadlineText
|
||||||
|
|
||||||
|
msg, err := s.client.Messages.New(ctx, anthropic.MessageNewParams{
|
||||||
|
Model: anthropic.ModelClaudeSonnet4_5,
|
||||||
|
MaxTokens: 512,
|
||||||
|
System: []anthropic.TextBlockParam{
|
||||||
|
{Text: summarizeSystemPrompt},
|
||||||
|
},
|
||||||
|
Messages: []anthropic.MessageParam{
|
||||||
|
anthropic.NewUserMessage(anthropic.NewTextBlock("Summarize the current state of this case:\n\n" + prompt)),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("claude API call: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract text from response
|
||||||
|
var summary string
|
||||||
|
for _, block := range msg.Content {
|
||||||
|
if block.Type == "text" {
|
||||||
|
summary += block.Text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if summary == "" {
|
||||||
|
return "", fmt.Errorf("empty response from Claude")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache summary in database
|
||||||
|
_, err = s.db.ExecContext(ctx,
|
||||||
|
"UPDATE cases SET ai_summary = $1, updated_at = $2 WHERE id = $3 AND tenant_id = $4",
|
||||||
|
summary, time.Now(), caseID, tenantID)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("caching summary: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return summary, nil
|
||||||
|
}
|
||||||
109
backend/internal/services/ai_service_test.go
Normal file
109
backend/internal/services/ai_service_test.go
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDeadlineExtractionToolSchema(t *testing.T) {
|
||||||
|
// Verify the tool schema serializes correctly
|
||||||
|
data, err := json.Marshal(deadlineExtractionTool)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal tool: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var parsed map[string]any
|
||||||
|
if err := json.Unmarshal(data, &parsed); err != nil {
|
||||||
|
t.Fatalf("failed to unmarshal tool JSON: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if parsed["name"] != "extract_deadlines" {
|
||||||
|
t.Errorf("expected name 'extract_deadlines', got %v", parsed["name"])
|
||||||
|
}
|
||||||
|
|
||||||
|
schema, ok := parsed["input_schema"].(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("input_schema is not a map")
|
||||||
|
}
|
||||||
|
|
||||||
|
if schema["type"] != "object" {
|
||||||
|
t.Errorf("expected schema type 'object', got %v", schema["type"])
|
||||||
|
}
|
||||||
|
|
||||||
|
props, ok := schema["properties"].(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("properties is not a map")
|
||||||
|
}
|
||||||
|
|
||||||
|
deadlines, ok := props["deadlines"].(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("deadlines property is not a map")
|
||||||
|
}
|
||||||
|
|
||||||
|
if deadlines["type"] != "array" {
|
||||||
|
t.Errorf("expected deadlines type 'array', got %v", deadlines["type"])
|
||||||
|
}
|
||||||
|
|
||||||
|
items, ok := deadlines["items"].(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("items is not a map")
|
||||||
|
}
|
||||||
|
|
||||||
|
itemProps, ok := items["properties"].(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("item properties is not a map")
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedFields := []string{"title", "due_date", "duration_value", "duration_unit", "timing", "trigger_event", "rule_reference", "confidence", "source_quote"}
|
||||||
|
for _, field := range expectedFields {
|
||||||
|
if _, ok := itemProps[field]; !ok {
|
||||||
|
t.Errorf("missing expected field %q in item properties", field)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
required, ok := items["required"].([]any)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("required is not a list")
|
||||||
|
}
|
||||||
|
if len(required) != 8 {
|
||||||
|
t.Errorf("expected 8 required fields, got %d", len(required))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExtractedDeadlineJSON(t *testing.T) {
|
||||||
|
dueDate := "2026-04-15"
|
||||||
|
d := ExtractedDeadline{
|
||||||
|
Title: "Statement of Defence",
|
||||||
|
DueDate: &dueDate,
|
||||||
|
DurationValue: 3,
|
||||||
|
DurationUnit: "months",
|
||||||
|
Timing: "after",
|
||||||
|
TriggerEvent: "service of the Statement of Claim",
|
||||||
|
RuleReference: "Rule 23 RoP",
|
||||||
|
Confidence: 0.95,
|
||||||
|
SourceQuote: "The defendant shall file a defence within 3 months",
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := json.Marshal(d)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var parsed ExtractedDeadline
|
||||||
|
if err := json.Unmarshal(data, &parsed); err != nil {
|
||||||
|
t.Fatalf("failed to unmarshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if parsed.Title != d.Title {
|
||||||
|
t.Errorf("title mismatch: %q != %q", parsed.Title, d.Title)
|
||||||
|
}
|
||||||
|
if *parsed.DueDate != *d.DueDate {
|
||||||
|
t.Errorf("due_date mismatch: %q != %q", *parsed.DueDate, *d.DueDate)
|
||||||
|
}
|
||||||
|
if parsed.DurationValue != d.DurationValue {
|
||||||
|
t.Errorf("duration_value mismatch: %d != %d", parsed.DurationValue, d.DurationValue)
|
||||||
|
}
|
||||||
|
if parsed.Confidence != d.Confidence {
|
||||||
|
t.Errorf("confidence mismatch: %f != %f", parsed.Confidence, d.Confidence)
|
||||||
|
}
|
||||||
|
}
|
||||||
151
backend/internal/services/dashboard_service.go
Normal file
151
backend/internal/services/dashboard_service.go
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DashboardService struct {
|
||||||
|
db *sqlx.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDashboardService(db *sqlx.DB) *DashboardService {
|
||||||
|
return &DashboardService{db: db}
|
||||||
|
}
|
||||||
|
|
||||||
|
type DashboardData struct {
|
||||||
|
DeadlineSummary DeadlineSummary `json:"deadline_summary"`
|
||||||
|
CaseSummary CaseSummary `json:"case_summary"`
|
||||||
|
UpcomingDeadlines []UpcomingDeadline `json:"upcoming_deadlines"`
|
||||||
|
UpcomingAppointments []UpcomingAppointment `json:"upcoming_appointments"`
|
||||||
|
RecentActivity []RecentActivity `json:"recent_activity"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeadlineSummary struct {
|
||||||
|
OverdueCount int `json:"overdue_count" db:"overdue_count"`
|
||||||
|
DueThisWeek int `json:"due_this_week" db:"due_this_week"`
|
||||||
|
DueNextWeek int `json:"due_next_week" db:"due_next_week"`
|
||||||
|
OKCount int `json:"ok_count" db:"ok_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CaseSummary struct {
|
||||||
|
ActiveCount int `json:"active_count" db:"active_count"`
|
||||||
|
NewThisMonth int `json:"new_this_month" db:"new_this_month"`
|
||||||
|
ClosedCount int `json:"closed_count" db:"closed_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpcomingDeadline struct {
|
||||||
|
ID uuid.UUID `json:"id" db:"id"`
|
||||||
|
Title string `json:"title" db:"title"`
|
||||||
|
DueDate string `json:"due_date" db:"due_date"`
|
||||||
|
CaseNumber string `json:"case_number" db:"case_number"`
|
||||||
|
CaseTitle string `json:"case_title" db:"case_title"`
|
||||||
|
Status string `json:"status" db:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpcomingAppointment struct {
|
||||||
|
ID uuid.UUID `json:"id" db:"id"`
|
||||||
|
Title string `json:"title" db:"title"`
|
||||||
|
StartAt time.Time `json:"start_at" db:"start_at"`
|
||||||
|
CaseNumber *string `json:"case_number" db:"case_number"`
|
||||||
|
Location *string `json:"location" db:"location"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RecentActivity struct {
|
||||||
|
EventType *string `json:"event_type" db:"event_type"`
|
||||||
|
Title string `json:"title" db:"title"`
|
||||||
|
CaseNumber string `json:"case_number" db:"case_number"`
|
||||||
|
EventDate *time.Time `json:"event_date" db:"event_date"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DashboardService) Get(ctx context.Context, tenantID uuid.UUID) (*DashboardData, error) {
|
||||||
|
now := time.Now()
|
||||||
|
today := now.Format("2006-01-02")
|
||||||
|
endOfWeek := now.AddDate(0, 0, 7-int(now.Weekday())).Format("2006-01-02")
|
||||||
|
endOfNextWeek := now.AddDate(0, 0, 14-int(now.Weekday())).Format("2006-01-02")
|
||||||
|
in7Days := now.AddDate(0, 0, 7).Format("2006-01-02")
|
||||||
|
startOfMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).Format("2006-01-02")
|
||||||
|
|
||||||
|
data := &DashboardData{}
|
||||||
|
|
||||||
|
// Single query with CTEs for deadline + case summaries
|
||||||
|
summaryQuery := `
|
||||||
|
WITH deadline_stats AS (
|
||||||
|
SELECT
|
||||||
|
COUNT(*) FILTER (WHERE due_date < $2 AND status = 'pending') AS overdue_count,
|
||||||
|
COUNT(*) FILTER (WHERE due_date >= $2 AND due_date <= $3 AND status = 'pending') AS due_this_week,
|
||||||
|
COUNT(*) FILTER (WHERE due_date > $3 AND due_date <= $4 AND status = 'pending') AS due_next_week,
|
||||||
|
COUNT(*) FILTER (WHERE due_date > $4 AND status = 'pending') AS ok_count
|
||||||
|
FROM deadlines
|
||||||
|
WHERE tenant_id = $1
|
||||||
|
),
|
||||||
|
case_stats AS (
|
||||||
|
SELECT
|
||||||
|
COUNT(*) FILTER (WHERE status = 'active') AS active_count,
|
||||||
|
COUNT(*) FILTER (WHERE created_at >= $5::date AND status != 'archived') AS new_this_month,
|
||||||
|
COUNT(*) FILTER (WHERE status IN ('closed', 'archived')) AS closed_count
|
||||||
|
FROM cases
|
||||||
|
WHERE tenant_id = $1
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
ds.overdue_count, ds.due_this_week, ds.due_next_week, ds.ok_count,
|
||||||
|
cs.active_count, cs.new_this_month, cs.closed_count
|
||||||
|
FROM deadline_stats ds, case_stats cs`
|
||||||
|
|
||||||
|
var summaryRow struct {
|
||||||
|
DeadlineSummary
|
||||||
|
CaseSummary
|
||||||
|
}
|
||||||
|
err := s.db.GetContext(ctx, &summaryRow, summaryQuery, tenantID, today, endOfWeek, endOfNextWeek, startOfMonth)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("dashboard summary: %w", err)
|
||||||
|
}
|
||||||
|
data.DeadlineSummary = summaryRow.DeadlineSummary
|
||||||
|
data.CaseSummary = summaryRow.CaseSummary
|
||||||
|
|
||||||
|
// Upcoming deadlines (next 7 days)
|
||||||
|
deadlineQuery := `
|
||||||
|
SELECT d.id, d.title, d.due_date, c.case_number, c.title AS case_title, d.status
|
||||||
|
FROM deadlines d
|
||||||
|
JOIN cases c ON c.id = d.case_id AND c.tenant_id = d.tenant_id
|
||||||
|
WHERE d.tenant_id = $1 AND d.status = 'pending' AND d.due_date >= $2 AND d.due_date <= $3
|
||||||
|
ORDER BY d.due_date ASC`
|
||||||
|
|
||||||
|
data.UpcomingDeadlines = []UpcomingDeadline{}
|
||||||
|
if err := s.db.SelectContext(ctx, &data.UpcomingDeadlines, deadlineQuery, tenantID, today, in7Days); err != nil {
|
||||||
|
return nil, fmt.Errorf("dashboard upcoming deadlines: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upcoming appointments (next 7 days)
|
||||||
|
appointmentQuery := `
|
||||||
|
SELECT a.id, a.title, a.start_at, c.case_number, a.location
|
||||||
|
FROM appointments a
|
||||||
|
LEFT JOIN cases c ON c.id = a.case_id AND c.tenant_id = a.tenant_id
|
||||||
|
WHERE a.tenant_id = $1 AND a.start_at >= $2::timestamp AND a.start_at < ($2::date + interval '7 days')
|
||||||
|
ORDER BY a.start_at ASC`
|
||||||
|
|
||||||
|
data.UpcomingAppointments = []UpcomingAppointment{}
|
||||||
|
if err := s.db.SelectContext(ctx, &data.UpcomingAppointments, appointmentQuery, tenantID, now); err != nil {
|
||||||
|
return nil, fmt.Errorf("dashboard upcoming appointments: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recent activity (last 10 case events)
|
||||||
|
activityQuery := `
|
||||||
|
SELECT ce.event_type, ce.title, c.case_number, ce.event_date
|
||||||
|
FROM case_events ce
|
||||||
|
JOIN cases c ON c.id = ce.case_id AND c.tenant_id = ce.tenant_id
|
||||||
|
WHERE ce.tenant_id = $1
|
||||||
|
ORDER BY COALESCE(ce.event_date, ce.created_at) DESC
|
||||||
|
LIMIT 10`
|
||||||
|
|
||||||
|
data.RecentActivity = []RecentActivity{}
|
||||||
|
if err := s.db.SelectContext(ctx, &data.RecentActivity, activityQuery, tenantID); err != nil {
|
||||||
|
return nil, fmt.Errorf("dashboard recent activity: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
33
backend/internal/services/dashboard_service_test.go
Normal file
33
backend/internal/services/dashboard_service_test.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDashboardDateCalculations(t *testing.T) {
|
||||||
|
// Verify the date range logic used in Get()
|
||||||
|
now := time.Date(2026, 3, 25, 14, 0, 0, 0, time.UTC) // Wednesday
|
||||||
|
|
||||||
|
today := now.Format("2006-01-02")
|
||||||
|
endOfWeek := now.AddDate(0, 0, 7-int(now.Weekday())).Format("2006-01-02")
|
||||||
|
endOfNextWeek := now.AddDate(0, 0, 14-int(now.Weekday())).Format("2006-01-02")
|
||||||
|
in7Days := now.AddDate(0, 0, 7).Format("2006-01-02")
|
||||||
|
startOfMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).Format("2006-01-02")
|
||||||
|
|
||||||
|
if today != "2026-03-25" {
|
||||||
|
t.Errorf("today = %s, want 2026-03-25", today)
|
||||||
|
}
|
||||||
|
if endOfWeek != "2026-03-29" { // Sunday
|
||||||
|
t.Errorf("endOfWeek = %s, want 2026-03-29", endOfWeek)
|
||||||
|
}
|
||||||
|
if endOfNextWeek != "2026-04-05" {
|
||||||
|
t.Errorf("endOfNextWeek = %s, want 2026-04-05", endOfNextWeek)
|
||||||
|
}
|
||||||
|
if in7Days != "2026-04-01" {
|
||||||
|
t.Errorf("in7Days = %s, want 2026-04-01", in7Days)
|
||||||
|
}
|
||||||
|
if startOfMonth != "2026-03-01" {
|
||||||
|
t.Errorf("startOfMonth = %s, want 2026-03-01", startOfMonth)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,23 @@ func NewDeadlineService(db *sqlx.DB) *DeadlineService {
|
|||||||
return &DeadlineService{db: db}
|
return &DeadlineService{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListAll returns all deadlines for a tenant, ordered by due_date
|
||||||
|
func (s *DeadlineService) ListAll(tenantID uuid.UUID) ([]models.Deadline, error) {
|
||||||
|
query := `SELECT id, tenant_id, case_id, title, description, due_date, original_due_date,
|
||||||
|
warning_date, source, rule_id, status, completed_at,
|
||||||
|
caldav_uid, caldav_etag, notes, created_at, updated_at
|
||||||
|
FROM deadlines
|
||||||
|
WHERE tenant_id = $1
|
||||||
|
ORDER BY due_date ASC`
|
||||||
|
|
||||||
|
var deadlines []models.Deadline
|
||||||
|
err := s.db.Select(&deadlines, query, tenantID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("listing all deadlines: %w", err)
|
||||||
|
}
|
||||||
|
return deadlines, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ListForCase returns all deadlines for a case, scoped to tenant
|
// ListForCase returns all deadlines for a case, scoped to tenant
|
||||||
func (s *DeadlineService) ListForCase(tenantID, caseID uuid.UUID) ([]models.Deadline, error) {
|
func (s *DeadlineService) ListForCase(tenantID, caseID uuid.UUID) ([]models.Deadline, error) {
|
||||||
query := `SELECT id, tenant_id, case_id, title, description, due_date, original_due_date,
|
query := `SELECT id, tenant_id, case_id, title, description, due_date, original_due_date,
|
||||||
|
|||||||
163
backend/internal/services/document_service.go
Normal file
163
backend/internal/services/document_service.go
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"mgit.msbls.de/m/KanzlAI-mGMT/internal/models"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
const documentBucket = "kanzlai-documents"
|
||||||
|
|
||||||
|
type DocumentService struct {
|
||||||
|
db *sqlx.DB
|
||||||
|
storage *StorageClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDocumentService(db *sqlx.DB, storage *StorageClient) *DocumentService {
|
||||||
|
return &DocumentService{db: db, storage: storage}
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateDocumentInput struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
DocType string `json:"doc_type"`
|
||||||
|
Filename string
|
||||||
|
ContentType string
|
||||||
|
Size int
|
||||||
|
Data io.Reader
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DocumentService) ListByCase(ctx context.Context, tenantID, caseID uuid.UUID) ([]models.Document, error) {
|
||||||
|
var docs []models.Document
|
||||||
|
err := s.db.SelectContext(ctx, &docs,
|
||||||
|
"SELECT * FROM documents WHERE tenant_id = $1 AND case_id = $2 ORDER BY created_at DESC",
|
||||||
|
tenantID, caseID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("listing documents: %w", err)
|
||||||
|
}
|
||||||
|
return docs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DocumentService) GetByID(ctx context.Context, tenantID, docID uuid.UUID) (*models.Document, error) {
|
||||||
|
var doc models.Document
|
||||||
|
err := s.db.GetContext(ctx, &doc,
|
||||||
|
"SELECT * FROM documents WHERE id = $1 AND tenant_id = $2", docID, tenantID)
|
||||||
|
if err != nil {
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("getting document: %w", err)
|
||||||
|
}
|
||||||
|
return &doc, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DocumentService) Create(ctx context.Context, tenantID, caseID, userID uuid.UUID, input CreateDocumentInput) (*models.Document, error) {
|
||||||
|
// Verify case belongs to tenant
|
||||||
|
var caseExists int
|
||||||
|
if err := s.db.GetContext(ctx, &caseExists,
|
||||||
|
"SELECT COUNT(*) FROM cases WHERE id = $1 AND tenant_id = $2",
|
||||||
|
caseID, tenantID); err != nil {
|
||||||
|
return nil, fmt.Errorf("verifying case: %w", err)
|
||||||
|
}
|
||||||
|
if caseExists == 0 {
|
||||||
|
return nil, fmt.Errorf("case not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
id := uuid.New()
|
||||||
|
storagePath := fmt.Sprintf("%s/%s/%s_%s", tenantID, caseID, id, input.Filename)
|
||||||
|
|
||||||
|
// Upload to Supabase Storage
|
||||||
|
if err := s.storage.Upload(ctx, documentBucket, storagePath, input.ContentType, input.Data); err != nil {
|
||||||
|
return nil, fmt.Errorf("uploading file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert metadata record
|
||||||
|
now := time.Now()
|
||||||
|
_, err := s.db.ExecContext(ctx,
|
||||||
|
`INSERT INTO documents (id, tenant_id, case_id, title, doc_type, file_path, file_size, mime_type, uploaded_by, created_at, updated_at)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $10)`,
|
||||||
|
id, tenantID, caseID, input.Title, nilIfEmpty(input.DocType), storagePath, input.Size, input.ContentType, userID, now)
|
||||||
|
if err != nil {
|
||||||
|
// Best effort: clean up uploaded file
|
||||||
|
_ = s.storage.Delete(ctx, documentBucket, []string{storagePath})
|
||||||
|
return nil, fmt.Errorf("inserting document record: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log case event
|
||||||
|
createEvent(ctx, s.db, tenantID, caseID, userID, "document_uploaded",
|
||||||
|
fmt.Sprintf("Document uploaded: %s", input.Title), nil)
|
||||||
|
|
||||||
|
var doc models.Document
|
||||||
|
if err := s.db.GetContext(ctx, &doc, "SELECT * FROM documents WHERE id = $1", id); err != nil {
|
||||||
|
return nil, fmt.Errorf("fetching created document: %w", err)
|
||||||
|
}
|
||||||
|
return &doc, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DocumentService) Download(ctx context.Context, tenantID, docID uuid.UUID) (io.ReadCloser, string, string, error) {
|
||||||
|
doc, err := s.GetByID(ctx, tenantID, docID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", "", err
|
||||||
|
}
|
||||||
|
if doc == nil {
|
||||||
|
return nil, "", "", fmt.Errorf("document not found")
|
||||||
|
}
|
||||||
|
if doc.FilePath == nil {
|
||||||
|
return nil, "", "", fmt.Errorf("document has no file")
|
||||||
|
}
|
||||||
|
|
||||||
|
body, contentType, err := s.storage.Download(ctx, documentBucket, *doc.FilePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", "", fmt.Errorf("downloading file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use stored mime_type if available, fall back to storage response
|
||||||
|
if doc.MimeType != nil && *doc.MimeType != "" {
|
||||||
|
contentType = *doc.MimeType
|
||||||
|
}
|
||||||
|
|
||||||
|
return body, contentType, doc.Title, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DocumentService) Delete(ctx context.Context, tenantID, docID, userID uuid.UUID) error {
|
||||||
|
doc, err := s.GetByID(ctx, tenantID, docID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if doc == nil {
|
||||||
|
return sql.ErrNoRows
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete from storage
|
||||||
|
if doc.FilePath != nil {
|
||||||
|
if err := s.storage.Delete(ctx, documentBucket, []string{*doc.FilePath}); err != nil {
|
||||||
|
return fmt.Errorf("deleting file from storage: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete database record
|
||||||
|
_, err = s.db.ExecContext(ctx,
|
||||||
|
"DELETE FROM documents WHERE id = $1 AND tenant_id = $2", docID, tenantID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("deleting document record: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log case event
|
||||||
|
createEvent(ctx, s.db, tenantID, doc.CaseID, userID, "document_deleted",
|
||||||
|
fmt.Sprintf("Document deleted: %s", doc.Title), nil)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func nilIfEmpty(s string) *string {
|
||||||
|
if s == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &s
|
||||||
|
}
|
||||||
112
backend/internal/services/storage.go
Normal file
112
backend/internal/services/storage.go
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StorageClient interacts with Supabase Storage via REST API.
|
||||||
|
type StorageClient struct {
|
||||||
|
baseURL string
|
||||||
|
serviceKey string
|
||||||
|
httpClient *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStorageClient(supabaseURL, serviceKey string) *StorageClient {
|
||||||
|
return &StorageClient{
|
||||||
|
baseURL: supabaseURL,
|
||||||
|
serviceKey: serviceKey,
|
||||||
|
httpClient: &http.Client{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upload stores a file in the given bucket at the specified path.
|
||||||
|
func (s *StorageClient) Upload(ctx context.Context, bucket, path, contentType string, data io.Reader) error {
|
||||||
|
url := fmt.Sprintf("%s/storage/v1/object/%s/%s", s.baseURL, bucket, path)
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "POST", url, data)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("creating upload request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Authorization", "Bearer "+s.serviceKey)
|
||||||
|
req.Header.Set("Content-Type", contentType)
|
||||||
|
req.Header.Set("x-upsert", "true")
|
||||||
|
|
||||||
|
resp, err := s.httpClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("uploading to storage: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
|
||||||
|
body, _ := io.ReadAll(resp.Body)
|
||||||
|
return fmt.Errorf("storage upload failed (status %d): %s", resp.StatusCode, string(body))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download retrieves a file from storage. Caller must close the returned ReadCloser.
|
||||||
|
func (s *StorageClient) Download(ctx context.Context, bucket, path string) (io.ReadCloser, string, error) {
|
||||||
|
url := fmt.Sprintf("%s/storage/v1/object/%s/%s", s.baseURL, bucket, path)
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", fmt.Errorf("creating download request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Authorization", "Bearer "+s.serviceKey)
|
||||||
|
|
||||||
|
resp, err := s.httpClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", fmt.Errorf("downloading from storage: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
resp.Body.Close()
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
return nil, "", fmt.Errorf("file not found in storage")
|
||||||
|
}
|
||||||
|
body, _ := io.ReadAll(resp.Body)
|
||||||
|
return nil, "", fmt.Errorf("storage download failed (status %d): %s", resp.StatusCode, string(body))
|
||||||
|
}
|
||||||
|
|
||||||
|
ct := resp.Header.Get("Content-Type")
|
||||||
|
return resp.Body, ct, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete removes files from storage by their paths.
|
||||||
|
func (s *StorageClient) Delete(ctx context.Context, bucket string, paths []string) error {
|
||||||
|
url := fmt.Sprintf("%s/storage/v1/object/%s", s.baseURL, bucket)
|
||||||
|
|
||||||
|
body, err := json.Marshal(map[string][]string{"prefixes": paths})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("marshaling delete request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "DELETE", url, bytes.NewReader(body))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("creating delete request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Authorization", "Bearer "+s.serviceKey)
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
resp, err := s.httpClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("deleting from storage: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent {
|
||||||
|
respBody, _ := io.ReadAll(resp.Body)
|
||||||
|
return fmt.Errorf("storage delete failed (status %d): %s", resp.StatusCode, string(respBody))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
73
frontend/src/app/(app)/fristen/page.tsx
Normal file
73
frontend/src/app/(app)/fristen/page.tsx
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { DeadlineList } from "@/components/deadlines/DeadlineList";
|
||||||
|
import { DeadlineCalendarView } from "@/components/deadlines/DeadlineCalendarView";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { api } from "@/lib/api";
|
||||||
|
import type { Deadline } from "@/lib/types";
|
||||||
|
import { Calendar, List, Calculator } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
type ViewMode = "list" | "calendar";
|
||||||
|
|
||||||
|
export default function FristenPage() {
|
||||||
|
const [view, setView] = useState<ViewMode>("list");
|
||||||
|
|
||||||
|
const { data: deadlines } = useQuery({
|
||||||
|
queryKey: ["deadlines"],
|
||||||
|
queryFn: () => api.get<Deadline[]>("/api/deadlines"),
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-lg font-semibold text-neutral-900">Fristen</h1>
|
||||||
|
<p className="mt-0.5 text-sm text-neutral-500">
|
||||||
|
Alle Fristen im Uberblick
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Link
|
||||||
|
href="/fristen/rechner"
|
||||||
|
className="flex items-center gap-1.5 rounded-md border border-neutral-200 bg-white px-3 py-1.5 text-sm text-neutral-700 transition-colors hover:bg-neutral-50"
|
||||||
|
>
|
||||||
|
<Calculator className="h-3.5 w-3.5" />
|
||||||
|
Fristenrechner
|
||||||
|
</Link>
|
||||||
|
<div className="flex rounded-md border border-neutral-200 bg-white">
|
||||||
|
<button
|
||||||
|
onClick={() => setView("list")}
|
||||||
|
className={`flex items-center gap-1 rounded-l-md px-2.5 py-1.5 text-sm transition-colors ${
|
||||||
|
view === "list"
|
||||||
|
? "bg-neutral-100 font-medium text-neutral-900"
|
||||||
|
: "text-neutral-500 hover:text-neutral-700"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<List className="h-3.5 w-3.5" />
|
||||||
|
Liste
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setView("calendar")}
|
||||||
|
className={`flex items-center gap-1 rounded-r-md px-2.5 py-1.5 text-sm transition-colors ${
|
||||||
|
view === "calendar"
|
||||||
|
? "bg-neutral-100 font-medium text-neutral-900"
|
||||||
|
: "text-neutral-500 hover:text-neutral-700"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Calendar className="h-3.5 w-3.5" />
|
||||||
|
Kalender
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{view === "list" ? (
|
||||||
|
<DeadlineList />
|
||||||
|
) : (
|
||||||
|
<DeadlineCalendarView deadlines={deadlines || []} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
26
frontend/src/app/(app)/fristen/rechner/page.tsx
Normal file
26
frontend/src/app/(app)/fristen/rechner/page.tsx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { DeadlineCalculator } from "@/components/deadlines/DeadlineCalculator";
|
||||||
|
import { ArrowLeft } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
export default function FristenrechnerPage() {
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div>
|
||||||
|
<Link
|
||||||
|
href="/fristen"
|
||||||
|
className="mb-2 inline-flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700"
|
||||||
|
>
|
||||||
|
<ArrowLeft className="h-3.5 w-3.5" />
|
||||||
|
Zuruck zu Fristen
|
||||||
|
</Link>
|
||||||
|
<h1 className="text-lg font-semibold text-neutral-900">Fristenrechner</h1>
|
||||||
|
<p className="mt-0.5 text-sm text-neutral-500">
|
||||||
|
Berechnen Sie Fristen basierend auf Verfahrensart und Auslosedatum
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<DeadlineCalculator />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
178
frontend/src/components/deadlines/DeadlineCalculator.tsx
Normal file
178
frontend/src/components/deadlines/DeadlineCalculator.tsx
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||||
|
import { api } from "@/lib/api";
|
||||||
|
import type { ProceedingType, CalculateResponse, CalculatedDeadline } from "@/lib/types";
|
||||||
|
import { format, parseISO, isPast, isThisWeek } from "date-fns";
|
||||||
|
import { de } from "date-fns/locale";
|
||||||
|
import { Calculator, Calendar, ArrowRight, AlertTriangle } from "lucide-react";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
function getTimelineUrgency(dueDate: string): "red" | "amber" | "green" {
|
||||||
|
const due = parseISO(dueDate);
|
||||||
|
if (isPast(due)) return "red";
|
||||||
|
if (isThisWeek(due, { weekStartsOn: 1 })) return "amber";
|
||||||
|
return "green";
|
||||||
|
}
|
||||||
|
|
||||||
|
const dotColors = {
|
||||||
|
red: "bg-red-500",
|
||||||
|
amber: "bg-amber-500",
|
||||||
|
green: "bg-green-500",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function DeadlineCalculator() {
|
||||||
|
const [proceedingType, setProceedingType] = useState("");
|
||||||
|
const [triggerDate, setTriggerDate] = useState("");
|
||||||
|
|
||||||
|
const { data: proceedingTypes, isLoading: typesLoading } = useQuery({
|
||||||
|
queryKey: ["proceeding-types"],
|
||||||
|
queryFn: () => api.get<ProceedingType[]>("/api/proceeding-types"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const calculateMutation = useMutation({
|
||||||
|
mutationFn: (params: { proceeding_type: string; trigger_event_date: string }) =>
|
||||||
|
api.post<CalculateResponse>("/api/deadlines/calculate", params),
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleCalculate(e: React.FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!proceedingType || !triggerDate) return;
|
||||||
|
calculateMutation.mutate({
|
||||||
|
proceeding_type: proceedingType,
|
||||||
|
trigger_event_date: triggerDate,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const results = calculateMutation.data;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
{/* Input form */}
|
||||||
|
<form onSubmit={handleCalculate} className="rounded-lg border border-neutral-200 bg-white p-5">
|
||||||
|
<div className="flex items-center gap-2 text-sm font-medium text-neutral-900">
|
||||||
|
<Calculator className="h-4 w-4" />
|
||||||
|
Fristenberechnung
|
||||||
|
</div>
|
||||||
|
<div className="mt-4 grid gap-4 sm:grid-cols-3">
|
||||||
|
<div>
|
||||||
|
<label className="mb-1 block text-xs font-medium text-neutral-500">
|
||||||
|
Verfahrensart
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
value={proceedingType}
|
||||||
|
onChange={(e) => setProceedingType(e.target.value)}
|
||||||
|
disabled={typesLoading}
|
||||||
|
className="w-full rounded-md border border-neutral-200 bg-white px-3 py-2 text-sm text-neutral-900"
|
||||||
|
>
|
||||||
|
<option value="">Bitte wahlen...</option>
|
||||||
|
{proceedingTypes?.map((pt) => (
|
||||||
|
<option key={pt.id} value={pt.code}>
|
||||||
|
{pt.name} ({pt.code})
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="mb-1 block text-xs font-medium text-neutral-500">
|
||||||
|
Auslosedatum
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
value={triggerDate}
|
||||||
|
onChange={(e) => setTriggerDate(e.target.value)}
|
||||||
|
className="w-full rounded-md border border-neutral-200 bg-white px-3 py-2 text-sm text-neutral-900"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-end">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={!proceedingType || !triggerDate || calculateMutation.isPending}
|
||||||
|
className="flex w-full items-center justify-center gap-2 rounded-md bg-neutral-900 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-neutral-800 disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{calculateMutation.isPending ? "Berechne..." : "Berechnen"}
|
||||||
|
<ArrowRight className="h-3.5 w-3.5" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{/* Error */}
|
||||||
|
{calculateMutation.isError && (
|
||||||
|
<div className="flex items-center gap-2 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">
|
||||||
|
<AlertTriangle className="h-4 w-4 shrink-0" />
|
||||||
|
Fehler bei der Berechnung. Bitte Eingaben prufen.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Results */}
|
||||||
|
{results && results.deadlines && (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<h3 className="text-sm font-medium text-neutral-900">
|
||||||
|
Berechnete Fristen
|
||||||
|
</h3>
|
||||||
|
<span className="text-xs text-neutral-500">
|
||||||
|
{results.deadlines.length} Fristen ab{" "}
|
||||||
|
{format(parseISO(results.trigger_event_date), "dd. MMM yyyy", { locale: de })}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Timeline */}
|
||||||
|
<div className="relative rounded-lg border border-neutral-200 bg-white">
|
||||||
|
{results.deadlines.map((d: CalculatedDeadline, i: number) => {
|
||||||
|
const urgency = getTimelineUrgency(d.due_date);
|
||||||
|
const isLast = i === results.deadlines.length - 1;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={d.rule_id}
|
||||||
|
className={`flex gap-3 px-4 py-3 ${!isLast ? "border-b border-neutral-100" : ""}`}
|
||||||
|
>
|
||||||
|
{/* Timeline dot + line */}
|
||||||
|
<div className="flex flex-col items-center pt-1">
|
||||||
|
<div className={`h-2.5 w-2.5 shrink-0 rounded-full ${dotColors[urgency]}`} />
|
||||||
|
{!isLast && <div className="mt-1 w-px flex-1 bg-neutral-200" />}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Content */}
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<div className="flex items-start justify-between gap-2">
|
||||||
|
<span className="text-sm font-medium text-neutral-900">
|
||||||
|
{d.title}
|
||||||
|
</span>
|
||||||
|
<span className="shrink-0 text-sm font-medium tabular-nums text-neutral-700">
|
||||||
|
{format(parseISO(d.due_date), "dd.MM.yyyy")}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="mt-0.5 flex items-center gap-2 text-xs text-neutral-500">
|
||||||
|
{d.rule_code && <span>{d.rule_code}</span>}
|
||||||
|
{d.was_adjusted && (
|
||||||
|
<>
|
||||||
|
{d.rule_code && <span>·</span>}
|
||||||
|
<span className="text-amber-600">
|
||||||
|
Angepasst (Original: {format(parseISO(d.original_due_date), "dd.MM.yyyy")})
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Empty state */}
|
||||||
|
{!results && !calculateMutation.isPending && (
|
||||||
|
<div className="rounded-lg border border-neutral-200 bg-white p-8 text-center">
|
||||||
|
<Calendar className="mx-auto h-8 w-8 text-neutral-300" />
|
||||||
|
<p className="mt-2 text-sm text-neutral-500">
|
||||||
|
Verfahrensart und Auslosedatum wahlen, um Fristen zu berechnen
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
154
frontend/src/components/deadlines/DeadlineCalendarView.tsx
Normal file
154
frontend/src/components/deadlines/DeadlineCalendarView.tsx
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import type { Deadline } from "@/lib/types";
|
||||||
|
import {
|
||||||
|
format,
|
||||||
|
startOfMonth,
|
||||||
|
endOfMonth,
|
||||||
|
startOfWeek,
|
||||||
|
endOfWeek,
|
||||||
|
eachDayOfInterval,
|
||||||
|
isSameMonth,
|
||||||
|
isToday,
|
||||||
|
parseISO,
|
||||||
|
isPast,
|
||||||
|
isThisWeek,
|
||||||
|
addMonths,
|
||||||
|
subMonths,
|
||||||
|
} from "date-fns";
|
||||||
|
import { de } from "date-fns/locale";
|
||||||
|
import { ChevronLeft, ChevronRight } from "lucide-react";
|
||||||
|
import { useState, useMemo } from "react";
|
||||||
|
|
||||||
|
interface DeadlineCalendarViewProps {
|
||||||
|
deadlines: Deadline[];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUrgency(deadline: Deadline): "red" | "amber" | "green" {
|
||||||
|
if (deadline.status === "completed") return "green";
|
||||||
|
const due = parseISO(deadline.due_date);
|
||||||
|
if (isPast(due)) return "red";
|
||||||
|
if (isThisWeek(due, { weekStartsOn: 1 })) return "amber";
|
||||||
|
return "green";
|
||||||
|
}
|
||||||
|
|
||||||
|
const dotColors = {
|
||||||
|
red: "bg-red-500",
|
||||||
|
amber: "bg-amber-500",
|
||||||
|
green: "bg-green-500",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function DeadlineCalendarView({ deadlines }: DeadlineCalendarViewProps) {
|
||||||
|
const [currentMonth, setCurrentMonth] = useState(new Date());
|
||||||
|
|
||||||
|
const monthStart = startOfMonth(currentMonth);
|
||||||
|
const monthEnd = endOfMonth(currentMonth);
|
||||||
|
const calStart = startOfWeek(monthStart, { weekStartsOn: 1 });
|
||||||
|
const calEnd = endOfWeek(monthEnd, { weekStartsOn: 1 });
|
||||||
|
const days = eachDayOfInterval({ start: calStart, end: calEnd });
|
||||||
|
|
||||||
|
const deadlinesByDay = useMemo(() => {
|
||||||
|
const map = new Map<string, Deadline[]>();
|
||||||
|
for (const d of deadlines) {
|
||||||
|
if (d.status === "completed") continue;
|
||||||
|
const key = d.due_date.slice(0, 10);
|
||||||
|
const existing = map.get(key) || [];
|
||||||
|
existing.push(d);
|
||||||
|
map.set(key, existing);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}, [deadlines]);
|
||||||
|
|
||||||
|
const weekDays = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-neutral-200 bg-white">
|
||||||
|
{/* Header */}
|
||||||
|
<div className="flex items-center justify-between border-b border-neutral-200 px-4 py-3">
|
||||||
|
<button
|
||||||
|
onClick={() => setCurrentMonth(subMonths(currentMonth, 1))}
|
||||||
|
className="rounded-md p-1 text-neutral-400 hover:bg-neutral-100 hover:text-neutral-600"
|
||||||
|
>
|
||||||
|
<ChevronLeft className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
<span className="text-sm font-medium text-neutral-900">
|
||||||
|
{format(currentMonth, "MMMM yyyy", { locale: de })}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => setCurrentMonth(addMonths(currentMonth, 1))}
|
||||||
|
className="rounded-md p-1 text-neutral-400 hover:bg-neutral-100 hover:text-neutral-600"
|
||||||
|
>
|
||||||
|
<ChevronRight className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Weekday labels */}
|
||||||
|
<div className="grid grid-cols-7 border-b border-neutral-100">
|
||||||
|
{weekDays.map((d) => (
|
||||||
|
<div key={d} className="px-2 py-2 text-center text-xs font-medium text-neutral-400">
|
||||||
|
{d}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Days grid */}
|
||||||
|
<div className="grid grid-cols-7">
|
||||||
|
{days.map((day, i) => {
|
||||||
|
const key = format(day, "yyyy-MM-dd");
|
||||||
|
const dayDeadlines = deadlinesByDay.get(key) || [];
|
||||||
|
const inMonth = isSameMonth(day, currentMonth);
|
||||||
|
const today = isToday(day);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={i}
|
||||||
|
className={`min-h-[4.5rem] border-b border-r border-neutral-100 p-1.5 ${
|
||||||
|
!inMonth ? "bg-neutral-50" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={`mb-1 text-right text-xs ${
|
||||||
|
today
|
||||||
|
? "font-bold text-neutral-900"
|
||||||
|
: inMonth
|
||||||
|
? "text-neutral-600"
|
||||||
|
: "text-neutral-300"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{today ? (
|
||||||
|
<span className="inline-flex h-5 w-5 items-center justify-center rounded-full bg-neutral-900 text-white">
|
||||||
|
{format(day, "d")}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
format(day, "d")
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="space-y-0.5">
|
||||||
|
{dayDeadlines.slice(0, 3).map((dl) => {
|
||||||
|
const urgency = getUrgency(dl);
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={dl.id}
|
||||||
|
className="flex items-center gap-1 truncate"
|
||||||
|
title={dl.title}
|
||||||
|
>
|
||||||
|
<div className={`h-1.5 w-1.5 shrink-0 rounded-full ${dotColors[urgency]}`} />
|
||||||
|
<span className="truncate text-[10px] text-neutral-700">
|
||||||
|
{dl.title}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{dayDeadlines.length > 3 && (
|
||||||
|
<div className="text-[10px] text-neutral-400">
|
||||||
|
+{dayDeadlines.length - 3} mehr
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
257
frontend/src/components/deadlines/DeadlineList.tsx
Normal file
257
frontend/src/components/deadlines/DeadlineList.tsx
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { api } from "@/lib/api";
|
||||||
|
import type { Deadline, Case } from "@/lib/types";
|
||||||
|
import { format, isPast, isThisWeek, parseISO } from "date-fns";
|
||||||
|
import { de } from "date-fns/locale";
|
||||||
|
import { Check, Clock, Filter } from "lucide-react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { useState, useMemo } from "react";
|
||||||
|
|
||||||
|
type StatusFilter = "all" | "pending" | "completed" | "overdue";
|
||||||
|
|
||||||
|
function getUrgency(deadline: Deadline): "red" | "amber" | "green" {
|
||||||
|
if (deadline.status === "completed") return "green";
|
||||||
|
const due = parseISO(deadline.due_date);
|
||||||
|
if (isPast(due)) return "red";
|
||||||
|
if (isThisWeek(due, { weekStartsOn: 1 })) return "amber";
|
||||||
|
return "green";
|
||||||
|
}
|
||||||
|
|
||||||
|
const urgencyConfig = {
|
||||||
|
red: {
|
||||||
|
bg: "bg-red-50",
|
||||||
|
border: "border-red-200",
|
||||||
|
badge: "bg-red-100 text-red-700",
|
||||||
|
dot: "bg-red-500",
|
||||||
|
label: "Uberschritten",
|
||||||
|
},
|
||||||
|
amber: {
|
||||||
|
bg: "bg-amber-50",
|
||||||
|
border: "border-amber-200",
|
||||||
|
badge: "bg-amber-100 text-amber-700",
|
||||||
|
dot: "bg-amber-500",
|
||||||
|
label: "Diese Woche",
|
||||||
|
},
|
||||||
|
green: {
|
||||||
|
bg: "bg-white",
|
||||||
|
border: "border-neutral-200",
|
||||||
|
badge: "bg-green-100 text-green-700",
|
||||||
|
dot: "bg-green-500",
|
||||||
|
label: "OK",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export function DeadlineList() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const [statusFilter, setStatusFilter] = useState<StatusFilter>("all");
|
||||||
|
const [caseFilter, setCaseFilter] = useState<string>("all");
|
||||||
|
|
||||||
|
const { data: deadlines, isLoading } = useQuery({
|
||||||
|
queryKey: ["deadlines"],
|
||||||
|
queryFn: () => api.get<Deadline[]>("/api/deadlines"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: cases } = useQuery({
|
||||||
|
queryKey: ["cases"],
|
||||||
|
queryFn: () => api.get<Case[]>("/api/cases"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const completeMutation = useMutation({
|
||||||
|
mutationFn: (id: string) =>
|
||||||
|
api.patch<Deadline>(`/api/deadlines/${id}/complete`),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["deadlines"] });
|
||||||
|
toast.success("Frist als erledigt markiert");
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error("Fehler beim Abschliessen der Frist");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const caseMap = useMemo(() => {
|
||||||
|
const map = new Map<string, Case>();
|
||||||
|
cases?.forEach((c) => map.set(c.id, c));
|
||||||
|
return map;
|
||||||
|
}, [cases]);
|
||||||
|
|
||||||
|
const filtered = useMemo(() => {
|
||||||
|
if (!deadlines) return [];
|
||||||
|
return deadlines.filter((d) => {
|
||||||
|
if (statusFilter === "pending" && d.status !== "pending") return false;
|
||||||
|
if (statusFilter === "completed" && d.status !== "completed") return false;
|
||||||
|
if (statusFilter === "overdue") {
|
||||||
|
if (d.status === "completed") return false;
|
||||||
|
if (!isPast(parseISO(d.due_date))) return false;
|
||||||
|
}
|
||||||
|
if (caseFilter !== "all" && d.case_id !== caseFilter) return false;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}, [deadlines, statusFilter, caseFilter]);
|
||||||
|
|
||||||
|
const counts = useMemo(() => {
|
||||||
|
if (!deadlines) return { overdue: 0, thisWeek: 0, ok: 0 };
|
||||||
|
let overdue = 0, thisWeek = 0, ok = 0;
|
||||||
|
for (const d of deadlines) {
|
||||||
|
if (d.status === "completed") continue;
|
||||||
|
const urgency = getUrgency(d);
|
||||||
|
if (urgency === "red") overdue++;
|
||||||
|
else if (urgency === "amber") thisWeek++;
|
||||||
|
else ok++;
|
||||||
|
}
|
||||||
|
return { overdue, thisWeek, ok };
|
||||||
|
}, [deadlines]);
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
{[1, 2, 3, 4, 5].map((i) => (
|
||||||
|
<div key={i} className="h-16 animate-pulse rounded-lg bg-neutral-100" />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
{/* Summary cards */}
|
||||||
|
<div className="grid grid-cols-3 gap-3">
|
||||||
|
<button
|
||||||
|
onClick={() => setStatusFilter(statusFilter === "overdue" ? "all" : "overdue")}
|
||||||
|
className={`rounded-lg border p-3 text-left transition-colors ${
|
||||||
|
statusFilter === "overdue"
|
||||||
|
? "border-red-300 bg-red-50"
|
||||||
|
: "border-neutral-200 bg-white hover:bg-neutral-50"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div className="text-2xl font-semibold text-red-600">{counts.overdue}</div>
|
||||||
|
<div className="text-xs text-neutral-500">Uberschritten</div>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setStatusFilter(statusFilter === "pending" ? "all" : "pending")}
|
||||||
|
className={`rounded-lg border p-3 text-left transition-colors ${
|
||||||
|
statusFilter === "pending"
|
||||||
|
? "border-amber-300 bg-amber-50"
|
||||||
|
: "border-neutral-200 bg-white hover:bg-neutral-50"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div className="text-2xl font-semibold text-amber-600">{counts.thisWeek}</div>
|
||||||
|
<div className="text-xs text-neutral-500">Diese Woche</div>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setStatusFilter("all")}
|
||||||
|
className={`rounded-lg border p-3 text-left transition-colors ${
|
||||||
|
statusFilter === "all"
|
||||||
|
? "border-green-300 bg-green-50"
|
||||||
|
: "border-neutral-200 bg-white hover:bg-neutral-50"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div className="text-2xl font-semibold text-green-600">{counts.ok}</div>
|
||||||
|
<div className="text-xs text-neutral-500">OK</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Filters */}
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="flex items-center gap-1.5 text-sm text-neutral-500">
|
||||||
|
<Filter className="h-3.5 w-3.5" />
|
||||||
|
<span>Filter:</span>
|
||||||
|
</div>
|
||||||
|
<select
|
||||||
|
value={statusFilter}
|
||||||
|
onChange={(e) => setStatusFilter(e.target.value as StatusFilter)}
|
||||||
|
className="rounded-md border border-neutral-200 bg-white px-2.5 py-1 text-sm text-neutral-700"
|
||||||
|
>
|
||||||
|
<option value="all">Alle Status</option>
|
||||||
|
<option value="pending">Offen</option>
|
||||||
|
<option value="completed">Erledigt</option>
|
||||||
|
<option value="overdue">Uberschritten</option>
|
||||||
|
</select>
|
||||||
|
{cases && cases.length > 0 && (
|
||||||
|
<select
|
||||||
|
value={caseFilter}
|
||||||
|
onChange={(e) => setCaseFilter(e.target.value)}
|
||||||
|
className="rounded-md border border-neutral-200 bg-white px-2.5 py-1 text-sm text-neutral-700"
|
||||||
|
>
|
||||||
|
<option value="all">Alle Akten</option>
|
||||||
|
{cases.map((c) => (
|
||||||
|
<option key={c.id} value={c.id}>
|
||||||
|
{c.case_number} — {c.title}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Deadline list */}
|
||||||
|
{filtered.length === 0 ? (
|
||||||
|
<div className="rounded-lg border border-neutral-200 bg-white p-8 text-center">
|
||||||
|
<Clock className="mx-auto h-8 w-8 text-neutral-300" />
|
||||||
|
<p className="mt-2 text-sm text-neutral-500">Keine Fristen gefunden</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{filtered.map((deadline) => {
|
||||||
|
const urgency = getUrgency(deadline);
|
||||||
|
const config = urgencyConfig[urgency];
|
||||||
|
const caseInfo = caseMap.get(deadline.case_id);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={deadline.id}
|
||||||
|
className={`flex items-center gap-3 rounded-lg border px-4 py-3 ${config.bg} ${config.border}`}
|
||||||
|
>
|
||||||
|
<div className={`h-2.5 w-2.5 shrink-0 rounded-full ${config.dot}`} />
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="truncate text-sm font-medium text-neutral-900">
|
||||||
|
{deadline.title}
|
||||||
|
</span>
|
||||||
|
<span className={`shrink-0 rounded px-1.5 py-0.5 text-xs font-medium ${config.badge}`}>
|
||||||
|
{config.label}
|
||||||
|
</span>
|
||||||
|
{deadline.status === "completed" && (
|
||||||
|
<span className="shrink-0 rounded bg-neutral-100 px-1.5 py-0.5 text-xs font-medium text-neutral-500">
|
||||||
|
Erledigt
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="mt-0.5 flex items-center gap-2 text-xs text-neutral-500">
|
||||||
|
<span>
|
||||||
|
{format(parseISO(deadline.due_date), "dd. MMM yyyy", { locale: de })}
|
||||||
|
</span>
|
||||||
|
{caseInfo && (
|
||||||
|
<>
|
||||||
|
<span>·</span>
|
||||||
|
<span className="truncate">
|
||||||
|
{caseInfo.case_number} — {caseInfo.title}
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{deadline.source !== "manual" && (
|
||||||
|
<>
|
||||||
|
<span>·</span>
|
||||||
|
<span>{deadline.source}</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{deadline.status !== "completed" && (
|
||||||
|
<button
|
||||||
|
onClick={() => completeMutation.mutate(deadline.id)}
|
||||||
|
disabled={completeMutation.isPending}
|
||||||
|
title="Als erledigt markieren"
|
||||||
|
className="shrink-0 rounded-md p-1.5 text-neutral-400 hover:bg-white hover:text-green-600"
|
||||||
|
>
|
||||||
|
<Check className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -69,6 +69,13 @@ class ApiClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patch<T>(path: string, body?: unknown) {
|
||||||
|
return this.request<T>(path, {
|
||||||
|
method: "PATCH",
|
||||||
|
body: body ? JSON.stringify(body) : undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
delete<T>(path: string) {
|
delete<T>(path: string) {
|
||||||
return this.request<T>(path, { method: "DELETE" });
|
return this.request<T>(path, { method: "DELETE" });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,54 @@ export interface Document {
|
|||||||
updated_at: string;
|
updated_at: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DeadlineRule {
|
||||||
|
id: string;
|
||||||
|
proceeding_type_id?: number;
|
||||||
|
parent_id?: string;
|
||||||
|
code?: string;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
primary_party?: string;
|
||||||
|
event_type?: string;
|
||||||
|
is_mandatory: boolean;
|
||||||
|
duration_value: number;
|
||||||
|
duration_unit: string;
|
||||||
|
timing?: string;
|
||||||
|
rule_code?: string;
|
||||||
|
deadline_notes?: string;
|
||||||
|
sequence_order: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RuleTreeNode extends DeadlineRule {
|
||||||
|
children?: RuleTreeNode[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProceedingType {
|
||||||
|
id: number;
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
jurisdiction?: string;
|
||||||
|
default_color: string;
|
||||||
|
sort_order: number;
|
||||||
|
is_active: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CalculatedDeadline {
|
||||||
|
rule_code: string;
|
||||||
|
rule_id: string;
|
||||||
|
title: string;
|
||||||
|
due_date: string;
|
||||||
|
original_due_date: string;
|
||||||
|
was_adjusted: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CalculateResponse {
|
||||||
|
proceeding_type: string;
|
||||||
|
trigger_event_date: string;
|
||||||
|
deadlines: CalculatedDeadline[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface ApiError {
|
export interface ApiError {
|
||||||
error: string;
|
error: string;
|
||||||
status: number;
|
status: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user