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