Refactor user handler and middleware for improved error handling and logging

- Consolidated user ID retrieval and permission checks into helper functions.
- Updated UserHandler to utilize BaseHandler for common database and configuration access.
- Enhanced logging for user-related operations, including login, registration, and password changes.
- Removed redundant context handling in middleware and improved readability.
- Introduced FileUtil for file URL generation and management, encapsulating file-related logic.
- Refactored FileRepo and UserRepo to streamline database operations and error handling.
- Deleted unused request_id middleware and integrated its functionality into request_logger.
- Removed legacy test runner script to simplify testing process.
This commit is contained in:
limitcool
2025-06-17 23:09:02 +08:00
parent 36d816d908
commit b7628c770b
16 changed files with 588 additions and 407 deletions

View File

@@ -10,18 +10,16 @@ import (
// AdminHandler 管理员处理器
type AdminHandler struct {
db *gorm.DB
config *configs.Config
*BaseHandler
}
// NewAdminHandler 创建管理员处理器
func NewAdminHandler(db *gorm.DB, config *configs.Config) *AdminHandler {
handler := &AdminHandler{
db: db,
config: config,
BaseHandler: NewBaseHandler(db, config),
}
logger.Info("AdminHandler initialized")
handler.LogInit("AdminHandler")
return handler
}
@@ -35,9 +33,9 @@ func (h *AdminHandler) GetSystemSettings(ctx *gin.Context) {
// 返回系统设置
settings := map[string]any{
"app_name": h.config.App.Name,
"app_name": h.Config.App.Name,
"app_version": "1.0.0",
"app_mode": h.config.App.Mode,
"app_mode": h.Config.App.Mode,
}
response.Success(ctx, settings)