fix: Set IdempotencyKey before validation in CreateWithIdempotency
This commit is contained in:
@@ -57,11 +57,21 @@ func (f *Factory) CreateWithIdempotency(agentID uuid.UUID, commandType string, p
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// If no existing command found, proceed with creation
|
// If no existing command found, proceed with creation
|
||||||
if err.Error() == "sql: no rows in result set" || err.Error() == "command not found" {
|
if err.Error() == "sql: no rows in result set" || err.Error() == "command not found" {
|
||||||
cmd, createErr := f.Create(agentID, commandType, params)
|
cmd := &models.AgentCommand{
|
||||||
if createErr != nil {
|
ID: uuid.New(),
|
||||||
return nil, createErr
|
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 cmd, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("failed to check idempotency: %w", err)
|
return nil, fmt.Errorf("failed to check idempotency: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user