get server by id
This commit is contained in:
@@ -3,6 +3,7 @@ package controller
|
||||
import (
|
||||
"acc-server-manager/local/service"
|
||||
"acc-server-manager/local/utl/common"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
@@ -54,19 +55,19 @@ func (ac *ApiController) getFirst(c *fiber.Ctx) error {
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/api/{service} [get]
|
||||
func (ac *ApiController) getStatus(c *fiber.Ctx) error {
|
||||
serverId, err := c.ParamsInt("serverId")
|
||||
if err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
if serverId == 0 {
|
||||
service := c.Params("service")
|
||||
c.Locals("service", service)
|
||||
} else {
|
||||
service := c.Params("service")
|
||||
if service == "" {
|
||||
serverId, err := c.ParamsInt("service")
|
||||
if err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
c.Locals("serverId", serverId)
|
||||
} else {
|
||||
c.Locals("service", service)
|
||||
}
|
||||
apiModel, err := ac.service.GetStatus(c)
|
||||
if err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
return c.Status(400).SendString(strings.ReplaceAll(err.Error(), "\x00", ""))
|
||||
}
|
||||
return c.SendString(apiModel)
|
||||
}
|
||||
@@ -88,7 +89,7 @@ func (ac *ApiController) startServer(c *fiber.Ctx) error {
|
||||
c.Locals("serverId", model.ServerId)
|
||||
apiModel, err := ac.service.ApiStartServer(c)
|
||||
if err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
return c.Status(400).SendString(strings.ReplaceAll(err.Error(), "\x00", ""))
|
||||
}
|
||||
return c.SendString(apiModel)
|
||||
}
|
||||
@@ -110,7 +111,7 @@ func (ac *ApiController) stopServer(c *fiber.Ctx) error {
|
||||
c.Locals("serverId", model.ServerId)
|
||||
apiModel, err := ac.service.ApiStopServer(c)
|
||||
if err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
return c.Status(400).SendString(strings.ReplaceAll(err.Error(), "\x00", ""))
|
||||
}
|
||||
return c.SendString(apiModel)
|
||||
}
|
||||
@@ -132,7 +133,7 @@ func (ac *ApiController) restartServer(c *fiber.Ctx) error {
|
||||
c.Locals("serverId", model.ServerId)
|
||||
apiModel, err := ac.service.ApiRestartServer(c)
|
||||
if err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
return c.Status(400).SendString(strings.ReplaceAll(err.Error(), "\x00", ""))
|
||||
}
|
||||
return c.SendString(apiModel)
|
||||
}
|
||||
|
||||
@@ -58,7 +58,11 @@ func (ac *ConfigController) updateConfig(c *fiber.Ctx) error {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
if restart {
|
||||
ac.apiService.RestartServer(c)
|
||||
serviceName, err := ac.apiService.GetServiceName(c)
|
||||
if err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "Unable to restart service"})
|
||||
}
|
||||
ac.apiService.RestartServer(serviceName)
|
||||
}
|
||||
|
||||
return c.JSON(ConfigModel)
|
||||
|
||||
@@ -25,6 +25,7 @@ func NewServerController(as *service.ServerService, routeGroups *common.RouteGro
|
||||
}
|
||||
|
||||
routeGroups.Server.Get("/", ac.getAll)
|
||||
routeGroups.Server.Get("/:id", ac.getById)
|
||||
|
||||
return ac
|
||||
}
|
||||
@@ -40,3 +41,16 @@ func (ac *ServerController) getAll(c *fiber.Ctx) error {
|
||||
ServerModel := ac.service.GetAll(c)
|
||||
return c.JSON(ServerModel)
|
||||
}
|
||||
|
||||
// getById returns Servers
|
||||
//
|
||||
// @Summary Return Servers
|
||||
// @Description Return Servers
|
||||
// @Tags Server
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/server [get]
|
||||
func (ac *ServerController) getById(c *fiber.Ctx) error {
|
||||
serverID, _ := c.ParamsInt("id")
|
||||
ServerModel := ac.service.GetById(c, serverID)
|
||||
return c.JSON(ServerModel)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user