refactor: reorganize models to pkg/model and add authentication module
- Move ORM models from internal/model to pkg/model organized by module (auth/k8s/registry) - Add authentication module with login, user management handlers - Update all import paths to use new model locations - Add frontend auth pages (Login, UserManagement) and authStore - Remove deprecated internal/model/model.go
This commit is contained in:
@@ -7,9 +7,10 @@ import (
|
||||
"net"
|
||||
|
||||
"gitea.loveuer.com/loveuer/cluster/internal/middleware"
|
||||
"gitea.loveuer.com/loveuer/cluster/internal/model"
|
||||
"gitea.loveuer.com/loveuer/cluster/internal/module/auth"
|
||||
"gitea.loveuer.com/loveuer/cluster/internal/module/k8s"
|
||||
"gitea.loveuer.com/loveuer/cluster/internal/module/registry"
|
||||
registry_model "gitea.loveuer.com/loveuer/cluster/pkg/model/registry"
|
||||
"gitea.loveuer.com/loveuer/cluster/pkg/store"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"gorm.io/gorm"
|
||||
@@ -33,10 +34,15 @@ func Init(ctx context.Context, address string, db *gorm.DB, store store.Store) (
|
||||
|
||||
// Ensure database migration for RegistryConfig
|
||||
// This is done here to ensure the table exists before config APIs are called
|
||||
if err := db.AutoMigrate(&model.RegistryConfig{}); err != nil {
|
||||
if err := db.AutoMigrate(®istry_model.RegistryConfig{}); err != nil {
|
||||
log.Printf("Warning: failed to migrate RegistryConfig: %v", err)
|
||||
}
|
||||
|
||||
// Initialize auth module
|
||||
if err := auth.Init(ctx, db); err != nil {
|
||||
log.Printf("Warning: failed to initialize auth module: %v", err)
|
||||
}
|
||||
|
||||
// Initialize k8s module
|
||||
if err := k8s.Init(ctx, db, store); err != nil {
|
||||
log.Printf("Warning: failed to initialize k8s module: %v", err)
|
||||
@@ -87,6 +93,20 @@ func Init(ctx context.Context, address string, db *gorm.DB, store store.Store) (
|
||||
k8sAPI.Delete("/service/delete", k8s.K8sServiceDelete(ctx, db, store))
|
||||
}
|
||||
|
||||
// auth apis
|
||||
{
|
||||
authAPI := app.Group("/api/v1/auth")
|
||||
authAPI.Post("/login", auth.Login(ctx, db))
|
||||
authAPI.Get("/wallpaper", auth.Wallpaper(ctx))
|
||||
authAPI.Get("/current", auth.GetCurrentUser(ctx))
|
||||
|
||||
// user management
|
||||
authAPI.Get("/user/list", auth.UserList(ctx, db))
|
||||
authAPI.Post("/user/create", auth.UserCreate(ctx, db))
|
||||
authAPI.Post("/user/update/:id", auth.UserUpdate(ctx, db))
|
||||
authAPI.Delete("/user/delete/:id", auth.UserDelete(ctx, db))
|
||||
}
|
||||
|
||||
ln, err = net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
return fn, fmt.Errorf("failed to listen on %s: %w", address, err)
|
||||
|
||||
Reference in New Issue
Block a user