update docs
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
type ConfigController struct {
|
||||
service *service.ConfigService
|
||||
apiService *service.ApiService
|
||||
apiService *service.ServiceControlService
|
||||
errorHandler *error_handler.ControllerErrorHandler
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ type ConfigController struct {
|
||||
// *Fiber.RouterGroup: Fiber Router Group
|
||||
// Returns:
|
||||
// *ConfigController: Controller for "Config" interactions
|
||||
func NewConfigController(as *service.ConfigService, routeGroups *common.RouteGroups, as2 *service.ApiService, auth *middleware.AuthMiddleware) *ConfigController {
|
||||
func NewConfigController(as *service.ConfigService, routeGroups *common.RouteGroups, as2 *service.ServiceControlService, auth *middleware.AuthMiddleware) *ConfigController {
|
||||
ac := &ConfigController{
|
||||
service: as,
|
||||
apiService: as2,
|
||||
@@ -43,13 +43,21 @@ func NewConfigController(as *service.ConfigService, routeGroups *common.RouteGro
|
||||
|
||||
// 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
|
||||
// @Summary Update server configuration file
|
||||
// @Description Update a specific configuration file for an ACC server
|
||||
// @Tags Server Configuration
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Server ID (UUID format)"
|
||||
// @Param file path string true "Config file name (e.g., configuration.json, settings.json, event.json)"
|
||||
// @Param content body object true "Configuration file content as JSON"
|
||||
// @Success 200 {object} object{message=string} "Update successful"
|
||||
// @Failure 400 {object} error_handler.ErrorResponse "Invalid request or JSON format"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||
// @Failure 404 {object} error_handler.ErrorResponse "Server or config file not found"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /v1/server/{id}/config/{file} [put]
|
||||
func (ac *ConfigController) UpdateConfig(c *fiber.Ctx) error {
|
||||
restart := c.QueryBool("restart")
|
||||
@@ -73,7 +81,7 @@ func (ac *ConfigController) UpdateConfig(c *fiber.Ctx) error {
|
||||
}
|
||||
logging.Info("restart: %v", restart)
|
||||
if restart {
|
||||
_, err := ac.apiService.ApiRestartServer(c)
|
||||
_, err := ac.apiService.ServiceControlRestartServer(c)
|
||||
if err != nil {
|
||||
logging.ErrorWithContext("CONFIG_RESTART", "Failed to restart server after config update: %v", err)
|
||||
}
|
||||
@@ -84,12 +92,20 @@ func (ac *ConfigController) UpdateConfig(c *fiber.Ctx) error {
|
||||
|
||||
// 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
|
||||
// @Summary Get server configuration file
|
||||
// @Description Retrieve a specific configuration file for an ACC server
|
||||
// @Tags Server Configuration
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Server ID (UUID format)"
|
||||
// @Param file path string true "Config file name (e.g., configuration.json, settings.json, event.json)"
|
||||
// @Success 200 {object} object "Configuration file content as JSON"
|
||||
// @Failure 400 {object} error_handler.ErrorResponse "Invalid server ID"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||
// @Failure 404 {object} error_handler.ErrorResponse "Server or config file not found"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /v1/server/{id}/config/{file} [get]
|
||||
func (ac *ConfigController) GetConfig(c *fiber.Ctx) error {
|
||||
Model, err := ac.service.GetConfig(c)
|
||||
@@ -101,11 +117,19 @@ func (ac *ConfigController) GetConfig(c *fiber.Ctx) error {
|
||||
|
||||
// getConfigs returns Config
|
||||
//
|
||||
// @Summary Return Configs
|
||||
// @Description Return Config files
|
||||
// @Param id path number true "required"
|
||||
// @Tags Config
|
||||
// @Success 200 {array} string
|
||||
// @Summary List available configuration files
|
||||
// @Description Get a list of all available configuration files for an ACC server
|
||||
// @Tags Server Configuration
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Server ID (UUID format)"
|
||||
// @Success 200 {array} string "List of available configuration files"
|
||||
// @Failure 400 {object} error_handler.ErrorResponse "Invalid server ID"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||
// @Failure 404 {object} error_handler.ErrorResponse "Server not found"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /v1/server/{id}/config [get]
|
||||
func (ac *ConfigController) GetConfigs(c *fiber.Ctx) error {
|
||||
Model, err := ac.service.GetConfigs(c)
|
||||
|
||||
@@ -20,9 +20,9 @@ func InitializeControllers(c *dig.Container) {
|
||||
logging.Panic("unable to initialize auth middleware")
|
||||
}
|
||||
|
||||
err := c.Invoke(NewApiController)
|
||||
err := c.Invoke(NewServiceControlController)
|
||||
if err != nil {
|
||||
logging.Panic("unable to initialize api controller")
|
||||
logging.Panic("unable to initialize service control controller")
|
||||
}
|
||||
|
||||
err = c.Invoke(NewConfigController)
|
||||
|
||||
@@ -37,10 +37,15 @@ func NewLookupController(as *service.LookupService, routeGroups *common.RouteGro
|
||||
|
||||
// getTracks returns Tracks
|
||||
//
|
||||
// @Summary Return Tracks Lookup
|
||||
// @Description Return Tracks Lookup
|
||||
// @Tags Lookup
|
||||
// @Success 200 {array} string
|
||||
// @Summary Get available tracks
|
||||
// @Description Get a list of all available ACC tracks with their identifiers
|
||||
// @Tags Lookups
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} object{id=string,name=string} "List of tracks"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /v1/lookup/tracks [get]
|
||||
func (ac *LookupController) GetTracks(c *fiber.Ctx) error {
|
||||
result, err := ac.service.GetTracks(c)
|
||||
@@ -52,10 +57,15 @@ func (ac *LookupController) GetTracks(c *fiber.Ctx) error {
|
||||
|
||||
// getCarModels returns CarModels
|
||||
//
|
||||
// @Summary Return CarModels Lookup
|
||||
// @Description Return CarModels Lookup
|
||||
// @Tags Lookup
|
||||
// @Success 200 {array} string
|
||||
// @Summary Get available car models
|
||||
// @Description Get a list of all available ACC car models with their identifiers
|
||||
// @Tags Lookups
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} object{id=string,name=string,class=string} "List of car models"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /v1/lookup/car-models [get]
|
||||
func (ac *LookupController) GetCarModels(c *fiber.Ctx) error {
|
||||
result, err := ac.service.GetCarModels(c)
|
||||
@@ -67,10 +77,15 @@ func (ac *LookupController) GetCarModels(c *fiber.Ctx) error {
|
||||
|
||||
// getDriverCategories returns DriverCategories
|
||||
//
|
||||
// @Summary Return DriverCategories Lookup
|
||||
// @Description Return DriverCategories Lookup
|
||||
// @Tags Lookup
|
||||
// @Success 200 {array} string
|
||||
// @Summary Get driver categories
|
||||
// @Description Get a list of all driver categories (Bronze, Silver, Gold, Platinum)
|
||||
// @Tags Lookups
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} object{id=number,name=string,description=string} "List of driver categories"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /v1/lookup/driver-categories [get]
|
||||
func (ac *LookupController) GetDriverCategories(c *fiber.Ctx) error {
|
||||
result, err := ac.service.GetDriverCategories(c)
|
||||
@@ -82,10 +97,15 @@ func (ac *LookupController) GetDriverCategories(c *fiber.Ctx) error {
|
||||
|
||||
// getCupCategories returns CupCategories
|
||||
//
|
||||
// @Summary Return CupCategories Lookup
|
||||
// @Description Return CupCategories Lookup
|
||||
// @Tags Lookup
|
||||
// @Success 200 {array} string
|
||||
// @Summary Get cup categories
|
||||
// @Description Get a list of all available racing cup categories
|
||||
// @Tags Lookups
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} object{id=number,name=string} "List of cup categories"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /v1/lookup/cup-categories [get]
|
||||
func (ac *LookupController) GetCupCategories(c *fiber.Ctx) error {
|
||||
result, err := ac.service.GetCupCategories(c)
|
||||
@@ -97,10 +117,15 @@ func (ac *LookupController) GetCupCategories(c *fiber.Ctx) error {
|
||||
|
||||
// getSessionTypes returns SessionTypes
|
||||
//
|
||||
// @Summary Return SessionTypes Lookup
|
||||
// @Description Return SessionTypes Lookup
|
||||
// @Tags Lookup
|
||||
// @Success 200 {array} string
|
||||
// @Summary Get session types
|
||||
// @Description Get a list of all available session types (Practice, Qualifying, Race)
|
||||
// @Tags Lookups
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} object{id=string,name=string,code=string} "List of session types"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /v1/lookup/session-types [get]
|
||||
func (ac *LookupController) GetSessionTypes(c *fiber.Ctx) error {
|
||||
result, err := ac.service.GetSessionTypes(c)
|
||||
|
||||
@@ -51,6 +51,17 @@ func NewMembershipController(service *service.MembershipService, auth *middlewar
|
||||
}
|
||||
|
||||
// Login handles user login.
|
||||
// @Summary User login
|
||||
// @Description Authenticate a user and receive a JWT token
|
||||
// @Tags Authentication
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param credentials body object{username=string,password=string} true "Login credentials"
|
||||
// @Success 200 {object} object{token=string} "JWT token"
|
||||
// @Failure 400 {object} error_handler.ErrorResponse "Invalid request body"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Invalid credentials"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Router /auth/login [post]
|
||||
func (c *MembershipController) Login(ctx *fiber.Ctx) error {
|
||||
type request struct {
|
||||
Username string `json:"username"`
|
||||
@@ -72,6 +83,20 @@ func (c *MembershipController) Login(ctx *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// CreateUser creates a new user.
|
||||
// @Summary Create a new user
|
||||
// @Description Create a new user account with specified role
|
||||
// @Tags User Management
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param user body object{username=string,password=string,role=string} true "User details"
|
||||
// @Success 200 {object} model.User "Created user details"
|
||||
// @Failure 400 {object} error_handler.ErrorResponse "Invalid request body"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||
// @Failure 409 {object} error_handler.ErrorResponse "User already exists"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /membership [post]
|
||||
func (mc *MembershipController) CreateUser(c *fiber.Ctx) error {
|
||||
type request struct {
|
||||
Username string `json:"username"`
|
||||
@@ -93,6 +118,17 @@ func (mc *MembershipController) CreateUser(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// ListUsers lists all users.
|
||||
// @Summary List all users
|
||||
// @Description Get a list of all registered users
|
||||
// @Tags User Management
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} model.User "List of users"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /membership [get]
|
||||
func (mc *MembershipController) ListUsers(c *fiber.Ctx) error {
|
||||
users, err := mc.service.ListUsers(c.UserContext())
|
||||
if err != nil {
|
||||
|
||||
@@ -34,10 +34,23 @@ func NewServerController(ss *service.ServerService, routeGroups *common.RouteGro
|
||||
|
||||
apiServerRoutes := routeGroups.Api.Group("/server")
|
||||
apiServerRoutes.Get("/", auth.HasPermission(model.ServerView), ac.GetAllApi)
|
||||
|
||||
return ac
|
||||
}
|
||||
|
||||
// GetAll returns Servers
|
||||
// GetAllApi returns all servers in API format
|
||||
// @Summary List all servers (API format)
|
||||
// @Description Get a list of all ACC servers with filtering options
|
||||
// @Tags Server
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param filter query model.ServerFilter false "Filter options"
|
||||
// @Success 200 {array} model.ServerAPI "List of servers"
|
||||
// @Failure 400 {object} error_handler.ErrorResponse "Invalid filter parameters"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /server [get]
|
||||
func (ac *ServerController) GetAllApi(c *fiber.Ctx) error {
|
||||
var filter model.ServerFilter
|
||||
if err := common.ParseQueryFilter(c, &filter); err != nil {
|
||||
@@ -53,6 +66,20 @@ func (ac *ServerController) GetAllApi(c *fiber.Ctx) error {
|
||||
}
|
||||
return c.JSON(apiServers)
|
||||
}
|
||||
|
||||
// GetAll returns all servers
|
||||
// @Summary List all servers
|
||||
// @Description Get a list of all ACC servers with detailed information
|
||||
// @Tags Server
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param filter query model.ServerFilter false "Filter options"
|
||||
// @Success 200 {array} model.Server "List of servers with full details"
|
||||
// @Failure 400 {object} error_handler.ErrorResponse "Invalid filter parameters"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /v1/server [get]
|
||||
func (ac *ServerController) GetAll(c *fiber.Ctx) error {
|
||||
var filter model.ServerFilter
|
||||
if err := common.ParseQueryFilter(c, &filter); err != nil {
|
||||
@@ -66,6 +93,19 @@ func (ac *ServerController) GetAll(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// GetById returns a single server by its ID
|
||||
// @Summary Get server by ID
|
||||
// @Description Get detailed information about a specific ACC server
|
||||
// @Tags Server
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Server ID (UUID format)"
|
||||
// @Success 200 {object} model.Server "Server details"
|
||||
// @Failure 400 {object} error_handler.ErrorResponse "Invalid server ID format"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 404 {object} error_handler.ErrorResponse "Server not found"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /v1/server/{id} [get]
|
||||
func (ac *ServerController) GetById(c *fiber.Ctx) error {
|
||||
serverIDStr := c.Params("id")
|
||||
serverID, err := uuid.Parse(serverIDStr)
|
||||
@@ -81,6 +121,19 @@ func (ac *ServerController) GetById(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// CreateServer creates a new server
|
||||
// @Summary Create a new ACC server
|
||||
// @Description Create a new ACC server instance with the provided configuration
|
||||
// @Tags Server
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param server body model.Server true "Server configuration"
|
||||
// @Success 200 {object} object "Created server details"
|
||||
// @Failure 400 {object} error_handler.ErrorResponse "Invalid server data"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /v1/server [post]
|
||||
func (ac *ServerController) CreateServer(c *fiber.Ctx) error {
|
||||
server := new(model.Server)
|
||||
if err := c.BodyParser(server); err != nil {
|
||||
@@ -94,6 +147,21 @@ func (ac *ServerController) CreateServer(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// UpdateServer updates an existing server
|
||||
// @Summary Update an ACC server
|
||||
// @Description Update configuration for an existing ACC server
|
||||
// @Tags Server
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Server ID (UUID format)"
|
||||
// @Param server body model.Server true "Updated server configuration"
|
||||
// @Success 200 {object} object "Updated server details"
|
||||
// @Failure 400 {object} error_handler.ErrorResponse "Invalid server data or ID"
|
||||
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||
// @Failure 404 {object} error_handler.ErrorResponse "Server not found"
|
||||
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /v1/server/{id} [put]
|
||||
func (ac *ServerController) UpdateServer(c *fiber.Ctx) error {
|
||||
serverIDStr := c.Params("id")
|
||||
serverID, err := uuid.Parse(serverIDStr)
|
||||
|
||||
@@ -72,7 +72,7 @@ type State struct {
|
||||
}
|
||||
|
||||
type ServerState struct {
|
||||
sync.RWMutex
|
||||
sync.RWMutex `swaggerignore:"-" json:"-"`
|
||||
Session string `json:"session"`
|
||||
SessionStart time.Time `json:"sessionStart"`
|
||||
PlayerCount int `json:"playerCount"`
|
||||
|
||||
Reference in New Issue
Block a user