| | | 1 | | using Elsa.Authorization; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Labels.Contracts; |
| | | 4 | | using Elsa.Workflows; |
| | | 5 | | using FastEndpoints; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Labels.Endpoints.Labels.Post; |
| | | 9 | | |
| | | 10 | | [PublicAPI] |
| | | 11 | | internal class Create : ElsaEndpoint<Request, Response, LabelMapper> |
| | | 12 | | { |
| | | 13 | | private readonly ILabelStore _store; |
| | | 14 | | |
| | 0 | 15 | | public Create(ILabelStore store, IIdentityGenerator identityGenerator) |
| | | 16 | | { |
| | 0 | 17 | | _store = store; |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | public override void Configure() |
| | | 21 | | { |
| | 0 | 22 | | Post("/labels"); |
| | 0 | 23 | | RequirePermission(Elsa.Labels.Permissions.LabelPermissions.Labels, CoreVerbs.Create); |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 27 | | { |
| | 0 | 28 | | var label = Map.ToEntity(request); |
| | 0 | 29 | | await _store.SaveAsync(label, cancellationToken); |
| | 0 | 30 | | var response = Map.FromEntity(label); |
| | 0 | 31 | | await Send.CreatedAtAsync<Get.Get>(new { Id = label.Id }, response, cancellation: cancellationToken); |
| | 0 | 32 | | } |
| | | 33 | | } |