feat(envelope): Envelopes-Datenquelle und Initialisierung angepasst

- `EnvelopeTypeService` und `EnvelopeTypeController` hinzugefügt, um Envelope-Typen im Cache zu speichern und bereitzustellen.
- `ConfigurationService` erstellt und mit `APP_INITIALIZER` konfiguriert, um Envelope-Typen bei der Anwendungserstellung zu laden.
- `EnvelopeTableComponent` aktualisiert, um Envelope-Typen aus der Konfiguration zu verwenden, anstatt hartkodierte Werte zu nutzen.
This commit is contained in:
Developer 02
2024-09-02 14:48:20 +02:00
parent e9d686a4c1
commit 7444eeba2a
6 changed files with 122 additions and 6 deletions

View File

@@ -1,19 +1,31 @@
using AutoMapper;
using DigitalData.Core.Application;
using Microsoft.Extensions.Localization;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Infrastructure.Contracts;
using EnvelopeGenerator.Application.Resources;
using Microsoft.Extensions.Caching.Memory;
using DigitalData.Core.DTO;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
namespace EnvelopeGenerator.Application.Services
{
public class EnvelopeTypeService : BasicCRUDService<IEnvelopeTypeRepository, EnvelopeTypeDto, EnvelopeType, int>, IEnvelopeTypeService
{
public EnvelopeTypeService(IEnvelopeTypeRepository repository, IMapper mapper)
private static readonly Guid CacheKey = Guid.NewGuid();
private readonly IMemoryCache _cache;
public EnvelopeTypeService(IEnvelopeTypeRepository repository, IMapper mapper, IMemoryCache cache)
: base(repository, mapper)
{
_cache = cache;
}
public override async Task<DataResult<IEnumerable<EnvelopeTypeDto>>> ReadAllAsync()
=> await _cache.GetOrCreateAsync(CacheKey, async entry => await base.ReadAllAsync())
?? Result.Fail<IEnumerable<EnvelopeTypeDto>>().Notice(LogLevel.Error, Flag.NotFound, "No cached envelope types are available in the database. If you have added any envelope types after the server started, please restart the server.");
}
}