api with functioning managment
This commit is contained in:
@@ -25,7 +25,10 @@ func NewApiController(as *service.ApiService, routeGroups *common.RouteGroups) *
|
||||
}
|
||||
|
||||
routeGroups.Api.Get("/", ac.getFirst)
|
||||
routeGroups.Api.Post("/", ac.startServer)
|
||||
routeGroups.Api.Get("/:service", ac.getStatus)
|
||||
routeGroups.Api.Post("/start", ac.startServer)
|
||||
routeGroups.Api.Post("/stop", ac.stopServer)
|
||||
routeGroups.Api.Post("/restart", ac.restartServer)
|
||||
|
||||
return ac
|
||||
}
|
||||
@@ -42,14 +45,30 @@ func (ac *ApiController) getFirst(c *fiber.Ctx) error {
|
||||
return c.SendString(apiModel.Api)
|
||||
}
|
||||
|
||||
// startServer returns API
|
||||
// getStatus returns service status
|
||||
//
|
||||
// @Summary Return API
|
||||
// @Description Return API
|
||||
// @Summary Return service status
|
||||
// @Description Returns service status
|
||||
// @Param service path string true "required"
|
||||
// @Tags api
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/api/{service} [get]
|
||||
func (ac *ApiController) getStatus(c *fiber.Ctx) error {
|
||||
apiModel, err := ac.service.GetStatus(c)
|
||||
if err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
return c.SendString(apiModel)
|
||||
}
|
||||
|
||||
// startServer starts service
|
||||
//
|
||||
// @Summary Start service
|
||||
// @Description Starts service
|
||||
// @Param name body string true "required"
|
||||
// @Tags api
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/api [post]
|
||||
// @Router /v1/api/start [post]
|
||||
func (ac *ApiController) startServer(c *fiber.Ctx) error {
|
||||
model := new(Service)
|
||||
if err := c.BodyParser(model); err != nil {
|
||||
@@ -58,7 +77,49 @@ func (ac *ApiController) startServer(c *fiber.Ctx) error {
|
||||
c.Locals("service", model.Name)
|
||||
apiModel, err := ac.service.ApiStartServer(c)
|
||||
if err != nil {
|
||||
return c.SendStatus(400)
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
return c.SendString(apiModel)
|
||||
}
|
||||
|
||||
// stopServer stops service
|
||||
//
|
||||
// @Summary Stop service
|
||||
// @Description Stops service
|
||||
// @Param name body string true "required"
|
||||
// @Tags api
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/api/stop [post]
|
||||
func (ac *ApiController) stopServer(c *fiber.Ctx) error {
|
||||
model := new(Service)
|
||||
if err := c.BodyParser(model); err != nil {
|
||||
c.SendStatus(400)
|
||||
}
|
||||
c.Locals("service", model.Name)
|
||||
apiModel, err := ac.service.ApiStopServer(c)
|
||||
if err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
return c.SendString(apiModel)
|
||||
}
|
||||
|
||||
// restartServer returns API
|
||||
//
|
||||
// @Summary Restart service
|
||||
// @Description Restarts service
|
||||
// @Param name body string true "required"
|
||||
// @Tags api
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/api/restart [post]
|
||||
func (ac *ApiController) restartServer(c *fiber.Ctx) error {
|
||||
model := new(Service)
|
||||
if err := c.BodyParser(model); err != nil {
|
||||
c.SendStatus(400)
|
||||
}
|
||||
c.Locals("service", model.Name)
|
||||
apiModel, err := ac.service.ApiRestartServer(c)
|
||||
if err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
return c.SendString(apiModel)
|
||||
}
|
||||
|
||||
89
local/controller/config.go
Normal file
89
local/controller/config.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"acc-server-manager/local/service"
|
||||
"acc-server-manager/local/utl/common"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type ConfigController struct {
|
||||
service *service.ConfigService
|
||||
}
|
||||
|
||||
// NewConfigController
|
||||
// Initializes ConfigController.
|
||||
//
|
||||
// Args:
|
||||
// *services.ConfigService: Config service
|
||||
// *Fiber.RouterGroup: Fiber Router Group
|
||||
// Returns:
|
||||
// *ConfigController: Controller for "Config" interactions
|
||||
func NewConfigController(as *service.ConfigService, routeGroups *common.RouteGroups) *ConfigController {
|
||||
ac := &ConfigController{
|
||||
service: as,
|
||||
}
|
||||
|
||||
routeGroups.Config.Put("/:file", ac.updateConfig)
|
||||
routeGroups.Config.Get("/:file", ac.getConfig)
|
||||
routeGroups.Config.Get("/", ac.getConfigs)
|
||||
|
||||
return ac
|
||||
}
|
||||
|
||||
// updateConfig returns Config
|
||||
//
|
||||
// @Summary Update config
|
||||
// @Description Updates config
|
||||
// @Param id path number true "required"
|
||||
// @Param file path string true "required"
|
||||
// @Param content body string true "required"
|
||||
// @Tags Config
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/server/{id}/config/{file} [put]
|
||||
func (ac *ConfigController) updateConfig(c *fiber.Ctx) error {
|
||||
|
||||
var config map[string]interface{}
|
||||
if err := c.BodyParser(&config); err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "Invalid config format"})
|
||||
}
|
||||
|
||||
ConfigModel, err := ac.service.UpdateConfig(c, &config)
|
||||
if err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
return c.JSON(ConfigModel)
|
||||
}
|
||||
|
||||
// getConfig returns Config
|
||||
//
|
||||
// @Summary Return Config file
|
||||
// @Description Returns Config file
|
||||
// @Param id path number true "required"
|
||||
// @Param file path string true "required"
|
||||
// @Tags Config
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/server/{id}/config/{file} [get]
|
||||
func (ac *ConfigController) getConfig(c *fiber.Ctx) error {
|
||||
Model, err := ac.service.GetConfig(c)
|
||||
if err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
return c.JSON(Model)
|
||||
}
|
||||
|
||||
// getConfigs returns Config
|
||||
//
|
||||
// @Summary Return Configs
|
||||
// @Description Return Config files
|
||||
// @Param id path number true "required"
|
||||
// @Tags Config
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/server/{id}/config [get]
|
||||
func (ac *ConfigController) getConfigs(c *fiber.Ctx) error {
|
||||
Model, err := ac.service.GetConfigs(c)
|
||||
if err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
return c.JSON(Model)
|
||||
}
|
||||
@@ -24,6 +24,21 @@ func InitializeControllers(c *dig.Container) {
|
||||
if err != nil {
|
||||
panic("unable to initialize api controller")
|
||||
}
|
||||
|
||||
err = c.Invoke(NewConfigController)
|
||||
if err != nil {
|
||||
panic("unable to initialize config controller")
|
||||
}
|
||||
|
||||
err = c.Invoke(NewServerController)
|
||||
if err != nil {
|
||||
panic("unable to initialize server controller")
|
||||
}
|
||||
|
||||
err = c.Invoke(NewLookupController)
|
||||
if err != nil {
|
||||
panic("unable to initialize lookup controller")
|
||||
}
|
||||
}
|
||||
|
||||
// FilteredResponse
|
||||
|
||||
93
local/controller/lookup.go
Normal file
93
local/controller/lookup.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"acc-server-manager/local/service"
|
||||
"acc-server-manager/local/utl/common"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type LookupController struct {
|
||||
service *service.LookupService
|
||||
}
|
||||
|
||||
// NewLookupController
|
||||
// Initializes LookupController.
|
||||
//
|
||||
// Args:
|
||||
// *services.LookupService: Lookup service
|
||||
// *Fiber.RouterGroup: Fiber Router Group
|
||||
// Returns:
|
||||
// *LookupController: Controller for "Lookup" interactions
|
||||
func NewLookupController(as *service.LookupService, routeGroups *common.RouteGroups) *LookupController {
|
||||
ac := &LookupController{
|
||||
service: as,
|
||||
}
|
||||
routeGroups.Lookup.Get("/tracks", ac.getTracks)
|
||||
routeGroups.Lookup.Get("/car-models", ac.getCarModels)
|
||||
routeGroups.Lookup.Get("/driver-categories", ac.getDriverCategories)
|
||||
routeGroups.Lookup.Get("/cup-categories", ac.getCupCategories)
|
||||
routeGroups.Lookup.Get("/session-types", ac.getSessionTypes)
|
||||
|
||||
return ac
|
||||
}
|
||||
|
||||
// getTracks returns Tracks
|
||||
//
|
||||
// @Summary Return Tracks Lookup
|
||||
// @Description Return Tracks Lookup
|
||||
// @Tags Lookup
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/lookup/tracks [get]
|
||||
func (ac *LookupController) getTracks(c *fiber.Ctx) error {
|
||||
LookupModel := ac.service.GetTracks(c)
|
||||
return c.JSON(LookupModel)
|
||||
}
|
||||
|
||||
// getCarModels returns CarModels
|
||||
//
|
||||
// @Summary Return CarModels Lookup
|
||||
// @Description Return CarModels Lookup
|
||||
// @Tags Lookup
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/lookup/car-models [get]
|
||||
func (ac *LookupController) getCarModels(c *fiber.Ctx) error {
|
||||
LookupModel := ac.service.GetCarModels(c)
|
||||
return c.JSON(LookupModel)
|
||||
}
|
||||
|
||||
// getDriverCategories returns DriverCategories
|
||||
//
|
||||
// @Summary Return DriverCategories Lookup
|
||||
// @Description Return DriverCategories Lookup
|
||||
// @Tags Lookup
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/lookup/driver-categories [get]
|
||||
func (ac *LookupController) getDriverCategories(c *fiber.Ctx) error {
|
||||
LookupModel := ac.service.GetDriverCategories(c)
|
||||
return c.JSON(LookupModel)
|
||||
}
|
||||
|
||||
// getCupCategories returns CupCategories
|
||||
//
|
||||
// @Summary Return CupCategories Lookup
|
||||
// @Description Return CupCategories Lookup
|
||||
// @Tags Lookup
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/lookup/cup-categories [get]
|
||||
func (ac *LookupController) getCupCategories(c *fiber.Ctx) error {
|
||||
LookupModel := ac.service.GetCupCategories(c)
|
||||
return c.JSON(LookupModel)
|
||||
}
|
||||
|
||||
// getSessionTypes returns SessionTypes
|
||||
//
|
||||
// @Summary Return SessionTypes Lookup
|
||||
// @Description Return SessionTypes Lookup
|
||||
// @Tags Lookup
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/lookup/session-types [get]
|
||||
func (ac *LookupController) getSessionTypes(c *fiber.Ctx) error {
|
||||
LookupModel := ac.service.GetSessionTypes(c)
|
||||
return c.JSON(LookupModel)
|
||||
}
|
||||
42
local/controller/server.go
Normal file
42
local/controller/server.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"acc-server-manager/local/service"
|
||||
"acc-server-manager/local/utl/common"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type ServerController struct {
|
||||
service *service.ServerService
|
||||
}
|
||||
|
||||
// NewServerController
|
||||
// Initializes ServerController.
|
||||
//
|
||||
// Args:
|
||||
// *services.ServerService: Server service
|
||||
// *Fiber.RouterGroup: Fiber Router Group
|
||||
// Returns:
|
||||
// *ServerController: Controller for "Server" interactions
|
||||
func NewServerController(as *service.ServerService, routeGroups *common.RouteGroups) *ServerController {
|
||||
ac := &ServerController{
|
||||
service: as,
|
||||
}
|
||||
|
||||
routeGroups.Server.Get("/", ac.getAll)
|
||||
|
||||
return ac
|
||||
}
|
||||
|
||||
// getAll returns Servers
|
||||
//
|
||||
// @Summary Return Servers
|
||||
// @Description Return Servers
|
||||
// @Tags Server
|
||||
// @Success 200 {array} string
|
||||
// @Router /v1/server [get]
|
||||
func (ac *ServerController) getAll(c *fiber.Ctx) error {
|
||||
ServerModel := ac.service.GetAll(c)
|
||||
return c.JSON(ServerModel)
|
||||
}
|
||||
Reference in New Issue
Block a user