Feature (System Settings): Implemented system settings management functionality (#13556)

### What problem does this PR solve?

Feature (System Settings): Implemented system settings management
functionality

- Added a new SystemSettings model, including creation and update time
fields.

- Implemented SystemSettingsDAO, providing CRUD operations and
transaction support.

- Implemented management interfaces for variables, configurations, and
environment variables in the admin service.

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

Co-authored-by: Yingfeng <yingfeng.zhang@gmail.com>
This commit is contained in:
chanx
2026-03-12 19:06:20 +08:00
committed by GitHub
parent 7c79602c77
commit 1df804a14a
4 changed files with 410 additions and 39 deletions

View File

@@ -767,28 +767,46 @@ func (h *Handler) RestartService(c *gin.Context) {
}
// GetVariables handle get variables
// Python logic: if request body is empty, list all variables; otherwise get single variable by var_name from body
func (h *Handler) GetVariables(c *gin.Context) {
varName := c.Query("var_name")
if varName != "" {
// Get single variable
variable, err := h.service.GetVariable(varName)
// Check if request has body content
if c.Request.ContentLength == 0 || c.Request.ContentLength == -1 {
// List all variables
variables, err := h.service.GetAllVariables()
if err != nil {
errorResponse(c, err.Error(), 400)
errorResponse(c, err.Error(), 500)
return
}
success(c, variable, "")
success(c, variables, "")
return
}
// List all variables
variables, err := h.service.GetAllVariables()
// Get single variable by var_name from request body
var req struct {
VarName string `json:"var_name"`
}
if err := c.ShouldBindJSON(&req); err != nil {
errorResponse(c, "Invalid request body", 400)
return
}
if req.VarName == "" {
errorResponse(c, "Var name is required", 400)
return
}
variable, err := h.service.GetVariable(req.VarName)
if err != nil {
// Check if it's an AdminException
if adminErr, ok := err.(*AdminException); ok {
errorResponse(c, adminErr.Message, 400)
return
}
errorResponse(c, err.Error(), 500)
return
}
success(c, variables, "")
success(c, variable, "")
}
// SetVariableHTTPRequest set variable request
@@ -798,15 +816,31 @@ type SetVariableHTTPRequest struct {
}
// SetVariable handle set variable
// Python logic: update or create a system setting with the given name and value
func (h *Handler) SetVariable(c *gin.Context) {
var req SetVariableHTTPRequest
if err := c.ShouldBindJSON(&req); err != nil {
errorResponse(c, "Var name and value are required", 400)
errorResponse(c, "Var name is required", 400)
return
}
if req.VarName == "" {
errorResponse(c, "Var name is required", 400)
return
}
if req.VarValue == "" {
errorResponse(c, "Var value is required", 400)
return
}
if err := h.service.SetVariable(req.VarName, req.VarValue); err != nil {
errorResponse(c, err.Error(), 400)
// Check if it's an AdminException
if adminErr, ok := err.(*AdminException); ok {
errorResponse(c, adminErr.Message, 400)
return
}
errorResponse(c, err.Error(), 500)
return
}
@@ -814,10 +848,16 @@ func (h *Handler) SetVariable(c *gin.Context) {
}
// GetConfigs handle get configs
// Python logic: return all service configurations
func (h *Handler) GetConfigs(c *gin.Context) {
configs, err := h.service.GetAllConfigs()
if err != nil {
errorResponse(c, err.Error(), 400)
// Check if it's an AdminException
if adminErr, ok := err.(*AdminException); ok {
errorResponse(c, adminErr.Message, 400)
return
}
errorResponse(c, err.Error(), 500)
return
}
@@ -825,10 +865,16 @@ func (h *Handler) GetConfigs(c *gin.Context) {
}
// GetEnvironments handle get environments
// Python logic: return important environment variables
func (h *Handler) GetEnvironments(c *gin.Context) {
environments, err := h.service.GetAllEnvironments()
if err != nil {
errorResponse(c, err.Error(), 400)
// Check if it's an AdminException
if adminErr, ok := err.(*AdminException); ok {
errorResponse(c, adminErr.Message, 400)
return
}
errorResponse(c, err.Error(), 500)
return
}