Skip to content

Commit 8850457

Browse files
committed
fix: Improves subscription status handling
Improves the handling of subscription statuses by introducing a dedicated enum and mapping logic. This change decouples the status property from the underlying string representation and provides a more robust and maintainable way to represent and process subscription states, including handling cases where the status might not directly map to a known enum value.
1 parent 0fa0c9e commit 8850457

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

libs/HyperGuestSDK/Api/Pdm/Subscriptions/Subscription.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,39 @@ public SubscriptionStatus Status
8282
public class SubscriptionSummary
8383
{
8484
/// <summary>
85-
/// Gets or sets the status of the subscription.
85+
/// Gets or sets the status.
8686
/// </summary>
8787
[JsonPropertyName("status")]
88-
public SubscriptionStatus Status { get; set; }
88+
public string? StatusValue { get; set; }
8989

9090
/// <summary>
9191
/// Gets or sets the subscription ID.
9292
/// </summary>
9393
[JsonPropertyName("subscriptionId")]
9494
public required string SubscriptionId { get; set; }
95+
96+
#region Presentational
97+
/// <summary>
98+
/// Gets the status as a <see cref="SubscriptionStatus"/> enum value.
99+
/// </summary>
100+
public SubscriptionStatus Status
101+
{
102+
get
103+
{
104+
if (Enum.TryParse<SubscriptionStatus>(StatusValue, true, out var status))
105+
{
106+
return status;
107+
}
108+
109+
if (string.Equals("already exists", StatusValue, StringComparison.OrdinalIgnoreCase))
110+
{
111+
return SubscriptionStatus.Duplicate;
112+
}
113+
114+
return SubscriptionStatus.Unknown;
115+
}
116+
}
117+
#endregion
95118
}
96119

97120
/// <summary>

libs/HyperGuestSDK/Api/Pdm/Subscriptions/SubscriptionOperations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public async Task<HyperGuestResponse<Subscription>> GetSubscriptionAsync(string
136136
var request = new HyperGuestRequest(
137137
HyperGuestService.Pdm,
138138
HttpMethod.Get,
139-
path + $"/{subscriptionId}/getSubscription");
139+
path + $"/{subscriptionId}/getSubscriptionDetails");
140140

141141
return await client.FetchAsync<Subscription>(request, cancellationToken)
142142
.ConfigureAwait(false);

0 commit comments

Comments
 (0)