Restructure project with namespace updates and renamed files for better organization. Migrate project name from FsTool to FsToolbox.Cli.

This commit is contained in:
Andre Beging
2025-12-11 19:04:18 +01:00
parent 9f82cf491c
commit 46229a6dc7
14 changed files with 319 additions and 219 deletions

View File

@@ -1,7 +1,9 @@
namespace FsTool.Tasks
namespace FsToolbox.Cli.Tasks
{
public partial class RegionTasks
{
#region Record Store
/// <summary>
/// Basic region store information including cooperation status.
/// </summary>
@@ -10,6 +12,10 @@ namespace FsTool.Tasks
/// <param name="CooperationStatus">The cooperation status of the store.</param>
public record Store(int Id, string Name, CooperationStatus CooperationStatus);
#endregion
#region Enum CooperationStatus
/// <summary>
/// Describes the cooperation state between the store and the organization.
/// </summary>
@@ -21,7 +27,9 @@ namespace FsTool.Tasks
DoNotWant = 4,
Cooperating = 5,
DonatingToTafel = 6,
NoExisting = 7,
NoExisting = 7
}
#endregion
}
}

View File

@@ -1,12 +1,13 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using FsTool;
using FsTool.Helpers;
using FsToolbox.Cli.Helpers;
namespace FsTool.Tasks
namespace FsToolbox.Cli.Tasks
{
public partial class RegionTasks
{
#region Public Method GetStoresInRegionAsync
/// <summary>
/// Retrieves all stores within the specified region, ensuring the request is authenticated.
/// </summary>
@@ -38,10 +39,12 @@ namespace FsTool.Tasks
var opts = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = null // <── WICHTIG
PropertyNamingPolicy = null // <── WICHTIG
};
return root["stores"].Deserialize<List<Store>>(opts) ?? [];
}
#endregion
}
}
}

View File

@@ -1,27 +1,8 @@
namespace FsTool.Tasks
namespace FsToolbox.Cli.Tasks
{
public static partial class StoreTasks
{
/// <summary>
/// Represents a pickup date and the occupied slots for that date.
/// </summary>
/// <param name="Date">The pickup date string.</param>
/// <param name="OccupiedSlots">The slots already assigned for the date.</param>
public record Pickup(string Date, List<Slot> OccupiedSlots);
/// <summary>
/// Describes a booked slot and the profile occupying it.
/// </summary>
/// <param name="IsConfirmed">Indicates whether the slot is confirmed.</param>
/// <param name="Profile">The profile assigned to the slot.</param>
public record Slot(bool IsConfirmed, Profile Profile);
/// <summary>
/// Minimal profile information for a store member.
/// </summary>
/// <param name="Id">The Foodsharing profile identifier.</param>
/// <param name="Name">The profile display name.</param>
public record Profile(int Id, string Name);
#region Record Member
/// <summary>
/// Detailed store member information including verification and team status flags.
@@ -32,22 +13,65 @@ namespace FsTool.Tasks
/// <param name="Verified">The verification state of the member.</param>
public record Member(int Id, string Name, TeamActiveStatus Team_Active, VerifiedStatus Verified);
#endregion
#region Record Pickup
/// <summary>
/// Represents a pickup date and the occupied slots for that date.
/// </summary>
/// <param name="Date">The pickup date string.</param>
/// <param name="OccupiedSlots">The slots already assigned for the date.</param>
public record Pickup(string Date, List<Slot> OccupiedSlots);
#endregion
#region Record Profile
/// <summary>
/// Minimal profile information for a store member.
/// </summary>
/// <param name="Id">The Foodsharing profile identifier.</param>
/// <param name="Name">The profile display name.</param>
public record Profile(int Id, string Name);
#endregion
#region Record Slot
/// <summary>
/// Describes a booked slot and the profile occupying it.
/// </summary>
/// <param name="IsConfirmed">Indicates whether the slot is confirmed.</param>
/// <param name="Profile">The profile assigned to the slot.</param>
public record Slot(bool IsConfirmed, Profile Profile);
#endregion
#region Enum TeamActiveStatus
/// <summary>
/// Indicates whether a team member is active or only available as a jumper.
/// </summary>
public enum TeamActiveStatus
{
Jumper = 2,
Active = 1,
Active = 1
}
#endregion
#region Enum VerifiedStatus
/// <summary>
/// Specifies whether a member has completed verification.
/// </summary>
public enum VerifiedStatus
{
Unverified = 0,
Verified = 1,
Verified = 1
}
#endregion
}
}

