| | 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 TriggerUpdateDto : IValidatableObject |
| | 7 | | { |
| | 8 | | [Required (ErrorMessage = "Please enter a name.")] |
| | 9 | | [MaxLength(50)] |
| | 10 | | public required string Name { get; set; } |
| | 11 | |
|
| | 12 | | [Required (ErrorMessage = "Please enter an URL.")] |
| | 13 | | [MaxLength(200)] |
| | 14 | | public required string Url { get; set; } |
| | 15 | |
|
| | 16 | | public required int HttpMethodId { get; set; } |
| | 17 | |
|
| | 18 | | public string? Body { get; set; } |
| | 19 | |
|
| | 20 | | public required bool SkipOnFailure { get; set; } = false; |
| | 21 | |
|
| | 22 | | public int? ApiKeyInsertLocationId { get; set; } |
| | 23 | |
|
| | 24 | | [MaxLength(50)] |
| | 25 | | public string? ApiKeyFieldName { get; set; } |
| | 26 | |
|
| | 27 | | public int? ApiKeyId { get; set; } |
| | 28 | |
|
| | 29 | | public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) |
| | 30 | | { |
| | 31 | | if (!(ApiKeyInsertLocationId == null && string.IsNullOrWhiteSpace(ApiKeyFieldName) && ApiKeyId == null)) |
| | 32 | | { |
| | 33 | | if (ApiKeyInsertLocationId == null) |
| | 34 | | { |
| | 35 | | yield return new ValidationResult("Please select an insert location.", [nameof(ApiKeyInsertLocationId)]); |
| | 36 | | } |
| | 37 | | if (ApiKeyFieldName == null) |
| | 38 | | { |
| | 39 | | yield return new ValidationResult("Please enter a field name.", [nameof(ApiKeyFieldName)]); |
| | 40 | | } |
| | 41 | | if (ApiKeyId == null) |
| | 42 | | { |
| | 43 | | yield return new ValidationResult("Please select an API Key.", [nameof(ApiKeyId)]); |
| | 44 | | } |
| | 45 | | } |
| | 46 | | } |
| | 47 | | } |
| | 48 | |
|
| | 49 | | public static class TriggerUpdateDtoExtensions |
| | 50 | | { |
| | 51 | | public static TriggerUpdateBusinessModel ToBusinessModel(this TriggerUpdateDto triggerUpdateDto) |
| 0 | 52 | | { |
| 0 | 53 | | return new TriggerUpdateBusinessModel { |
| 0 | 54 | | Name = triggerUpdateDto.Name, |
| 0 | 55 | | Url = triggerUpdateDto.Url, |
| 0 | 56 | | HttpMethodId = triggerUpdateDto.HttpMethodId, |
| 0 | 57 | | Body = triggerUpdateDto.Body, |
| 0 | 58 | | SkipOnFailure = triggerUpdateDto.SkipOnFailure, |
| 0 | 59 | | ApiKeyInsertLocationId = triggerUpdateDto.ApiKeyInsertLocationId, |
| 0 | 60 | | ApiKeyFieldName = triggerUpdateDto.ApiKeyFieldName, |
| 0 | 61 | | ApiKeyId = triggerUpdateDto.ApiKeyId, |
| 0 | 62 | | }; |
| 0 | 63 | | } |
| | 64 | | } |