alter primary keys to uuids and adjust the membership system
This commit is contained in:
@@ -25,9 +25,9 @@ func NewApiService(repository *repository.ApiRepository,
|
||||
repository: repository,
|
||||
serverRepository: serverRepository,
|
||||
statusCache: model.NewServerStatusCache(model.CacheConfig{
|
||||
ExpirationTime: 30 * time.Second, // Cache expires after 30 seconds
|
||||
ThrottleTime: 5 * time.Second, // Minimum 5 seconds between checks
|
||||
DefaultStatus: model.StatusRunning, // Default to running if throttled
|
||||
ExpirationTime: 30 * time.Second, // Cache expires after 30 seconds
|
||||
ThrottleTime: 5 * time.Second, // Minimum 5 seconds between checks
|
||||
DefaultStatus: model.StatusRunning, // Default to running if throttled
|
||||
}),
|
||||
windowsService: NewWindowsService(systemConfigService),
|
||||
}
|
||||
@@ -65,15 +65,15 @@ func (as *ApiService) ApiStartServer(ctx *fiber.Ctx) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
// Update status cache for this service before starting
|
||||
as.statusCache.UpdateStatus(serviceName, model.StatusStarting)
|
||||
|
||||
|
||||
statusStr, err := as.StartServer(serviceName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
// Parse and update cache with new status
|
||||
status := model.ParseServiceStatus(statusStr)
|
||||
as.statusCache.UpdateStatus(serviceName, status)
|
||||
@@ -85,15 +85,15 @@ func (as *ApiService) ApiStopServer(ctx *fiber.Ctx) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
// Update status cache for this service before stopping
|
||||
as.statusCache.UpdateStatus(serviceName, model.StatusStopping)
|
||||
|
||||
|
||||
statusStr, err := as.StopServer(serviceName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
// Parse and update cache with new status
|
||||
status := model.ParseServiceStatus(statusStr)
|
||||
as.statusCache.UpdateStatus(serviceName, status)
|
||||
@@ -105,15 +105,15 @@ func (as *ApiService) ApiRestartServer(ctx *fiber.Ctx) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
// Update status cache for this service before restarting
|
||||
as.statusCache.UpdateStatus(serviceName, model.StatusRestarting)
|
||||
|
||||
|
||||
statusStr, err := as.RestartServer(serviceName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
// Parse and update cache with new status
|
||||
status := model.ParseServiceStatus(statusStr)
|
||||
as.statusCache.UpdateStatus(serviceName, status)
|
||||
@@ -172,8 +172,8 @@ func (as *ApiService) GetServiceName(ctx *fiber.Ctx) (string, error) {
|
||||
var err error
|
||||
serviceName, ok := ctx.Locals("service").(string)
|
||||
if !ok || serviceName == "" {
|
||||
serverId, ok2 := ctx.Locals("serverId").(int)
|
||||
if !ok2 || serverId == 0 {
|
||||
serverId, ok2 := ctx.Locals("serverId").(string)
|
||||
if !ok2 || serverId == "" {
|
||||
return "", errors.New("service name missing")
|
||||
}
|
||||
server, err = as.serverRepository.GetByID(ctx.UserContext(), serverId)
|
||||
|
||||
@@ -13,14 +13,15 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
"github.com/qjebbs/go-jsons"
|
||||
"golang.org/x/text/encoding/unicode"
|
||||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
const (
|
||||
ConfigurationJson = "configuration.json"
|
||||
AssistRulesJson = "assistRules.json"
|
||||
@@ -75,9 +76,9 @@ func NewConfigService(repository *repository.ConfigRepository, serverRepository
|
||||
return &ConfigService{
|
||||
repository: repository,
|
||||
serverRepository: serverRepository,
|
||||
configCache: model.NewServerConfigCache(model.CacheConfig{
|
||||
ExpirationTime: 5 * time.Minute, // Cache configs for 5 minutes
|
||||
ThrottleTime: 1 * time.Second, // Prevent rapid re-reads
|
||||
configCache: model.NewServerConfigCache(model.CacheConfig{
|
||||
ExpirationTime: 5 * time.Minute, // Cache configs for 5 minutes
|
||||
ThrottleTime: 1 * time.Second, // Prevent rapid re-reads
|
||||
DefaultStatus: model.StatusUnknown,
|
||||
}),
|
||||
}
|
||||
@@ -95,7 +96,7 @@ func (as *ConfigService) SetServerService(serverService *ServerService) {
|
||||
// Returns:
|
||||
// string: Application version
|
||||
func (as *ConfigService) UpdateConfig(ctx *fiber.Ctx, body *map[string]interface{}) (*model.Config, error) {
|
||||
serverID := ctx.Locals("serverId").(int)
|
||||
serverID := ctx.Locals("serverId").(string)
|
||||
configFile := ctx.Params("file")
|
||||
override := ctx.QueryBool("override", false)
|
||||
|
||||
@@ -103,8 +104,14 @@ func (as *ConfigService) UpdateConfig(ctx *fiber.Ctx, body *map[string]interface
|
||||
}
|
||||
|
||||
// updateConfigInternal handles the actual config update logic without Fiber dependencies
|
||||
func (as *ConfigService) updateConfigInternal(ctx context.Context, serverID int, configFile string, body *map[string]interface{}, override bool) (*model.Config, error) {
|
||||
server, err := as.serverRepository.GetByID(ctx, serverID)
|
||||
func (as *ConfigService) updateConfigInternal(ctx context.Context, serverID string, configFile string, body *map[string]interface{}, override bool) (*model.Config, error) {
|
||||
serverUUID, err := uuid.Parse(serverID)
|
||||
if err != nil {
|
||||
logging.Error("Invalid server ID format: %v", err)
|
||||
return nil, fmt.Errorf("invalid server ID format")
|
||||
}
|
||||
|
||||
server, err := as.serverRepository.GetByID(ctx, serverUUID)
|
||||
if err != nil {
|
||||
logging.Error("Server not found")
|
||||
return nil, fmt.Errorf("server not found")
|
||||
@@ -162,13 +169,13 @@ func (as *ConfigService) updateConfigInternal(ctx context.Context, serverID int,
|
||||
}
|
||||
|
||||
// Invalidate all configs for this server since configs can be interdependent
|
||||
as.configCache.InvalidateServerCache(strconv.Itoa(serverID))
|
||||
as.configCache.InvalidateServerCache(serverID)
|
||||
|
||||
as.serverService.StartAccServerRuntime(server)
|
||||
|
||||
// Log change
|
||||
return as.repository.UpdateConfig(ctx, &model.Config{
|
||||
ServerID: uint(serverID),
|
||||
ServerID: serverUUID,
|
||||
ConfigFile: configFile,
|
||||
OldConfig: string(oldDataUTF8),
|
||||
NewConfig: string(newData),
|
||||
@@ -184,13 +191,12 @@ func (as *ConfigService) updateConfigInternal(ctx context.Context, serverID int,
|
||||
// Returns:
|
||||
// string: Application version
|
||||
func (as *ConfigService) GetConfig(ctx *fiber.Ctx) (interface{}, error) {
|
||||
serverID, _ := ctx.ParamsInt("id")
|
||||
serverIDStr := ctx.Params("id")
|
||||
configFile := ctx.Params("file")
|
||||
serverIDStr := strconv.Itoa(serverID)
|
||||
|
||||
logging.Debug("Getting config for server ID: %d, file: %s", serverID, configFile)
|
||||
logging.Debug("Getting config for server ID: %s, file: %s", serverIDStr, configFile)
|
||||
|
||||
server, err := as.serverRepository.GetByID(ctx.UserContext(), serverID)
|
||||
server, err := as.serverRepository.GetByID(ctx.UserContext(), serverIDStr)
|
||||
if err != nil {
|
||||
logging.Error("Server not found")
|
||||
return nil, fiber.NewError(404, "Server not found")
|
||||
@@ -276,7 +282,7 @@ func (as *ConfigService) GetConfig(ctx *fiber.Ctx) (interface{}, error) {
|
||||
// GetConfigs
|
||||
// Gets all configurations for a server, using cache when possible.
|
||||
func (as *ConfigService) GetConfigs(ctx *fiber.Ctx) (*model.Configurations, error) {
|
||||
serverID, _ := ctx.ParamsInt("id")
|
||||
serverID := ctx.Params("id")
|
||||
|
||||
server, err := as.serverRepository.GetByID(ctx.UserContext(), serverID)
|
||||
if err != nil {
|
||||
@@ -288,7 +294,7 @@ func (as *ConfigService) GetConfigs(ctx *fiber.Ctx) (*model.Configurations, erro
|
||||
}
|
||||
|
||||
func (as *ConfigService) LoadConfigs(server *model.Server) (*model.Configurations, error) {
|
||||
serverIDStr := strconv.Itoa(int(server.ID))
|
||||
serverIDStr := server.ID.String()
|
||||
logging.Info("Loading configs for server ID: %s at path: %s", serverIDStr, server.GetConfigPath())
|
||||
configs := &model.Configurations{}
|
||||
|
||||
@@ -442,11 +448,11 @@ func transformBytes(t transform.Transformer, input []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
func (as *ConfigService) GetEventConfig(server *model.Server) (*model.EventConfig, error) {
|
||||
serverIDStr := strconv.Itoa(int(server.ID))
|
||||
serverIDStr := server.ID.String()
|
||||
if cached, ok := as.configCache.GetEvent(serverIDStr); ok {
|
||||
return cached, nil
|
||||
}
|
||||
|
||||
|
||||
event, err := mustDecode[model.EventConfig](EventJson, server.GetConfigPath())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -456,11 +462,11 @@ func (as *ConfigService) GetEventConfig(server *model.Server) (*model.EventConfi
|
||||
}
|
||||
|
||||
func (as *ConfigService) GetConfiguration(server *model.Server) (*model.Configuration, error) {
|
||||
serverIDStr := strconv.Itoa(int(server.ID))
|
||||
serverIDStr := server.ID.String()
|
||||
if cached, ok := as.configCache.GetConfiguration(serverIDStr); ok {
|
||||
return cached, nil
|
||||
}
|
||||
|
||||
|
||||
config, err := mustDecode[model.Configuration](ConfigurationJson, server.GetConfigPath())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -482,6 +488,6 @@ func (as *ConfigService) SaveConfiguration(server *model.Server, config *model.C
|
||||
}
|
||||
|
||||
// Update the configuration using the internal method
|
||||
_, err = as.updateConfigInternal(context.Background(), int(server.ID), ConfigurationJson, &configMap, true)
|
||||
_, err = as.updateConfigInternal(context.Background(), server.ID.String(), ConfigurationJson, &configMap, true)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ type MembershipService struct {
|
||||
|
||||
// NewMembershipService creates a new MembershipService.
|
||||
func NewMembershipService(repo *repository.MembershipRepository) *MembershipService {
|
||||
return &MembershipService{repo: repo}
|
||||
return &MembershipService{
|
||||
repo: repo,
|
||||
}
|
||||
}
|
||||
|
||||
// Login authenticates a user and returns a JWT.
|
||||
@@ -56,8 +58,8 @@ func (s *MembershipService) CreateUser(ctx context.Context, username, password,
|
||||
logging.Error("Failed to create user: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
logging.Debug("User created successfully")
|
||||
|
||||
logging.InfoOperation("USER_CREATE", "Created user: "+user.Username+" (ID: "+user.ID.String()+", Role: "+roleName+")")
|
||||
return user, nil
|
||||
}
|
||||
|
||||
@@ -83,6 +85,34 @@ type UpdateUserRequest struct {
|
||||
RoleID *uuid.UUID `json:"roleId"`
|
||||
}
|
||||
|
||||
// DeleteUser deletes a user with validation to prevent Super Admin deletion.
|
||||
func (s *MembershipService) DeleteUser(ctx context.Context, userID uuid.UUID) error {
|
||||
// Get user with role information
|
||||
user, err := s.repo.FindUserByID(ctx, userID)
|
||||
if err != nil {
|
||||
return errors.New("user not found")
|
||||
}
|
||||
|
||||
// Get role to check if it's Super Admin
|
||||
role, err := s.repo.FindRoleByID(ctx, user.RoleID)
|
||||
if err != nil {
|
||||
return errors.New("user role not found")
|
||||
}
|
||||
|
||||
// Prevent deletion of Super Admin users
|
||||
if role.Name == "Super Admin" {
|
||||
return errors.New("cannot delete Super Admin user")
|
||||
}
|
||||
|
||||
err = s.repo.DeleteUser(ctx, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logging.InfoOperation("USER_DELETE", "Deleted user: "+userID.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateUser updates a user's details.
|
||||
func (s *MembershipService) UpdateUser(ctx context.Context, userID uuid.UUID, req UpdateUserRequest) (*model.User, error) {
|
||||
user, err := s.repo.FindUserByID(ctx, userID)
|
||||
@@ -112,6 +142,7 @@ func (s *MembershipService) UpdateUser(ctx context.Context, userID uuid.UUID, re
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logging.InfoOperation("USER_UPDATE", "Updated user: "+user.Username+" (ID: "+user.ID.String()+")")
|
||||
return user, nil
|
||||
}
|
||||
|
||||
@@ -122,8 +153,8 @@ func (s *MembershipService) HasPermission(ctx context.Context, userID string, pe
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Super admin has all permissions
|
||||
if user.Role.Name == "Super Admin" {
|
||||
// Super admin and Admin have all permissions
|
||||
if user.Role.Name == "Super Admin" || user.Role.Name == "Admin" {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -165,6 +196,51 @@ func (s *MembershipService) SetupInitialData(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create Admin role with same permissions as Super Admin
|
||||
adminRole, err := s.repo.FindRoleByName(ctx, "Admin")
|
||||
if err != nil {
|
||||
adminRole = &model.Role{Name: "Admin"}
|
||||
if err := s.repo.CreateRole(ctx, adminRole); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := s.repo.AssignPermissionsToRole(ctx, adminRole, createdPermissions); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create Manager role with limited permissions (excluding membership, role, user, server create/delete)
|
||||
managerRole, err := s.repo.FindRoleByName(ctx, "Manager")
|
||||
if err != nil {
|
||||
managerRole = &model.Role{Name: "Manager"}
|
||||
if err := s.repo.CreateRole(ctx, managerRole); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Define manager permissions (limited set)
|
||||
managerPermissionNames := []string{
|
||||
model.ServerView,
|
||||
model.ServerUpdate,
|
||||
model.ServerStart,
|
||||
model.ServerStop,
|
||||
model.ConfigView,
|
||||
model.ConfigUpdate,
|
||||
}
|
||||
|
||||
managerPermissions := make([]model.Permission, 0)
|
||||
for _, permName := range managerPermissionNames {
|
||||
for _, perm := range createdPermissions {
|
||||
if perm.Name == permName {
|
||||
managerPermissions = append(managerPermissions, perm)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.repo.AssignPermissionsToRole(ctx, managerRole, managerPermissions); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create a default admin user if one doesn't exist
|
||||
_, err = s.repo.FindUserByUsername(ctx, "admin")
|
||||
if err != nil {
|
||||
@@ -177,3 +253,8 @@ func (s *MembershipService) SetupInitialData(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAllRoles retrieves all roles for dropdown selection.
|
||||
func (s *MembershipService) GetAllRoles(ctx context.Context) ([]*model.Role, error) {
|
||||
return s.repo.ListRoles(ctx)
|
||||
}
|
||||
|
||||
@@ -8,34 +8,34 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"acc-server-manager/local/utl/network"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultStartPort = 9600
|
||||
DefaultStartPort = 9600
|
||||
RequiredPortCount = 1 // Update this if ACC needs more ports
|
||||
)
|
||||
|
||||
type ServerService struct {
|
||||
repository *repository.ServerRepository
|
||||
stateHistoryRepo *repository.StateHistoryRepository
|
||||
apiService *ApiService
|
||||
configService *ConfigService
|
||||
steamService *SteamService
|
||||
windowsService *WindowsService
|
||||
firewallService *FirewallService
|
||||
repository *repository.ServerRepository
|
||||
stateHistoryRepo *repository.StateHistoryRepository
|
||||
apiService *ApiService
|
||||
configService *ConfigService
|
||||
steamService *SteamService
|
||||
windowsService *WindowsService
|
||||
firewallService *FirewallService
|
||||
systemConfigService *SystemConfigService
|
||||
instances sync.Map // Track instances per server
|
||||
lastInsertTimes sync.Map // Track last insert time per server
|
||||
debouncers sync.Map // Track debounce timers per server
|
||||
logTailers sync.Map // Track log tailers per server
|
||||
sessionIDs sync.Map // Track current session ID per server
|
||||
instances sync.Map // Track instances per server
|
||||
lastInsertTimes sync.Map // Track last insert time per server
|
||||
debouncers sync.Map // Track debounce timers per server
|
||||
logTailers sync.Map // Track log tailers per server
|
||||
sessionIDs sync.Map // Track current session ID per server
|
||||
}
|
||||
|
||||
type pendingState struct {
|
||||
@@ -54,7 +54,7 @@ func (s *ServerService) ensureLogTailing(server *model.Server, instance *trackin
|
||||
logPath := filepath.Join(server.GetLogPath(), "server.log")
|
||||
tailer := tracking.NewLogTailer(logPath, instance.HandleLogLine)
|
||||
s.logTailers.Store(server.ID, tailer)
|
||||
|
||||
|
||||
// Start tailing and automatically handle file changes
|
||||
tailer.Start()
|
||||
}()
|
||||
@@ -71,13 +71,13 @@ func NewServerService(
|
||||
systemConfigService *SystemConfigService,
|
||||
) *ServerService {
|
||||
service := &ServerService{
|
||||
repository: repository,
|
||||
stateHistoryRepo: stateHistoryRepo,
|
||||
apiService: apiService,
|
||||
configService: configService,
|
||||
steamService: steamService,
|
||||
windowsService: windowsService,
|
||||
firewallService: firewallService,
|
||||
repository: repository,
|
||||
stateHistoryRepo: stateHistoryRepo,
|
||||
apiService: apiService,
|
||||
configService: configService,
|
||||
steamService: steamService,
|
||||
windowsService: windowsService,
|
||||
firewallService: firewallService,
|
||||
systemConfigService: systemConfigService,
|
||||
}
|
||||
|
||||
@@ -97,39 +97,42 @@ func NewServerService(
|
||||
return service
|
||||
}
|
||||
|
||||
func (s *ServerService) shouldInsertStateHistory(serverID uint) bool {
|
||||
func (s *ServerService) shouldInsertStateHistory(serverID uuid.UUID) bool {
|
||||
insertInterval := 5 * time.Minute // Configure this as needed
|
||||
|
||||
|
||||
lastInsertInterface, exists := s.lastInsertTimes.Load(serverID)
|
||||
if !exists {
|
||||
s.lastInsertTimes.Store(serverID, time.Now().UTC())
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
lastInsert := lastInsertInterface.(time.Time)
|
||||
now := time.Now().UTC()
|
||||
|
||||
|
||||
if now.Sub(lastInsert) >= insertInterval {
|
||||
s.lastInsertTimes.Store(serverID, now)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *ServerService) getNextSessionID(serverID uint) uint {
|
||||
func (s *ServerService) getNextSessionID(serverID uuid.UUID) uuid.UUID {
|
||||
lastID, err := s.stateHistoryRepo.GetLastSessionID(context.Background(), serverID)
|
||||
if err != nil {
|
||||
logging.Error("Failed to get last session ID for server %d: %v", serverID, err)
|
||||
return 1 // Return 1 as fallback
|
||||
logging.Error("Failed to get last session ID for server %s: %v", serverID, err)
|
||||
return uuid.New() // Return new UUID as fallback
|
||||
}
|
||||
return lastID + 1
|
||||
if lastID == uuid.Nil {
|
||||
return uuid.New() // Return new UUID if no previous session
|
||||
}
|
||||
return uuid.New() // Always generate new UUID for each session
|
||||
}
|
||||
|
||||
func (s *ServerService) insertStateHistory(serverID uint, state *model.ServerState) {
|
||||
func (s *ServerService) insertStateHistory(serverID uuid.UUID, state *model.ServerState) {
|
||||
// Get or create session ID when session changes
|
||||
currentSessionInterface, exists := s.instances.Load(serverID)
|
||||
var sessionID uint
|
||||
var sessionID uuid.UUID
|
||||
if !exists {
|
||||
sessionID = s.getNextSessionID(serverID)
|
||||
} else {
|
||||
@@ -141,20 +144,20 @@ func (s *ServerService) insertStateHistory(serverID uint, state *model.ServerSta
|
||||
if !exists {
|
||||
sessionID = s.getNextSessionID(serverID)
|
||||
} else {
|
||||
sessionID = sessionIDInterface.(uint)
|
||||
sessionID = sessionIDInterface.(uuid.UUID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s.stateHistoryRepo.Insert(context.Background(), &model.StateHistory{
|
||||
ServerID: serverID,
|
||||
Session: state.Session,
|
||||
Track: state.Track,
|
||||
PlayerCount: state.PlayerCount,
|
||||
DateCreated: time.Now().UTC(),
|
||||
SessionStart: state.SessionStart,
|
||||
ServerID: serverID,
|
||||
Session: state.Session,
|
||||
Track: state.Track,
|
||||
PlayerCount: state.PlayerCount,
|
||||
DateCreated: time.Now().UTC(),
|
||||
SessionStart: state.SessionStart,
|
||||
SessionDurationMinutes: state.SessionDurationMinutes,
|
||||
SessionID: sessionID,
|
||||
SessionID: sessionID,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -210,7 +213,6 @@ func (s *ServerService) GenerateServerPath(server *model.Server) {
|
||||
server.Path = server.GenerateServerPath(steamCMDPath)
|
||||
}
|
||||
|
||||
|
||||
func (s *ServerService) handleStateChange(server *model.Server, state *model.ServerState) {
|
||||
// Update session duration when session changes
|
||||
s.updateSessionDuration(server, state.Session)
|
||||
@@ -258,7 +260,7 @@ func (s *ServerService) StartAccServerRuntime(server *model.Server) {
|
||||
}
|
||||
|
||||
// Invalidate config cache for this server before loading new configs
|
||||
serverIDStr := strconv.FormatUint(uint64(server.ID), 10)
|
||||
serverIDStr := server.ID.String()
|
||||
s.configService.configCache.InvalidateServerCache(serverIDStr)
|
||||
|
||||
s.updateSessionDuration(server, instance.State.Session)
|
||||
@@ -309,7 +311,7 @@ func (s *ServerService) GetAll(ctx *fiber.Ctx, filter *model.ServerFilter) (*[]m
|
||||
// context.Context: Application context
|
||||
// Returns:
|
||||
// string: Application version
|
||||
func (as *ServerService) GetById(ctx *fiber.Ctx, serverID int) (*model.Server, error) {
|
||||
func (as *ServerService) GetById(ctx *fiber.Ctx, serverID uuid.UUID) (*model.Server, error) {
|
||||
server, err := as.repository.GetByID(ctx.UserContext(), serverID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -321,10 +323,10 @@ func (as *ServerService) GetById(ctx *fiber.Ctx, serverID int) (*model.Server, e
|
||||
server.Status = model.ParseServiceStatus(status)
|
||||
instance, ok := as.instances.Load(server.ID)
|
||||
if !ok {
|
||||
logging.Error("Unable to retrieve instance for server of ID: %d", server.ID)
|
||||
logging.Error("Unable to retrieve instance for server of ID: %s", server.ID)
|
||||
} else {
|
||||
serverInstance := instance.(*tracking.AccServerInstance)
|
||||
if (serverInstance.State != nil) {
|
||||
if serverInstance.State != nil {
|
||||
server.State = serverInstance.State
|
||||
}
|
||||
}
|
||||
@@ -389,7 +391,7 @@ func (s *ServerService) CreateServer(ctx *fiber.Ctx, server *model.Server) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ServerService) DeleteServer(ctx *fiber.Ctx, serverID int) error {
|
||||
func (s *ServerService) DeleteServer(ctx *fiber.Ctx, serverID uuid.UUID) error {
|
||||
// Get server details
|
||||
server, err := s.repository.GetByID(ctx.UserContext(), serverID)
|
||||
if err != nil {
|
||||
@@ -401,7 +403,6 @@ func (s *ServerService) DeleteServer(ctx *fiber.Ctx, serverID int) error {
|
||||
logging.Error("Failed to delete Windows service: %v", err)
|
||||
}
|
||||
|
||||
|
||||
// Remove firewall rules
|
||||
configuration, err := s.configService.GetConfiguration(server)
|
||||
if err != nil {
|
||||
@@ -443,7 +444,7 @@ func (s *ServerService) UpdateServer(ctx *fiber.Ctx, server *model.Server) error
|
||||
}
|
||||
|
||||
// Get existing server details
|
||||
existingServer, err := s.repository.GetByID(ctx.UserContext(), int(server.ID))
|
||||
existingServer, err := s.repository.GetByID(ctx.UserContext(), server.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get existing server details: %v", err)
|
||||
}
|
||||
@@ -529,4 +530,4 @@ func (s *ServerService) updateServerPort(server *model.Server, port int) error {
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ func InitializeServices(c *dig.Container) {
|
||||
api.SetServerService(server)
|
||||
config.SetServerService(server)
|
||||
|
||||
|
||||
})
|
||||
if err != nil {
|
||||
logging.Panic("unable to initialize services: " + err.Error())
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
@@ -35,7 +36,7 @@ func (s *StateHistoryService) Insert(ctx *fiber.Ctx, model *model.StateHistory)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StateHistoryService) GetLastSessionID(ctx *fiber.Ctx, serverID uint) (uint, error) {
|
||||
func (s *StateHistoryService) GetLastSessionID(ctx *fiber.Ctx, serverID uuid.UUID) (uuid.UUID, error) {
|
||||
return s.repository.GetLastSessionID(ctx.UserContext(), serverID)
|
||||
}
|
||||
|
||||
@@ -130,4 +131,4 @@ func (s *StateHistoryService) GetStatistics(ctx *fiber.Ctx, filter *model.StateH
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user