| | 1 | | using System.ComponentModel.DataAnnotations; |
| | 2 | | using LGDXRobotCloud.Data.Models.Business.Automation; |
| | 3 | |
|
| | 4 | | namespace LGDXRobotCloud.Data.Models.DTOs.V1.Commands; |
| | 5 | |
|
| | 6 | | public record TriggerCreateDto |
| | 7 | | { |
| | 8 | | [Required (ErrorMessage = "Please enter a name.")] |
| | 9 | | [MaxLength(50)] |
| 0 | 10 | | public required string Name { get; set; } |
| | 11 | |
|
| | 12 | | [Required (ErrorMessage = "Please enter an URL.")] |
| | 13 | | [MaxLength(200)] |
| 0 | 14 | | public required string Url { get; set; } |
| | 15 | |
|
| 0 | 16 | | public required int HttpMethodId { get; set; } |
| | 17 | |
|
| 0 | 18 | | public string? Body { get; set; } |
| | 19 | |
|
| 0 | 20 | | public required bool SkipOnFailure { get; set; } = false; |
| | 21 | |
|
| 0 | 22 | | public int? ApiKeyInsertLocationId { get; set; } |
| | 23 | |
|
| | 24 | | [MaxLength(50)] |
| 0 | 25 | | public string? ApiKeyFieldName { get; set; } |
| | 26 | |
|
| 0 | 27 | | public int? ApiKeyId { get; set; } |
| | 28 | |
|
| | 29 | | public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) |
| 0 | 30 | | { |
| 0 | 31 | | if (!(ApiKeyInsertLocationId != null && ApiKeyFieldName != null && ApiKeyId != null)) |
| 0 | 32 | | { |
| 0 | 33 | | if (ApiKeyInsertLocationId == null) |
| 0 | 34 | | { |
| 0 | 35 | | yield return new ValidationResult("Please select an insert location.", [nameof(ApiKeyInsertLocationId)]); |
| 0 | 36 | | } |
| 0 | 37 | | if (ApiKeyFieldName == null) |
| 0 | 38 | | { |
| 0 | 39 | | yield return new ValidationResult("Please enter a field name.", [nameof(ApiKeyFieldName)]); |
| 0 | 40 | | } |
| 0 | 41 | | if (ApiKeyId == null) |
| 0 | 42 | | { |
| 0 | 43 | | yield return new ValidationResult("Please select an API Key.", [nameof(ApiKeyId)]); |
| 0 | 44 | | } |
| 0 | 45 | | } |
| 0 | 46 | | } |
| | 47 | | } |
| | 48 | |
|
| | 49 | | public static class TriggerCreateDtoExtensions |
| | 50 | | { |
| | 51 | | public static TriggerCreateBusinessModel ToBusinessModel(this TriggerCreateDto triggerCreateDto) |
| | 52 | | { |
| | 53 | | return new TriggerCreateBusinessModel { |
| | 54 | | Name = triggerCreateDto.Name, |
| | 55 | | Url = triggerCreateDto.Url, |
| | 56 | | HttpMethodId = triggerCreateDto.HttpMethodId, |
| | 57 | | Body = triggerCreateDto.Body, |
| | 58 | | SkipOnFailure = triggerCreateDto.SkipOnFailure, |
| | 59 | | ApiKeyInsertLocationId = triggerCreateDto.ApiKeyInsertLocationId, |
| | 60 | | ApiKeyFieldName = triggerCreateDto.ApiKeyFieldName, |
| | 61 | | ApiKeyId = triggerCreateDto.ApiKeyId, |
| | 62 | | }; |
| | 63 | | } |
| | 64 | | } |