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>
52 lines
1.7 KiB
C#
52 lines
1.7 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 BookingRuleRepository : BaseRepository, IBookingRuleRepository
|
|
{
|
|
private readonly string BOOKING_RULES = "BookingRules.json";
|
|
|
|
public BookingRuleRepository(ISettingsService settingsService, RepositoryCache cache, ILogger<BookingRuleRepository> logger)
|
|
: base(settingsService, cache, logger)
|
|
{
|
|
EnsureFileExists(BOOKING_RULES);
|
|
}
|
|
|
|
public Task<List<BookingRule>> GetBookingRuleListAsync() => LoadListAsync<BookingRule>(BOOKING_RULES);
|
|
|
|
public async Task SaveBookingRuleAsync(BookingRule bookingRule)
|
|
{
|
|
var bookingRules = await GetBookingRuleListAsync();
|
|
var idx = bookingRules.FindIndex(r => r.Id == bookingRule.Id);
|
|
if (idx >= 0)
|
|
{
|
|
bookingRules[idx] = bookingRule;
|
|
}
|
|
else
|
|
{
|
|
bookingRule.Id = Guid.NewGuid().ToString();
|
|
bookingRules.Add(bookingRule);
|
|
}
|
|
await SaveAsync(bookingRules, BOOKING_RULES);
|
|
}
|
|
|
|
public async Task<BookingRule> GetBookingRuleAsync(string id)
|
|
{
|
|
var bookingRules = await GetBookingRuleListAsync();
|
|
return bookingRules.FirstOrDefault(t => t.Id == id);
|
|
}
|
|
|
|
public async Task DeleteBookingRuleAsync(string id)
|
|
{
|
|
var bookingRules = await GetBookingRuleListAsync();
|
|
bookingRules.RemoveAll(t => t.Id == id);
|
|
await SaveAsync(bookingRules, BOOKING_RULES);
|
|
}
|
|
}
|
|
}
|