View File

@@ -1,13 +1,48 @@
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Nodes;
using FsTool;
using FsTool.Helpers;
using FsToolbox.Cli.Helpers;
namespace FsTool.Tasks
namespace FsToolbox.Cli.Tasks
{
public static partial class StoreTasks
{
#region Public Method GetPickupsAsync
/// <summary>
/// Retrieves all pickups for the specified store with authentication handled automatically.
/// </summary>
/// <param name="httpClient">The HTTP client used to send the request.</param>
/// <param name="storeId">The store identifier to query.</param>
/// <returns>A list of pickups, or an empty list when no data is available.</returns>
public static async Task<List<Pickup>> GetPickupsAsync(HttpClient httpClient, int storeId)
{
await AuthHelper.EnsureAuthenticationAsync(httpClient);
var uri = string.Format(Endpoints.StorePickups, storeId);
var response = await httpClient.GetAsync(uri);
var responseBody = await response.Content.ReadAsStringAsync();
// handle unsuccessful response
if (!response.IsSuccessStatusCode) await Console.Error.WriteLineAsync($"Pickup retrieval failed ({(int)response.StatusCode} {response.ReasonPhrase}): {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["pickups"].Deserialize<List<Pickup>>(opts) ?? [];
}
#endregion
#region Public Method GetStoreMembersAsync
/// <summary>
/// Retrieves the members of the specified store, requiring authentication before the request.
/// </summary>
@@ -36,45 +71,15 @@ namespace FsTool.Tasks
var opts = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = null // <── WICHTIG
PropertyNamingPolicy = null // <── WICHTIG
};
return root.Deserialize<List<Member>>(opts) ?? [];
}
/// <summary>
/// Retrieves all pickups for the specified store with authentication handled automatically.
/// </summary>
/// <param name="httpClient">The HTTP client used to send the request.</param>
/// <param name="storeId">The store identifier to query.</param>
/// <returns>A list of pickups, or an empty list when no data is available.</returns>
public static async Task<List<Pickup>> GetPickupsAsync(HttpClient httpClient, int storeId)
{
await AuthHelper.EnsureAuthenticationAsync(httpClient);
#endregion
var uri = string.Format(Endpoints.StorePickups, storeId);
var response = await httpClient.GetAsync(uri);
var responseBody = await response.Content.ReadAsStringAsync();
// handle unsuccessful response
if (!response.IsSuccessStatusCode)
{
await Console.Error.WriteLineAsync($"Pickup retrieval failed ({(int)response.StatusCode} {response.ReasonPhrase}): {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["pickups"].Deserialize<List<Pickup>>(opts) ?? [];
}
#region Public Method PatchPickupAsync
/// <summary>
/// Marks a pickup slot as confirmed for the specified store, date, and user.
@@ -102,5 +107,7 @@ namespace FsTool.Tasks
else
Console.WriteLine($"Pickup patch succeeded {fsId} on {pickupDate}");
}
#endregion
}
}
}

View File

@@ -1,10 +1,9 @@
using System;
using System.Linq;
using System.Net.Http.Json;
using FsTool;
using FsTool.Helpers;
using FsToolbox.Cli.Helpers;
namespace FsTool.Tasks
namespace FsToolbox.Cli.Tasks
{
public static class UserTasks
{
@@ -77,7 +76,7 @@ namespace FsTool.Tasks
var expiryEntry = cookies.FirstOrDefault(c => c.Trim().StartsWith("expires="));
var expireString = expiryEntry?.Split('=')[1];
if (DateTime.TryParse(expireString, out var expiration))
await AuthHelper.StoreCsrfTokenAsync(csrfToken, expiration);
await FsToolbox.Cli.Helpers.AuthHelper.StoreCsrfTokenAsync(csrfToken, expiration);
}
return csrfToken;
@@ -90,7 +89,7 @@ namespace FsTool.Tasks
/// <returns>A task that represents the asynchronous operation.</returns>
public static async Task GetCurrentUserAsync(HttpClient httpClient)
{
await AuthHelper.EnsureAuthenticationAsync(httpClient);
await FsToolbox.Cli.Helpers.AuthHelper.EnsureAuthenticationAsync(httpClient);
var response = await httpClient.GetAsync(Endpoints.UserCurrent);