| | | 1 | | using Microsoft.AspNetCore.Http.HttpResults; |
| | | 2 | | using pva.SuperV.Engine.Exceptions; |
| | | 3 | | using pva.SuperV.Model.FieldProcessings; |
| | | 4 | | using pva.SuperV.Model.Services; |
| | | 5 | | |
| | | 6 | | namespace pva.SuperV.Api.Routes.Scripts |
| | | 7 | | { |
| | | 8 | | internal static class CreateScript |
| | | 9 | | { |
| | | 10 | | internal static async Task<Results<Created<ScriptDefinitionModel>, NotFound<string>, BadRequest<string>>> |
| | | 11 | | Handle(IScriptService scriptService, string projectId, ScriptDefinitionModel createRequest) |
| | 3 | 12 | | { |
| | | 13 | | try |
| | 3 | 14 | | { |
| | 3 | 15 | | ScriptDefinitionModel createdScript = await scriptService.CreateScriptAsync(projectId, createRequest); |
| | 1 | 16 | | return TypedResults.Created<ScriptDefinitionModel>($"/field-processings/{projectId}/{createdScript.Name} |
| | | 17 | | } |
| | 1 | 18 | | catch (UnknownEntityException e) |
| | 1 | 19 | | { |
| | 1 | 20 | | return TypedResults.NotFound(e.Message); |
| | | 21 | | } |
| | 1 | 22 | | catch (SuperVException e) |
| | 1 | 23 | | { |
| | 1 | 24 | | return TypedResults.BadRequest(e.Message); |
| | | 25 | | } |
| | 3 | 26 | | } |
| | | 27 | | } |
| | | 28 | | } |