more caching and auth middleware

This commit is contained in:
Fran Jurmanović
2025-07-01 21:41:48 +02:00
parent 55cf7c049d
commit 12e259270d
5 changed files with 61 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
package controller
import (
"acc-server-manager/local/middleware"
"acc-server-manager/local/service"
"acc-server-manager/local/utl/common"
"acc-server-manager/local/utl/error_handler"
@@ -22,17 +23,19 @@ type ApiController struct {
// *Fiber.RouterGroup: Fiber Router Group
// Returns:
// *ApiController: Controller for "api" interactions
func NewApiController(as *service.ApiService, routeGroups *common.RouteGroups) *ApiController {
func NewApiController(as *service.ApiService, routeGroups *common.RouteGroups, auth *middleware.AuthMiddleware) *ApiController {
ac := &ApiController{
service: as,
errorHandler: error_handler.NewControllerErrorHandler(),
}
routeGroups.Api.Get("/", ac.getFirst)
routeGroups.Api.Get("/:service", ac.getStatus)
routeGroups.Api.Post("/start", ac.startServer)
routeGroups.Api.Post("/stop", ac.stopServer)
routeGroups.Api.Post("/restart", ac.restartServer)
apiGroup := routeGroups.Api
apiGroup.Use(auth.Authenticate)
apiGroup.Get("/", ac.getFirst)
apiGroup.Get("/:service", ac.getStatus)
apiGroup.Post("/start", ac.startServer)
apiGroup.Post("/stop", ac.stopServer)
apiGroup.Post("/restart", ac.restartServer)
return ac
}