From 786fafefa56b5cacb359518698366152799ebb34 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Thu, 2 Jul 2026 22:07:08 +0200 Subject: [PATCH] =?UTF-8?q?PR=20N:=20polish=20pass=20=E2=80=94=20ClassIds?= =?UTF-8?q?=20static,=20drop=20loaded=20flag,=20mandator=20from=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three long-noted rough edges from the original analysis, each a one-line touch: - ClassIds becomes static class (was instantiable). - Home.razor.cs drops the `loaded` bool guard (Blazor already runs OnInitializedAsync exactly once per component instance). - Move the "Claudio Schaad" mandator default out of SettingsService into SettingsDataset.DefaultMandator, plumbed through appsettings.Development.json. Co-Authored-By: Claude Opus 4.7 --- IMPROVEMENT_PLAN.md | 1 + Schaad.Accounting.Common/ClassIds.cs | 2 +- .../Datasets/SettingsDataset.cs | 5 +++++ Schaad.Accounting.Services/SettingsService.cs | 3 ++- .../Components/Pages/Home.razor.cs | 16 +++++----------- .../appsettings.Development.json | 3 ++- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/IMPROVEMENT_PLAN.md b/IMPROVEMENT_PLAN.md index 0e36629..7a02c89 100644 --- a/IMPROVEMENT_PLAN.md +++ b/IMPROVEMENT_PLAN.md @@ -109,3 +109,4 @@ Analysis and phased plan produced 2026-07-02. See conversation history for full - **PR K** — Phase 5 item 27: introduce `IFxConverter.ConvertToChf(amount, fromCurrency)` and its `FxConverter` implementation. The vendor `IFxService` and the FixerIo API key are now hidden inside `FxConverter`; callers stop threading the API key through every method call. `ViewService` drops both `IFxService` and `ISettingsService` from its constructor and takes `IFxConverter` instead. Simplifies `GetAccountViewList` (no more per-call `settingsService.GetSettings()` reads) and `GetBalanceSheetView`. Two-test `FxConverterTestShould` locks in the target-currency and API-key routing. - **PR L** — Phase 2 item 10: drop the hand-rolled `Copy(target)` methods from `Account`, `BookingRule`, `BookingText`, `SubClass`, and `SplitPredefinition`; keep only a `Transaction.Clone()` for defensive-copy needs in `GetTransaction` / `ViewService.WithDisplaySign`. Every `SaveXxx` now uses `FindIndex` → in-place replace (or `Add` for new entries), moving the two "hidden" defaults (`Account.Currency = "CHF"` when unset, `Transaction.BookingDate = ValueDate` when unset) into the corresponding `SaveXxx` method where they belong. Fixes a pre-existing bug: `Transaction.Copy` never copied `RelatedParty`, so update-saves silently dropped it. Added `PreserveRelatedPartyWhenRoundTrippingTransaction` and `DefaultBookingDateToValueDateWhenBookingDateIsUnset` as regression tests. 42 tests total. - **PR M** — Phase 2 item 18 (final slice): add `ILogger` and log a match-count summary from `MatchOpenBankTransactions` (`"Matched {Matched} of {Total} open bank transactions"`). Completes item 18 — statement imports (PR H), repository save failures (PR J), and match runs now all emit structured logs. Also removes a dead `ISettingsService` injection from `Home.razor.cs` (declared with `[Inject]` but never used anywhere in the file). +- **PR N** — Small polish pass covering three long-noted rough edges from the original analysis: `ClassIds` becomes a `static class` (was instantiable); `Home.razor.cs` loses the redundant `loaded` guard in `OnInitializedAsync` (Blazor already runs that lifecycle hook once per component instance); the hardcoded `mandator = "Claudio Schaad"` in `SettingsService` moves to a `DefaultMandator` field on `SettingsDataset`, plumbed through `appsettings.Development.json`. diff --git a/Schaad.Accounting.Common/ClassIds.cs b/Schaad.Accounting.Common/ClassIds.cs index 52f3867..6e2579e 100644 --- a/Schaad.Accounting.Common/ClassIds.cs +++ b/Schaad.Accounting.Common/ClassIds.cs @@ -1,6 +1,6 @@ namespace Schaad.Accounting { - public class ClassIds + public static class ClassIds { public const int Activa = 1; public const int Passiva = 2; diff --git a/Schaad.Accounting.Common/Datasets/SettingsDataset.cs b/Schaad.Accounting.Common/Datasets/SettingsDataset.cs index 87cc132..25ad6d8 100644 --- a/Schaad.Accounting.Common/Datasets/SettingsDataset.cs +++ b/Schaad.Accounting.Common/Datasets/SettingsDataset.cs @@ -5,5 +5,10 @@ public string DataPath { get; set; } public string FixerIoApiKey { get; set; } + + /// + /// Mandator selected when the app starts. Users can switch via the header dropdown. + /// + public string DefaultMandator { get; set; } = "Claudio Schaad"; } } \ No newline at end of file diff --git a/Schaad.Accounting.Services/SettingsService.cs b/Schaad.Accounting.Services/SettingsService.cs index 59a778e..5de9255 100644 --- a/Schaad.Accounting.Services/SettingsService.cs +++ b/Schaad.Accounting.Services/SettingsService.cs @@ -10,12 +10,13 @@ namespace Schaad.Accounting.Services public class SettingsService : ISettingsService { private readonly SettingsDataset settingsDataset; - private string mandator = "Claudio Schaad"; + private string mandator; private int year = DateTime.Now.Year; public SettingsService(SettingsDataset settingsDataset) { this.settingsDataset = settingsDataset; + this.mandator = settingsDataset.DefaultMandator; } public int GetYear() diff --git a/Schaad.Accounting.UI/Components/Pages/Home.razor.cs b/Schaad.Accounting.UI/Components/Pages/Home.razor.cs index 3c2183d..f203894 100644 --- a/Schaad.Accounting.UI/Components/Pages/Home.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/Home.razor.cs @@ -37,25 +37,19 @@ public partial class Home : ComponentBase private List? matchingBankTransactions; private IReadOnlyList accounts = []; private IReadOnlyList bookingTexts = []; - + FluentInputFile? myFileByBuffer; int? progressPercent; string? progressTitle; bool IsCanceled; Dictionary Files = new(); - private bool loaded; - protected override Task OnInitializedAsync() { - if (loaded == false) { - matchingBankTransactions = viewService.MatchOpenBankTransactions(); - accounts = viewService.GetAccountViewList(); - bookingTexts = bookingTextRepository.GetBookingTextList().Select(b => b.Text).ToArray(); - loaded = true; - } - - return base.OnInitializedAsync(); + matchingBankTransactions = viewService.MatchOpenBankTransactions(); + accounts = viewService.GetAccountViewList(); + bookingTexts = bookingTextRepository.GetBookingTextList().Select(b => b.Text).ToArray(); + return base.OnInitializedAsync(); } async Task OnProgressChangeAsync(FluentInputFileEventArgs file) diff --git a/Schaad.Accounting.UI/appsettings.Development.json b/Schaad.Accounting.UI/appsettings.Development.json index 79a092d..c513c03 100644 --- a/Schaad.Accounting.UI/appsettings.Development.json +++ b/Schaad.Accounting.UI/appsettings.Development.json @@ -7,6 +7,7 @@ }, "Settings": { "DataPath": "D:\\Developer\\AccountingData\\", - "FixerIoApiKey": "ee23142f1120bb1223b0e76f98abfa97" + "FixerIoApiKey": "ee23142f1120bb1223b0e76f98abfa97", + "DefaultMandator": "Claudio Schaad" } }