|
| 1 | +using DevExcelerateApi.Core.Extensions; |
| 2 | +using DevExcelerateApi.Helpers; |
| 3 | + |
| 4 | +namespace DevExcelerateApi.Models |
| 5 | +{ |
| 6 | + public class CreateTeamRequestModel : DevExIssueRequestModel |
| 7 | + { |
| 8 | + public string? TeamOwner { get; set; } // will be inherited from issue |
| 9 | + |
| 10 | + public string? TeamName { get; set; } |
| 11 | + |
| 12 | + public string? TeamDescription { get; set; } |
| 13 | + |
| 14 | + public string? ParentTeamName { get; set; } |
| 15 | + |
| 16 | + public string? TeamIdentityProviderGroup { get; set; } |
| 17 | + |
| 18 | + // TeamPrivacy: secret, closed (visible to all members of the organization.) |
| 19 | + public string? TeamVisibility { get; set; } |
| 20 | + |
| 21 | + public string? TeamMaintainers { get; set; } // will be inherited from issue |
| 22 | + |
| 23 | + public string? TeamMembers { get; set; } |
| 24 | + |
| 25 | + public static new CreateTeamRequestModel Parse(IDictionary<string, object?> values) |
| 26 | + { |
| 27 | + ArgumentNullException.ThrowIfNull(values); |
| 28 | + |
| 29 | + values.TryGetValue("team_owner", out var teamOwner); |
| 30 | + values.TryGetValue("team_name", out var teamName); |
| 31 | + values.TryGetValue("team_description", out var teamDescription); |
| 32 | + values.TryGetValue("parent_team_name", out var parentTeamName); |
| 33 | + values.TryGetValue("team_identity_provider_group", out var teamIdentityProviderGroup); |
| 34 | + values.TryGetValue("team_visibility", out var teamVisibility); |
| 35 | + values.TryGetValue("team_maintainers", out var teamMaintainers); |
| 36 | + values.TryGetValue("team_members", out var teamMembers); |
| 37 | + |
| 38 | + return new CreateTeamRequestModel |
| 39 | + { |
| 40 | + RequestType = DevExIssueRequestModel.Parse(values).RequestType, |
| 41 | + TeamOwner = teamOwner?.ToString(), |
| 42 | + TeamName = teamName?.ToString()?.SanitizeResourceName(), |
| 43 | + TeamDescription = teamDescription?.ToString(), |
| 44 | + ParentTeamName = parentTeamName?.ToString(), |
| 45 | + TeamIdentityProviderGroup = teamIdentityProviderGroup?.ToString(), |
| 46 | + TeamVisibility = teamVisibility?.ToString(), |
| 47 | + TeamMaintainers = teamMaintainers?.ToString(), |
| 48 | + TeamMembers = teamMembers?.ToString(), |
| 49 | + }; |
| 50 | + } |
| 51 | + |
| 52 | + public bool IsValid() |
| 53 | + { |
| 54 | + return !string.IsNullOrEmpty(TeamName) && |
| 55 | + !string.IsNullOrEmpty(TeamDescription) && |
| 56 | + !string.IsNullOrEmpty(TeamVisibility); |
| 57 | + } |
| 58 | + |
| 59 | + public string SerializeToYaml() |
| 60 | + { |
| 61 | + return YamlHelpers.Serialize(this); |
| 62 | + } |
| 63 | + |
| 64 | + public static CreateTeamRequestModel DeserializeFromYaml(string yamlContent) |
| 65 | + { |
| 66 | + ArgumentNullException.ThrowIfNull(yamlContent); |
| 67 | + return YamlHelpers.Deserialize<CreateTeamRequestModel>(yamlContent); |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments