| | | 1 | | using Microsoft.AspNetCore.Mvc; |
| | | 2 | | using pva.SuperV.Model; |
| | | 3 | | using pva.SuperV.Model.FieldDefinitions; |
| | | 4 | | using pva.SuperV.Model.Instances; |
| | | 5 | | using pva.SuperV.Model.Services; |
| | | 6 | | using System.ComponentModel; |
| | | 7 | | |
| | | 8 | | namespace pva.SuperV.Api.Routes.Instances |
| | | 9 | | { |
| | | 10 | | public static class InstancesEndpoints |
| | | 11 | | { |
| | | 12 | | public static WebApplication MapInstancesEndpoints(this WebApplication app) |
| | 131 | 13 | | { |
| | 131 | 14 | | RouteGroupBuilder instancesApi = app.MapGroup("/instances"); |
| | 131 | 15 | | instancesApi.MapGet("/{runnableProjectId}", |
| | 131 | 16 | | (IInstanceService instanceService, |
| | 131 | 17 | | [Description("ID of runnable project")] string runnableProjectId) |
| | 2 | 18 | | => GetInstances.Handle(instanceService, runnableProjectId)) |
| | 131 | 19 | | .WithName("GetInstances") |
| | 131 | 20 | | .WithDisplayName("GetInstances") |
| | 131 | 21 | | .WithSummary("Gets the list of instances from a project") |
| | 131 | 22 | | .WithDescription("Gets the list of instances from a project") |
| | 131 | 23 | | .Produces<List<FieldDefinitionModel>>(StatusCodes.Status200OK) |
| | 131 | 24 | | .Produces<string>(StatusCodes.Status404NotFound) |
| | 131 | 25 | | .Produces<string>(StatusCodes.Status400BadRequest); |
| | | 26 | | |
| | 131 | 27 | | instancesApi.MapPost("/{runnableProjectId}/search", |
| | 131 | 28 | | (IInstanceService instanceService, |
| | 131 | 29 | | [Description("ID of runnable project")] string runnableProjectId, |
| | 131 | 30 | | [FromBody] InstancePagedSearchRequest search) |
| | 1 | 31 | | => SearchInstances.Handle(instanceService, runnableProjectId, search)) |
| | 131 | 32 | | .WithName("SearchInstances") |
| | 131 | 33 | | .WithDisplayName("SearchInstances") |
| | 131 | 34 | | .WithSummary("Searches the list of instances from a project") |
| | 131 | 35 | | .WithDescription("Searches the list of instances from a project") |
| | 131 | 36 | | .Produces<PagedSearchResult<FieldDefinitionModel>>(StatusCodes.Status200OK) |
| | 131 | 37 | | .Produces<string>(StatusCodes.Status404NotFound) |
| | 131 | 38 | | .Produces<string>(StatusCodes.Status400BadRequest); |
| | | 39 | | |
| | 131 | 40 | | instancesApi.MapGet("/{runnableProjectId}/{instanceName}", |
| | 131 | 41 | | (IInstanceService instanceService, |
| | 131 | 42 | | [Description("ID of runnable project")] string runnableProjectId, |
| | 131 | 43 | | [Description("Name of instance")] string instanceName) |
| | 2 | 44 | | => GetInstance.Handle(instanceService, runnableProjectId, instanceName)) |
| | 131 | 45 | | .WithName("GetInstance") |
| | 131 | 46 | | .WithDisplayName("GetInstance") |
| | 131 | 47 | | .WithSummary("Gets an instance of a project by its name") |
| | 131 | 48 | | .WithDescription("Gets an instance of a project by its name") |
| | 131 | 49 | | .Produces<FieldDefinitionModel>(StatusCodes.Status200OK) |
| | 131 | 50 | | .Produces<string>(StatusCodes.Status404NotFound) |
| | 131 | 51 | | .Produces<string>(StatusCodes.Status400BadRequest); |
| | | 52 | | |
| | 131 | 53 | | instancesApi.MapPost("/{runnableProjectId}", |
| | 131 | 54 | | (IInstanceService instanceService, |
| | 131 | 55 | | [Description("ID of runnable project")] string runnableProjectId, |
| | 131 | 56 | | [Description("Instance creation request")][FromBody] InstanceModel createRequest, |
| | 131 | 57 | | [FromQuery] bool addToRunningInstances = true) |
| | 5 | 58 | | => CreateInstance.Handle(instanceService, runnableProjectId, createRequest, addToRunningInstances)) |
| | 131 | 59 | | .WithName("CreateInstance") |
| | 131 | 60 | | .WithDisplayName("CreateInstance") |
| | 131 | 61 | | .WithSummary("Creates an instance with a class of a project") |
| | 131 | 62 | | .WithDescription("Creates an instance with a class of a project") |
| | 131 | 63 | | .Produces<FieldDefinitionModel>(StatusCodes.Status201Created) |
| | 131 | 64 | | .Produces<string>(StatusCodes.Status404NotFound) |
| | 131 | 65 | | .Produces<string>(StatusCodes.Status400BadRequest); |
| | | 66 | | |
| | 131 | 67 | | instancesApi.MapDelete("/{runnableProjectId}/{instanceName}", |
| | 131 | 68 | | (IInstanceService instanceService, |
| | 131 | 69 | | [Description("ID of runnable project")] string runnableProjectId, |
| | 131 | 70 | | [Description("Name of instance")] string instanceName) |
| | 3 | 71 | | => DeleteInstance.Handle(instanceService, runnableProjectId, instanceName)) |
| | 131 | 72 | | .WithName("DeleteInstance") |
| | 131 | 73 | | .WithDisplayName("DeleteInstance") |
| | 131 | 74 | | .WithSummary("Deletes an instance from a project by its name") |
| | 131 | 75 | | .WithDescription("Deletes an instance from a project by its name") |
| | 131 | 76 | | .Produces(StatusCodes.Status204NoContent) |
| | 131 | 77 | | .Produces<string>(StatusCodes.Status404NotFound) |
| | 131 | 78 | | .Produces<string>(StatusCodes.Status400BadRequest); |
| | | 79 | | |
| | 131 | 80 | | instancesApi.MapGet("/{runnableProjectId}/{instanceName}/{fieldName}/value", |
| | 131 | 81 | | async (IFieldValueService fieldValueService, |
| | 131 | 82 | | [Description("ID of runnable project")] string runnableProjectId, |
| | 131 | 83 | | [Description("Name of instance")] string instanceName, |
| | 131 | 84 | | [Description("Name of field")] string fieldName) |
| | 18 | 85 | | => await GetInstanceField.Handle(fieldValueService, runnableProjectId, instanceName, fieldName)) |
| | 131 | 86 | | .WithName("GetField") |
| | 131 | 87 | | .WithDisplayName("GetField") |
| | 131 | 88 | | .WithSummary("Gets the field of an instance from a project by its name") |
| | 131 | 89 | | .WithDescription("Gets the field of an instance from a project by its name") |
| | 131 | 90 | | .Produces<FieldModel>(StatusCodes.Status200OK) |
| | 131 | 91 | | .Produces<string>(StatusCodes.Status404NotFound) |
| | 131 | 92 | | .Produces<string>(StatusCodes.Status400BadRequest); |
| | | 93 | | |
| | 131 | 94 | | instancesApi.MapPut("/{runnableProjectId}/{instanceName}/{fieldName}/value", |
| | 131 | 95 | | async (IFieldValueService fieldValueService, |
| | 131 | 96 | | [Description("ID of runnable project")] string runnableProjectId, |
| | 131 | 97 | | [Description("Name of instance")] string instanceName, |
| | 131 | 98 | | [Description("Name of field")] string fieldName, |
| | 131 | 99 | | [Description("Value of field")][FromBody] FieldValueModel value) |
| | 70 | 100 | | => await UpdateInstanceFieldValue.Handle(fieldValueService, runnableProjectId, instanceName, fieldNa |
| | 131 | 101 | | .WithName("UpdateFieldValue") |
| | 131 | 102 | | .WithDisplayName("UpdateFieldValue") |
| | 131 | 103 | | .WithSummary("Updates the value of a field of an instance from a project by its name") |
| | 131 | 104 | | .WithDescription("Updates the value of a field of an instance from a project by its name") |
| | 131 | 105 | | .Produces<FieldValueModel>(StatusCodes.Status200OK) |
| | 131 | 106 | | .Produces<string>(StatusCodes.Status404NotFound) |
| | 131 | 107 | | .Produces<string>(StatusCodes.Status400BadRequest); |
| | | 108 | | |
| | 131 | 109 | | return app; |
| | 131 | 110 | | } |
| | | 111 | | } |
| | | 112 | | } |