## Summary
All data folders are now migrated to JSON in the `{mandator}/{year}` layout, so the one-time migration from #2 is no longer needed.
- Remove `DataMigrator` and its 15 tests, its DI registration and the startup call in `Program.cs` (`Main` is back to a plain `app.Run()`).
- Remove the old-layout year-folder filter in `SettingsService.GetMandators` and the `DataFolders.IsYear` helper it used.
- Remove the migration notes from `CLAUDE.md` and code comments.
- Rename `.xml` paths to `.json` in a repository-cache test (cosmetic).
Bank-statement import (CAMT053 `.xml` in `StatementImport`) is unaffected.
**Note:** this version expects every data folder to be migrated already. An old-layout or XML data folder is no longer converted. The original XMLs remain in `backup/{mandator}/{year}/xml-<timestamp>/` and can be deleted manually.
## Test plan
- [x] `dotnet build --no-incremental`: no warnings
- [x] `dotnet test`: 62/62 pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reviewed-on: #3
Co-authored-by: Claudio Schaad <c.schaad@pog.ch>
Co-committed-by: Claudio Schaad <c.schaad@pog.ch>
111 lines
No EOL
3.1 KiB
C#
111 lines
No EOL
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Schaad.Accounting.Datasets;
|
|
using Schaad.Accounting.Interfaces;
|
|
|
|
namespace Schaad.Accounting.Services
|
|
{
|
|
public class SettingsService : ISettingsService
|
|
{
|
|
private readonly SettingsDataset settingsDataset;
|
|
private string mandator;
|
|
private int year = DateTime.Now.Year;
|
|
|
|
public SettingsService(SettingsDataset settingsDataset)
|
|
{
|
|
this.settingsDataset = settingsDataset;
|
|
this.mandator = settingsDataset.DefaultMandator;
|
|
}
|
|
|
|
public int GetYear()
|
|
{
|
|
return year;
|
|
}
|
|
|
|
public void SetYear(int year)
|
|
{
|
|
this.year = year;
|
|
}
|
|
|
|
public bool TrySetYear(int year)
|
|
{
|
|
var oldYear = this.year;
|
|
SetYear(year);
|
|
if (Directory.GetFiles(GetDbPath()).Any() == false)
|
|
{
|
|
SetYear(oldYear);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public string GetMandator()
|
|
{
|
|
return mandator;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Mandators that have a folder for the given year.
|
|
/// </summary>
|
|
public IReadOnlyList<string> GetMandators(int year)
|
|
{
|
|
var dataPath = GetSettings().DataPath;
|
|
if (Directory.Exists(dataPath) == false)
|
|
{
|
|
return [];
|
|
}
|
|
return Directory.GetDirectories(dataPath)
|
|
.Where(d => Directory.Exists(Path.Combine(d, year.ToString())))
|
|
.Select(Path.GetFileName)
|
|
.Where(name => !DataFolders.IsReserved(name))
|
|
.ToList();
|
|
}
|
|
|
|
public void SetMandator(string mandator)
|
|
{
|
|
this.mandator = mandator;
|
|
}
|
|
|
|
public string GetBackupFilePath()
|
|
{
|
|
var backupPath = EnsureDirectory(Path.Combine(GetSettings().DataPath, DataFolders.Backup, mandator, year.ToString()));
|
|
return Path.Combine(backupPath, DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip");
|
|
}
|
|
|
|
public string GetUploadPath()
|
|
{
|
|
return EnsureDirectory(Path.Combine(GetSettings().DataPath, DataFolders.Uploads, mandator, year.ToString()));
|
|
}
|
|
|
|
public string GetCreditCardStatementPath()
|
|
{
|
|
return EnsureDirectory(Path.Combine(GetUploadPath(), DataFolders.CreditCard));
|
|
}
|
|
|
|
public string GetDbPath()
|
|
{
|
|
return EnsureDirectory(Path.Combine(GetSettings().DataPath, mandator, year.ToString()));
|
|
}
|
|
|
|
public string GetLastYearDbPath()
|
|
{
|
|
return EnsureDirectory(Path.Combine(GetSettings().DataPath, mandator, (year - 1).ToString()));
|
|
}
|
|
|
|
public SettingsDataset GetSettings()
|
|
{
|
|
return settingsDataset;
|
|
}
|
|
|
|
private static string EnsureDirectory(string path)
|
|
{
|
|
if (Directory.Exists(path) == false)
|
|
{
|
|
Directory.CreateDirectory(path);
|
|
}
|
|
return path;
|
|
}
|
|
}
|
|
} |