Feature user and admin panels (#30)

This commit is contained in:
2026-02-16 20:30:36 +00:00
parent c5866ae785
commit 2fc4f6980c
15 changed files with 1805 additions and 111 deletions

View File

@@ -44,12 +44,17 @@ func main() {
{
// Health (routable through ingress)
api.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{
info := gin.H{
"status": "ok",
"version": Version,
"database": database.IsConnected(),
"providers": providers.List(),
})
}
// Include registration status for frontend
if database.IsConnected() {
info["registration_enabled"] = isRegistrationOpen()
}
c.JSON(200, info)
})
authGroup := api.Group("/auth")
@@ -95,9 +100,37 @@ func main() {
protected.GET("/api-configs/:id/models", apiCfg.ListModels)
protected.GET("/models", apiCfg.ListAllModels)
// Settings — future
protected.GET("/settings", stubHandler("settings"))
protected.PUT("/settings", stubHandler("settings"))
// User Settings & Profile
settings := handlers.NewSettingsHandler()
protected.GET("/profile", settings.GetProfile)
protected.PUT("/profile", settings.UpdateProfile)
protected.POST("/profile/password", settings.ChangePassword)
protected.GET("/settings", settings.GetSettings)
protected.PUT("/settings", settings.UpdateSettings)
}
// ── Admin routes ────────────────────────
admin := api.Group("/admin")
admin.Use(middleware.Auth(cfg))
admin.Use(middleware.RequireAdmin())
{
adm := handlers.NewAdminHandler()
// User management
admin.GET("/users", adm.ListUsers)
admin.POST("/users", adm.CreateUser)
admin.PUT("/users/:id/role", adm.UpdateUserRole)
admin.PUT("/users/:id/active", adm.ToggleUserActive)
admin.POST("/users/:id/reset-password", adm.ResetPassword)
admin.DELETE("/users/:id", adm.DeleteUser)
// Global settings
admin.GET("/settings", adm.ListGlobalSettings)
admin.GET("/settings/:key", adm.GetGlobalSetting)
admin.PUT("/settings/:key", adm.UpdateGlobalSetting)
// Stats
admin.GET("/stats", adm.GetStats)
}
}
@@ -108,8 +141,6 @@ func main() {
}
}
func stubHandler(feature string) gin.HandlerFunc {
return func(c *gin.Context) {
c.JSON(501, gin.H{"error": feature + " not implemented"})
}
func isRegistrationOpen() bool {
return handlers.IsRegistrationEnabled()
}