diff --git a/aggregator-server/internal/command/factory.go b/aggregator-server/internal/command/factory.go index 13b1b3a..1734403 100644 --- a/aggregator-server/internal/command/factory.go +++ b/aggregator-server/internal/command/factory.go @@ -57,11 +57,21 @@ func (f *Factory) CreateWithIdempotency(agentID uuid.UUID, commandType string, p if err != nil { // If no existing command found, proceed with creation if err.Error() == "sql: no rows in result set" || err.Error() == "command not found" { - cmd, createErr := f.Create(agentID, commandType, params) - if createErr != nil { - return nil, createErr + cmd := &models.AgentCommand{ + ID: uuid.New(), + AgentID: agentID, + CommandType: commandType, + Status: "pending", + Source: determineSource(commandType), + IdempotencyKey: &idempotencyKey, + Params: params, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + } + + if err := f.validator.Validate(cmd); err != nil { + return nil, fmt.Errorf("command validation failed: %w", err) } - cmd.IdempotencyKey = &idempotencyKey return cmd, nil } return nil, fmt.Errorf("failed to check idempotency: %w", err)