| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Alterations.Core.Contracts; |
| | | 3 | | using Elsa.Alterations.Core.Filters; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Alterations.Endpoints.Alterations.Get; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Gets an alteration plan and its associated jobs. |
| | | 10 | | /// </summary> |
| | | 11 | | [PublicAPI] |
| | | 12 | | public class Get : ElsaEndpointWithoutRequest<Response> |
| | | 13 | | { |
| | | 14 | | private readonly IAlterationPlanStore _alterationPlanStore; |
| | | 15 | | private readonly IAlterationJobStore _alterationJobStore; |
| | | 16 | | |
| | | 17 | | /// <inheritdoc /> |
| | 1 | 18 | | public Get(IAlterationPlanStore alterationPlanStore, IAlterationJobStore alterationJobStore) |
| | | 19 | | { |
| | 1 | 20 | | _alterationPlanStore = alterationPlanStore; |
| | 1 | 21 | | _alterationJobStore = alterationJobStore; |
| | 1 | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <inheritdoc /> |
| | | 25 | | public override void Configure() |
| | | 26 | | { |
| | 1 | 27 | | Get("/alterations/{id}"); |
| | 1 | 28 | | ConfigurePermissions("read:alterations"); |
| | 1 | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <inheritdoc /> |
| | | 32 | | public override async Task HandleAsync(CancellationToken cancellationToken) |
| | | 33 | | { |
| | 0 | 34 | | var planId = Route<string>("id"); |
| | | 35 | | |
| | | 36 | | // Load the plan. |
| | 0 | 37 | | var plan = await _alterationPlanStore.FindAsync(new AlterationPlanFilter { Id = planId }, cancellationToken); |
| | | 38 | | |
| | 0 | 39 | | if (plan == null) |
| | | 40 | | { |
| | 0 | 41 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 42 | | return; |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | // Load the jobs. |
| | 0 | 46 | | var jobs = (await _alterationJobStore.FindManyAsync(new AlterationJobFilter { PlanId = planId }, cancellationTok |
| | | 47 | | |
| | | 48 | | // Write response. |
| | 0 | 49 | | var response = new Response(plan, jobs); |
| | 0 | 50 | | await Send.OkAsync(response, cancellationToken); |
| | 0 | 51 | | } |
| | | 52 | | } |