初始化
This commit is contained in:
67
server/handlers/setting.go
Normal file
67
server/handlers/setting.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/niangaodev/art-code/models"
|
||||
"github.com/niangaodev/art-code/repositories"
|
||||
)
|
||||
|
||||
// 获取系统配置列表
|
||||
func AdminGetSettings(c *gin.Context) {
|
||||
settings, err := repositories.GetSettings()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get settings"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, repositories.BuildSettingsResponse(settings))
|
||||
}
|
||||
|
||||
// 更新系统配置
|
||||
func AdminUpdateSetting(c *gin.Context) {
|
||||
var setting models.Setting
|
||||
if err := c.ShouldBindJSON(&setting); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
|
||||
return
|
||||
}
|
||||
|
||||
// 更新系统配置
|
||||
if err := repositories.UpdateSetting(&setting); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to update setting"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Setting updated successfully"})
|
||||
}
|
||||
|
||||
// 创建系统配置
|
||||
func AdminCreateSetting(c *gin.Context) {
|
||||
var setting models.Setting
|
||||
if err := c.ShouldBindJSON(&setting); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
|
||||
return
|
||||
}
|
||||
|
||||
// 创建系统配置
|
||||
if err := repositories.CreateSetting(&setting); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create setting"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Setting created successfully"})
|
||||
}
|
||||
|
||||
// 删除系统配置
|
||||
func AdminDeleteSetting(c *gin.Context) {
|
||||
keyName := c.Param("key")
|
||||
|
||||
// 删除系统配置
|
||||
if err := repositories.DeleteSetting(keyName); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to delete setting"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Setting deleted successfully"})
|
||||
}
|
||||
Reference in New Issue
Block a user