refactor(config): changed to settings to match the other lst in node. makes it more easy to manage
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"lst.net/utils/db"
|
||||
logging "lst.net/utils/logger"
|
||||
)
|
||||
|
||||
type ConfigUpdateInput struct {
|
||||
Description *string `json:"description"`
|
||||
Value *string `json:"value"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
AppService *string `json:"app_service"`
|
||||
}
|
||||
|
||||
func RegisterConfigRoutes(l *gin.Engine, baseUrl string) {
|
||||
// seed the db on start up
|
||||
db.SeedConfigs(db.DB)
|
||||
|
||||
configGroup := l.Group(baseUrl + "/api/config")
|
||||
configGroup.GET("/configs", getconfigs)
|
||||
configGroup.POST("/configs", newConfig)
|
||||
}
|
||||
|
||||
func getconfigs(c *gin.Context) {
|
||||
log := logging.New()
|
||||
configs, err := db.GetAllConfigs(db.DB)
|
||||
log.Info("Current Configs", "system", map[string]interface{}{
|
||||
"endpoint": "/api/config/configs",
|
||||
"client_ip": c.ClientIP(),
|
||||
"user_agent": c.Request.UserAgent(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"message": "There was an error getting the configs", "error": err})
|
||||
}
|
||||
|
||||
c.JSON(200, gin.H{"message": "Current configs", "data": configs})
|
||||
}
|
||||
|
||||
func newConfig(c *gin.Context) {
|
||||
|
||||
var config ConfigUpdateInput
|
||||
|
||||
err := c.ShouldBindBodyWithJSON(&config)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"message": "Internal Server Error"})
|
||||
}
|
||||
|
||||
c.JSON(200, gin.H{"message": "New config was just added", "data": config})
|
||||
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
package system
|
||||
package servers
|
||||
|
||||
65
backend/cmd/services/system/settings/settings.go
Normal file
65
backend/cmd/services/system/settings/settings.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"lst.net/utils/db"
|
||||
logging "lst.net/utils/logger"
|
||||
)
|
||||
|
||||
type SettingUpdateInput struct {
|
||||
Description *string `json:"description"`
|
||||
Value *string `json:"value"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
AppService *string `json:"app_service"`
|
||||
}
|
||||
|
||||
func RegisterSettingsRoutes(l *gin.Engine, baseUrl string) {
|
||||
// seed the db on start up
|
||||
db.SeedConfigs(db.DB)
|
||||
|
||||
s := l.Group(baseUrl + "/api/v1")
|
||||
s.GET("/settings", getSettings)
|
||||
s.PATCH("/settings", updateSettingById)
|
||||
}
|
||||
|
||||
func getSettings(c *gin.Context) {
|
||||
logger := logging.New()
|
||||
configs, err := db.GetAllConfigs(db.DB)
|
||||
logger.Info("Current Settings", "system", map[string]interface{}{
|
||||
"endpoint": "/api/v1/settings",
|
||||
"client_ip": c.ClientIP(),
|
||||
"user_agent": c.Request.UserAgent(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
logger.Error("Current Settings", "system", map[string]interface{}{
|
||||
"endpoint": "/api/v1/settings",
|
||||
"client_ip": c.ClientIP(),
|
||||
"user_agent": c.Request.UserAgent(),
|
||||
"error": err,
|
||||
})
|
||||
c.JSON(500, gin.H{"message": "There was an error getting the settings", "error": err})
|
||||
}
|
||||
|
||||
c.JSON(200, gin.H{"message": "Current settings", "data": configs})
|
||||
}
|
||||
|
||||
func updateSettingById(c *gin.Context) {
|
||||
logger := logging.New()
|
||||
var setting SettingUpdateInput
|
||||
|
||||
err := c.ShouldBindBodyWithJSON(&setting)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"message": "Internal Server Error"})
|
||||
logger.Error("Current Settings", "system", map[string]interface{}{
|
||||
"endpoint": "/api/v1/settings",
|
||||
"client_ip": c.ClientIP(),
|
||||
"user_agent": c.Request.UserAgent(),
|
||||
"error": err,
|
||||
})
|
||||
}
|
||||
|
||||
c.JSON(200, gin.H{"message": "Setting was just updated", "data": setting})
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package system
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/joho/godotenv"
|
||||
"lst.net/cmd/services/system/config"
|
||||
"lst.net/cmd/services/system/settings"
|
||||
"lst.net/cmd/services/websocket"
|
||||
|
||||
_ "lst.net/docs"
|
||||
@@ -115,7 +115,7 @@ func main() {
|
||||
|
||||
//logging.RegisterLoggerRoutes(r, basePath)
|
||||
websocket.RegisterSocketRoutes(r, basePath)
|
||||
config.RegisterConfigRoutes(r, basePath)
|
||||
settings.RegisterSettingsRoutes(r, basePath)
|
||||
|
||||
r.Any(basePath+"/api", errorApiLoc)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user