Repositories now read and write indented, human-readable JSON
(System.Text.Json, shared settings in JsonStorage). File names and folders
are unchanged apart from the extension.
XmlToJsonMigrator runs at startup before the app serves requests. It converts
the known Data/*.xml files under every year/mandator, verifies the JSON reads
back to the same data, and moves the XML to
{year}/backup/{mandator}/xml-{timestamp}/. Bank-statement XMLs in uploads/ are
never touched. Any failure stops startup and leaves that file's XML in place.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Logging;
|
|
using Schaad.Accounting.Interfaces;
|
|
using Schaad.Accounting.Models;
|
|
|
|
namespace Schaad.Accounting.Repositories
|
|
{
|
|
public class SplitPredefinitionRepository : BaseRepository, ISplitPredefinitionRepository
|
|
{
|
|
private readonly string SPLIT_PREDEFINITION = "SplitPredefinitions.json";
|
|
|
|
public SplitPredefinitionRepository(ISettingsService settingsService, RepositoryCache cache, ILogger<SplitPredefinitionRepository> logger)
|
|
: base(settingsService, cache, logger)
|
|
{
|
|
EnsureFileExists(SPLIT_PREDEFINITION);
|
|
}
|
|
|
|
public Task<List<SplitPredefinition>> GetSplitPredefinitionListAsync() => LoadListAsync<SplitPredefinition>(SPLIT_PREDEFINITION);
|
|
|
|
public async Task SaveSplitPredefinitionAsync(SplitPredefinition splitPredefinition)
|
|
{
|
|
var definitions = await GetSplitPredefinitionListAsync();
|
|
var idx = definitions.FindIndex(d => d.Id == splitPredefinition.Id);
|
|
if (idx >= 0)
|
|
{
|
|
definitions[idx] = splitPredefinition;
|
|
}
|
|
else
|
|
{
|
|
splitPredefinition.Id = Guid.NewGuid().ToString();
|
|
definitions.Add(splitPredefinition);
|
|
}
|
|
await SaveAsync(definitions, SPLIT_PREDEFINITION);
|
|
}
|
|
}
|
|
}
|