Files
KanzlAI-mGMT/backend/internal/router/router.go
m bd15b4eb38 feat: add appointment CRUD backend (Phase 1D)
- AppointmentService with tenant-scoped List, GetByID, Create, Update, Delete
- List supports filtering by case_id, appointment_type, and date range (start_from/start_to)
- AppointmentHandler with JSON request/response handling and input validation
- Router wired up: GET/POST /api/appointments, PUT/DELETE /api/appointments/{id}
2026-03-25 13:25:46 +01:00

64 lines
1.7 KiB
Go

package router
import (
"encoding/json"
"net/http"
"mgit.msbls.de/m/KanzlAI-mGMT/internal/auth"
"mgit.msbls.de/m/KanzlAI-mGMT/internal/handlers"
"mgit.msbls.de/m/KanzlAI-mGMT/internal/services"
"github.com/jmoiron/sqlx"
)
func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
mux := http.NewServeMux()
// Public routes
mux.HandleFunc("GET /health", handleHealth(db))
// Services
appointmentSvc := services.NewAppointmentService(db)
// Handlers
apptH := handlers.NewAppointmentHandler(appointmentSvc)
// Authenticated API routes
api := http.NewServeMux()
api.HandleFunc("GET /api/cases", placeholder("cases"))
api.HandleFunc("GET /api/deadlines", placeholder("deadlines"))
api.HandleFunc("GET /api/documents", placeholder("documents"))
// Appointments CRUD
api.HandleFunc("GET /api/appointments", apptH.List)
api.HandleFunc("POST /api/appointments", apptH.Create)
api.HandleFunc("PUT /api/appointments/{id}", apptH.Update)
api.HandleFunc("DELETE /api/appointments/{id}", apptH.Delete)
mux.Handle("/api/", authMW.RequireAuth(api))
return mux
}
func handleHealth(db *sqlx.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if err := db.Ping(); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
json.NewEncoder(w).Encode(map[string]string{"status": "error", "error": err.Error()})
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
}
}
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,
})
}
}