| | | 1 | | using Microsoft.AspNetCore.Mvc; |
| | | 2 | | using pva.SuperV.Model; |
| | | 3 | | using pva.SuperV.Model.FieldDefinitions; |
| | | 4 | | using pva.SuperV.Model.Services; |
| | | 5 | | using System.ComponentModel; |
| | | 6 | | |
| | | 7 | | namespace pva.SuperV.Api.Routes.FieldDefinitions |
| | | 8 | | { |
| | | 9 | | public static class FieldDefinitionEndpoints |
| | | 10 | | { |
| | | 11 | | public static WebApplication MapFieldDefinitionEndpoints(this WebApplication app) |
| | 131 | 12 | | { |
| | 131 | 13 | | RouteGroupBuilder fieldDefinitionsApi = app.MapGroup("/fields"); |
| | 131 | 14 | | fieldDefinitionsApi.MapGet("/{projectId}/{className}", |
| | 131 | 15 | | async (IFieldDefinitionService fieldDefinitionService, |
| | 131 | 16 | | [Description("ID of project")] string projectId, |
| | 131 | 17 | | [Description("Name of class")] string className) |
| | 2 | 18 | | => await GetFieldDefinitions.Handle(fieldDefinitionService, projectId, className)) |
| | 131 | 19 | | .WithName("GetFieldDefinitions") |
| | 131 | 20 | | .WithDisplayName("GetFieldDefinitions") |
| | 131 | 21 | | .WithSummary("Gets the list of available fields in a class from a project") |
| | 131 | 22 | | .WithDescription("Gets the list of available fields in a class 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 | | fieldDefinitionsApi.MapPost("/{projectId}/{className}/search", |
| | 131 | 28 | | async (IFieldDefinitionService fieldDefinitionService, |
| | 131 | 29 | | [Description("ID of project")] string projectId, |
| | 131 | 30 | | [Description("Name of class")] string className, |
| | 131 | 31 | | [FromBody] FieldDefinitionPagedSearchRequest search) |
| | 1 | 32 | | => await SearchFieldDefinitions.Handle(fieldDefinitionService, projectId, className, search)) |
| | 131 | 33 | | .WithName("SearchFieldDefinitions") |
| | 131 | 34 | | .WithDisplayName("SearchFieldDefinitions") |
| | 131 | 35 | | .WithSummary("Searches the list of available fields in a class from a project") |
| | 131 | 36 | | .WithDescription("Searches the list of available fields in a class from a project") |
| | 131 | 37 | | .Produces<PagedSearchResult<FieldDefinitionModel>>(StatusCodes.Status200OK) |
| | 131 | 38 | | .Produces<string>(StatusCodes.Status404NotFound) |
| | 131 | 39 | | .Produces<string>(StatusCodes.Status400BadRequest); |
| | | 40 | | |
| | 131 | 41 | | fieldDefinitionsApi.MapGet("/{projectId}/{className}/{fieldName}", |
| | 131 | 42 | | async (IFieldDefinitionService fieldDefinitionService, |
| | 131 | 43 | | [Description("ID of project")] string projectId, |
| | 131 | 44 | | [Description("Name of class")] string className, |
| | 131 | 45 | | [Description("Name of field")] string fieldName) |
| | 13 | 46 | | => await GetFieldDefinition.Handle(fieldDefinitionService, projectId, className, fieldName)) |
| | 131 | 47 | | .WithName("GetFieldDefinition") |
| | 131 | 48 | | .WithDisplayName("GetFieldDefinition") |
| | 131 | 49 | | .WithSummary("Gets a field definition from a class of a project by its name") |
| | 131 | 50 | | .WithDescription("Gets a field definitionfrom a class of a project by its name") |
| | 131 | 51 | | .Produces<FieldDefinitionModel>(StatusCodes.Status200OK) |
| | 131 | 52 | | .Produces<string>(StatusCodes.Status404NotFound) |
| | 131 | 53 | | .Produces<string>(StatusCodes.Status400BadRequest); |
| | | 54 | | |
| | 131 | 55 | | fieldDefinitionsApi.MapPost("/{wipProjectId}/{className}", |
| | 131 | 56 | | async (IFieldDefinitionService fieldDefinitionService, |
| | 131 | 57 | | [Description("ID of WIP project")] string wipProjectId, |
| | 131 | 58 | | [Description("Name of class")] string className, |
| | 131 | 59 | | [Description("Field creation requests")][FromBody] List<FieldDefinitionModel> createRequests) |
| | 6 | 60 | | => await CreateFieldDefinitions.Handle(fieldDefinitionService, wipProjectId, className, createReques |
| | 131 | 61 | | .WithName("CreateFieldDefinitions") |
| | 131 | 62 | | .WithDisplayName("CreateFieldDefinitions") |
| | 131 | 63 | | .WithSummary("Creates field definitions in a class of a WIP project") |
| | 131 | 64 | | .WithDescription("Creates field definitions in a class of a WIP project") |
| | 131 | 65 | | .Produces<List<FieldDefinitionModel>>(StatusCodes.Status201Created) |
| | 131 | 66 | | .Produces<string>(StatusCodes.Status404NotFound) |
| | 131 | 67 | | .Produces<string>(StatusCodes.Status400BadRequest); |
| | | 68 | | |
| | 131 | 69 | | fieldDefinitionsApi.MapPut("/{wipProjectId}/{className}/{fieldName}", |
| | 131 | 70 | | async (IFieldDefinitionService fieldDefinitionService, |
| | 131 | 71 | | [Description("ID of WIP project")] string wipProjectId, |
| | 131 | 72 | | [Description("Name of class")] string className, |
| | 131 | 73 | | [Description("Name of class")] string fieldName, |
| | 131 | 74 | | [Description("Field update request")][FromBody] FieldDefinitionModel updateRequest) |
| | 3 | 75 | | => await UpdateFieldDefinition.Handle(fieldDefinitionService, wipProjectId, className, fieldName, up |
| | 131 | 76 | | .WithName("UpdateFieldDefinition") |
| | 131 | 77 | | .WithDisplayName("UpdateFieldDefinition") |
| | 131 | 78 | | .WithSummary("Updates field definition in a class of a WIP project") |
| | 131 | 79 | | .WithDescription("Uodates field definition in a class of a WIP project") |
| | 131 | 80 | | .Produces<List<FieldDefinitionModel>>(StatusCodes.Status200OK) |
| | 131 | 81 | | .Produces<string>(StatusCodes.Status404NotFound) |
| | 131 | 82 | | .Produces<string>(StatusCodes.Status400BadRequest); |
| | | 83 | | |
| | 131 | 84 | | fieldDefinitionsApi.MapDelete("/{wipProjectId}/{className}/{fieldName}", |
| | 131 | 85 | | async (IFieldDefinitionService fieldDefinitionService, |
| | 131 | 86 | | [Description("ID of WIP project")] string wipProjectId, |
| | 131 | 87 | | [Description("Name of class")] string className, |
| | 131 | 88 | | [Description("Name of field")] string fieldName) |
| | 3 | 89 | | => await DeleteFieldDefinition.Handle(fieldDefinitionService, wipProjectId, className, fieldName)) |
| | 131 | 90 | | .WithName("DeleteFieldDefinition") |
| | 131 | 91 | | .WithDisplayName("DeleteFieldDefinition") |
| | 131 | 92 | | .WithSummary("Deletes a field definition from a class of a WIP project by its name") |
| | 131 | 93 | | .WithDescription("Deletes a field definition from a class of a WIP project by its name") |
| | 131 | 94 | | .Produces(StatusCodes.Status204NoContent) |
| | 131 | 95 | | .Produces<string>(StatusCodes.Status404NotFound) |
| | 131 | 96 | | .Produces<string>(StatusCodes.Status400BadRequest); |
| | | 97 | | |
| | 131 | 98 | | return app; |
| | 131 | 99 | | } |
| | | 100 | | } |
| | | 101 | | } |