parent
2bd39a5ff1
commit
b77e93a4a9
|
|
@ -5,10 +5,7 @@ namespace Elsa.Samples.SendHttp
|
|||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
public static void Main(string[] args) => CreateHostBuilder(args).Build().Run();
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
|
|
|
|||
|
|
@ -1,63 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using Elsa.Models;
|
||||
using Elsa.Persistence;
|
||||
using Elsa.Persistence.Specifications;
|
||||
using Elsa.Persistence.Specifications.WorkflowDefinitions;
|
||||
using Elsa.Serialization;
|
||||
using Elsa.Server.Api.Attributes;
|
||||
using Elsa.Server.Api.Models;
|
||||
using Elsa.Server.Api.Swagger.Examples;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using Swashbuckle.AspNetCore.Filters;
|
||||
|
||||
namespace Elsa.Server.Api.Endpoints.WorkflowDefinitions
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1")]
|
||||
[Route("v{apiVersion:apiVersion}/workflow-definitions")]
|
||||
[Produces("application/json")]
|
||||
public class GetMany : Controller
|
||||
{
|
||||
private readonly IWorkflowDefinitionStore _workflowDefinitionStore;
|
||||
private readonly IContentSerializer _serializer;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GetMany(IWorkflowDefinitionStore workflowDefinitionStore, IContentSerializer serializer, IMapper mapper)
|
||||
{
|
||||
_workflowDefinitionStore = workflowDefinitionStore;
|
||||
_serializer = serializer;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ListModel<WorkflowDefinitionSummaryModel>))]
|
||||
[SwaggerResponseExample(StatusCodes.Status200OK, typeof(WorkflowDefinitionPagedListExample))]
|
||||
[SwaggerOperation(
|
||||
Summary = "Returns a list of workflow definitions for the specified ids.",
|
||||
Description = "Returns a list of workflow definition summaries. When no version options are specified, the latest versions are returned.",
|
||||
OperationId = "WorkflowDefinitions.GetMany",
|
||||
Tags = new[] { "WorkflowDefinitions" })
|
||||
]
|
||||
public async Task<ActionResult<WorkflowDefinitionSummaryModel[]>> Handle([RequiredFromQuery] string? ids, VersionOptions? version = default, CancellationToken cancellationToken = default)
|
||||
{
|
||||
IList<WorkflowDefinitionSummaryModel> summaries = new List<WorkflowDefinitionSummaryModel>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(ids))
|
||||
{
|
||||
version ??= VersionOptions.Latest;
|
||||
var splitIds = ids.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
var specification = new ManyWorkflowDefinitionIdsSpecification(splitIds, version.Value);
|
||||
var items = await _workflowDefinitionStore.FindManyAsync(specification, cancellationToken: cancellationToken);
|
||||
summaries = _mapper.Map<IList<WorkflowDefinitionSummaryModel>>(items);
|
||||
}
|
||||
|
||||
return Json(new ListModel<WorkflowDefinitionSummaryModel>(summaries), _serializer.GetSettings());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -7,6 +8,7 @@ using Elsa.Persistence;
|
|||
using Elsa.Persistence.Specifications;
|
||||
using Elsa.Persistence.Specifications.WorkflowDefinitions;
|
||||
using Elsa.Serialization;
|
||||
using Elsa.Server.Api.Attributes;
|
||||
using Elsa.Server.Api.Models;
|
||||
using Elsa.Server.Api.Swagger.Examples;
|
||||
using Elsa.Services;
|
||||
|
|
@ -45,11 +47,16 @@ namespace Elsa.Server.Api.Endpoints.WorkflowDefinitions
|
|||
OperationId = "WorkflowDefinitions.List",
|
||||
Tags = new[] { "WorkflowDefinitions" })
|
||||
]
|
||||
public async Task<ActionResult<PagedList<WorkflowDefinitionSummaryModel>>> Handle(int? page = default, int? pageSize = default, VersionOptions? version = default, CancellationToken cancellationToken = default)
|
||||
public async Task<ActionResult<PagedList<WorkflowDefinitionSummaryModel>>> Handle(
|
||||
[FromQuery] string? ids,
|
||||
int? page = default,
|
||||
int? pageSize = default,
|
||||
VersionOptions? version = default,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken);
|
||||
version ??= VersionOptions.Latest;
|
||||
var specification = new VersionOptionsSpecification(version.Value).And(new TenantSpecification<WorkflowDefinition>(tenantId));
|
||||
var specification = GetSpecification(ids, version.Value).And(new TenantSpecification<WorkflowDefinition>(tenantId));
|
||||
var totalCount = await _workflowDefinitionStore.CountAsync(specification, cancellationToken);
|
||||
var paging = page == null || pageSize == null ? default : Paging.Page(page.Value, pageSize.Value);
|
||||
var items = await _workflowDefinitionStore.FindManyAsync(specification, paging: paging, cancellationToken: cancellationToken);
|
||||
|
|
@ -58,5 +65,14 @@ namespace Elsa.Server.Api.Endpoints.WorkflowDefinitions
|
|||
|
||||
return Json(pagedList, _serializer.GetSettings());
|
||||
}
|
||||
|
||||
private Specification<WorkflowDefinition> GetSpecification(string? ids, VersionOptions version)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ids))
|
||||
return new VersionOptionsSpecification(version);
|
||||
|
||||
var splitIds = ids.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
return new ManyWorkflowDefinitionIdsSpecification(splitIds, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -77,8 +77,6 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
Type = PrimitiveType.String.ToString().ToLower(),
|
||||
Example = new OpenApiString("System.String, mscorlib")
|
||||
});
|
||||
|
||||
c.ResolveConflictingActions(d => d.First());
|
||||
|
||||
configure?.Invoke(c);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue