feat(models): rename ModelPublicUser to ModelPublicUsers and update references
Some checks failed
CI / Test (1.22) (push) Failing after -22m18s
CI / Test (1.23) (push) Failing after -22m7s
CI / Lint (push) Failing after -22m32s
CI / Build (push) Failing after -22m38s

* Update user-related models to use plural naming for consistency
* Add relationships to ModelPublicUsers in related models
* Adjust database migration and schema to reflect changes
* Remove deprecated ModelPublicUser
This commit is contained in:
Hein
2026-02-20 17:56:02 +02:00
parent a3ff2dc497
commit cecbd2cef5
13 changed files with 107 additions and 89 deletions

View File

@@ -73,8 +73,14 @@ func NewServer(cfg *config.Config, db *bun.DB, wh WhatsHookedInterface) (*Server
apiV1Router.Use(security.NewAuthMiddleware(securityList))
apiV1Router.Use(security.SetSecurityMiddleware(securityList))
// Create the embedded dist FS (built Vite output, includes web/public/ contents)
distFS, err := fs.Sub(serverembed.RootEmbedFS, "dist")
if err != nil {
return nil, fmt.Errorf("failed to sub embedded dist FS: %w", err)
}
// Setup WhatsApp API routes on main router (these use their own Auth middleware)
SetupWhatsAppRoutes(router, wh)
SetupWhatsAppRoutes(router, wh, distFS)
// Setup ResolveSpec routes on the protected /api/v1 subrouter (auto-generated CRUD)
restheadspec.SetupMuxRoutes(apiV1Router, handler, nil)
@@ -83,10 +89,6 @@ func NewServer(cfg *config.Config, db *bun.DB, wh WhatsHookedInterface) (*Server
SetupCustomRoutes(router, secProvider, db)
// Serve React SPA from the embedded filesystem at /ui/
distFS, err := fs.Sub(serverembed.RootEmbedFS, "dist")
if err != nil {
return nil, fmt.Errorf("failed to sub embedded dist FS: %w", err)
}
spa := embeddedSPAHandler{fs: distFS, indexPath: "index.html"}
router.PathPrefix("/ui/").Handler(http.StripPrefix("/ui", spa))
router.PathPrefix("/ui").Handler(http.StripPrefix("/ui", spa))
@@ -131,7 +133,7 @@ func (s *Server) Start() error {
// registerModelsToRegistry registers all BUN models with the model registry
func registerModelsToRegistry(registry common.ModelRegistry) {
// Register all models with their table names (without schema for SQLite compatibility)
registry.RegisterModel("users", &models.ModelPublicUser{})
registry.RegisterModel("users", &models.ModelPublicUsers{})
registry.RegisterModel("api_keys", &models.ModelPublicAPIKey{})
registry.RegisterModel("hooks", &models.ModelPublicHook{})
registry.RegisterModel("whatsapp_accounts", &models.ModelPublicWhatsappAccount{})
@@ -141,7 +143,7 @@ func registerModelsToRegistry(registry common.ModelRegistry) {
}
// SetupWhatsAppRoutes adds all WhatsApp API routes
func SetupWhatsAppRoutes(router *mux.Router, wh WhatsHookedInterface) {
func SetupWhatsAppRoutes(router *mux.Router, wh WhatsHookedInterface, distFS fs.FS) {
h := wh.Handlers()
// Landing page (no auth required)
@@ -151,8 +153,12 @@ func SetupWhatsAppRoutes(router *mux.Router, wh WhatsHookedInterface) {
router.HandleFunc("/privacy-policy", h.ServePrivacyPolicy).Methods("GET")
router.HandleFunc("/terms-of-service", h.ServeTermsOfService).Methods("GET")
// Static files (no auth required)
router.PathPrefix("/static/").HandlerFunc(h.ServeStatic)
// Logo files served from the embedded pkg/handlers/static/ (referenced by index.html)
router.HandleFunc("/static/logo.png", h.ServeStatic)
router.HandleFunc("/static/logo1024.png", h.ServeStatic)
// Everything else under /static/ is served from the built web/public/ directory
router.PathPrefix("/static/").Handler(http.StripPrefix("/static", http.FileServer(http.FS(distFS))))
// Health check (no auth required)
router.HandleFunc("/health", h.Health).Methods("GET")
@@ -481,7 +487,7 @@ func handleQueryCreate(w http.ResponseWriter, r *http.Request, db *bun.DB, req Q
m.ID.FromString(generatedID)
case *models.ModelPublicEventLog:
m.ID.FromString(generatedID)
case *models.ModelPublicUser:
case *models.ModelPublicUsers:
m.ID.FromString(generatedID)
}
}
@@ -547,7 +553,7 @@ func handleQueryDelete(w http.ResponseWriter, r *http.Request, db *bun.DB, req Q
func getModelForTable(table string) func() interface{} {
switch table {
case "users":
return func() interface{} { return &[]models.ModelPublicUser{} }
return func() interface{} { return &[]models.ModelPublicUsers{} }
case "hooks":
return func() interface{} { return &[]models.ModelPublicHook{} }
case "whatsapp_accounts":
@@ -569,7 +575,7 @@ func getModelForTable(table string) func() interface{} {
func getModelSingleForTable(table string) interface{} {
switch table {
case "users":
return &models.ModelPublicUser{}
return &models.ModelPublicUsers{}
case "hooks":
return &models.ModelPublicHook{}
case "whatsapp_accounts":