| | 1 | | using System.ComponentModel.DataAnnotations; |
| | 2 | | using LGDXRobotCloud.Data.Models.Business.Administration; |
| | 3 | |
|
| | 4 | | namespace LGDXRobotCloud.Data.Models.DTOs.V1.Commands; |
| | 5 | |
|
| | 6 | | public record ApiKeyCreateDto |
| | 7 | | { |
| | 8 | | [Required (ErrorMessage = "Please enter a name.")] |
| | 9 | | [MaxLength(50)] |
| | 10 | | public required string Name { get; set; } |
| | 11 | |
|
| | 12 | | [MaxLength(200)] |
| | 13 | | public string? Secret { get; set; } |
| | 14 | |
|
| | 15 | | [Required] |
| | 16 | | public required bool IsThirdParty { get; set; } |
| | 17 | |
|
| | 18 | | public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext) |
| | 19 | | { |
| | 20 | | if (IsThirdParty && string.IsNullOrWhiteSpace(Secret)) |
| | 21 | | { |
| | 22 | | yield return new ValidationResult("Secret is required for Third-Party API Key.", [nameof(Secret)]); |
| | 23 | | } |
| | 24 | | if (!IsThirdParty && !string.IsNullOrWhiteSpace(Secret)) |
| | 25 | | { |
| | 26 | | yield return new ValidationResult("LGDXRobot Cloud API Keys will be generated automatically.", [nameof(Secret)]); |
| | 27 | | } |
| | 28 | | } |
| | 29 | | } |
| | 30 | |
|
| | 31 | | public static class ApiKeyCreateDtoExtensions |
| | 32 | | { |
| | 33 | | public static ApiKeyCreateBusinessModel ToBusinessModel(this ApiKeyCreateDto apiKey) |
| 0 | 34 | | { |
| 0 | 35 | | return new ApiKeyCreateBusinessModel{ |
| 0 | 36 | | Name = apiKey.Name, |
| 0 | 37 | | Secret = apiKey.Secret, |
| 0 | 38 | | IsThirdParty = apiKey.IsThirdParty |
| 0 | 39 | | }; |
| 0 | 40 | | } |
| | 41 | | } |