Move CLI project into subfolder

This commit is contained in:
Andre Beging
2025-12-12 08:23:19 +01:00
parent 05b92e8f54
commit c9a56abe8b
15 changed files with 2 additions and 2 deletions

50
Cli/Tasks/RegionTasks.cs Normal file
View File

@@ -0,0 +1,50 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using FsToolbox.Cli.Helper;
namespace FsToolbox.Cli.Tasks
{
public static partial class RegionTasks
{
#region Public Method GetStoresInRegionAsync
/// <summary>
/// Retrieves all stores within the specified region, ensuring the request is authenticated.
/// </summary>
/// <param name="httpClient">The HTTP client used to perform the request.</param>
/// <param name="regionId">The region identifier to query.</param>
/// <returns>A list of stores, or an empty list when the call fails or returns no data.</returns>
public static async Task<List<Store>> GetStoresInRegionAsync(HttpClient httpClient, int regionId)
{
await AuthHelper.EnsureAuthenticationAsync(httpClient);
var uri = string.Format(Endpoints.RegionStores, regionId);
var response = await httpClient.GetAsync(uri);
var responseBody = await response.Content.ReadAsStringAsync();
// handle unsuccessful response
if (!response.IsSuccessStatusCode)
{
await Console.Error.WriteLineAsync($"Region stores retrieval failed ({(int)response.StatusCode} {response.ReasonPhrase}): {responseBody}");
return [];
}
Console.WriteLine($"Stores in region {regionId}:");
Console.WriteLine(responseBody);
var root = JsonNode.Parse(responseBody);
if (root == null) return [];
// Deserialize JsonNode to List<Pickup>
var opts = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = null // <── WICHTIG
};
return root["stores"].Deserialize<List<Store>>(opts) ?? [];
}
#endregion
}
}