Fixed IsNameUnique for InMemory WorkflowDefinition store (#4370)
This commit is contained in:
parent
e2c3ab0efd
commit
2c014a9524
|
|
@ -154,13 +154,15 @@ public class DapperWorkflowDefinitionStore : IWorkflowDefinitionStore
|
|||
/// <inheritdoc />
|
||||
public async Task<bool> GetIsNameUnique(string name, string? definitionId = default, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _store.AnyAsync(query =>
|
||||
var exists = await _store.AnyAsync(query =>
|
||||
{
|
||||
query.Is(nameof(WorkflowDefinition.Name), name);
|
||||
|
||||
if (definitionId != null)
|
||||
query.IsNot(nameof(WorkflowDefinition.DefinitionId), definitionId);
|
||||
}, cancellationToken);
|
||||
|
||||
return !exists;
|
||||
}
|
||||
|
||||
private void ApplyFilter(ParameterizedQuery query, WorkflowDefinitionFilter filter)
|
||||
|
|
|
|||
|
|
@ -146,7 +146,8 @@ public class EFCoreWorkflowDefinitionStore : IWorkflowDefinitionStore
|
|||
/// <inheritdoc />
|
||||
public async Task<bool> GetIsNameUnique(string name, string? definitionId = default, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _store.AnyAsync(x => x.Name == name && x.DefinitionId != definitionId, cancellationToken);
|
||||
var exists = await _store.AnyAsync(x => x.Name == name && x.DefinitionId != definitionId, cancellationToken);
|
||||
return !exists;
|
||||
}
|
||||
|
||||
private ValueTask OnSaveAsync(ManagementElsaDbContext managementElsaDbContext, WorkflowDefinition entity, CancellationToken cancellationToken)
|
||||
|
|
|
|||
|
|
@ -132,7 +132,8 @@ public class MongoWorkflowDefinitionStore : IWorkflowDefinitionStore
|
|||
/// <inheritdoc />
|
||||
public async Task<bool> GetIsNameUnique(string name, string? definitionId = default, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _mongoDbStore.AnyAsync(x => x.Name == name && x.DefinitionId != definitionId, cancellationToken);
|
||||
var exists = await _mongoDbStore.AnyAsync(x => x.Name == name && x.DefinitionId != definitionId, cancellationToken);
|
||||
return !exists;
|
||||
}
|
||||
|
||||
private IMongoQueryable<WorkflowDefinition> Filter(IMongoQueryable<WorkflowDefinition> queryable, WorkflowDefinitionFilter filter) =>
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ internal class IsNameUnique : ElsaEndpoint<Request>
|
|||
|
||||
public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
|
||||
{
|
||||
var exists = await _store.GetIsNameUnique(request.Name.Trim(), request.DefinitionId, cancellationToken);
|
||||
var response = new Response(!exists);
|
||||
var isUnique = await _store.GetIsNameUnique(request.Name.Trim(), request.DefinitionId, cancellationToken);
|
||||
var response = new Response(isUnique);
|
||||
|
||||
await SendOkAsync(response, cancellationToken);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue