57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
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)
|
|
routeGroups.Server.Get("/:id", ac.getById)
|
|
|
|
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)
|
|
}
|
|
|
|
// 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)
|
|
}
|