diff --git a/EnvelopeGenerator.Application/Configuration/Queries/ReadDefaultConfigQuery.cs b/EnvelopeGenerator.Application/Configuration/Queries/ReadDefaultConfigQuery.cs new file mode 100644 index 00000000..808ba713 --- /dev/null +++ b/EnvelopeGenerator.Application/Configuration/Queries/ReadDefaultConfigQuery.cs @@ -0,0 +1,49 @@ +using AutoMapper; +using DigitalData.Core.Abstraction.Application.Repository; +using EnvelopeGenerator.Application.Common.Dto; +using EnvelopeGenerator.Domain.Entities; +using MediatR; +using Microsoft.EntityFrameworkCore; + +namespace EnvelopeGenerator.Application.Configuration.Queries; + +/// +/// +/// +public record ReadDefaultConfigQuery : IRequest +{ +} + +/// +/// +/// +public class ReadDefaultConfigQueryHandler : IRequestHandler +{ + private readonly IRepository _repo; + + private readonly IMapper _mapper; + + /// + /// + /// + /// + /// + public ReadDefaultConfigQueryHandler(IRepository repo, IMapper mapper) + { + _repo = repo; + _mapper = mapper; + } + + /// + /// + /// + /// + /// + /// + /// + public async Task Handle(ReadDefaultConfigQuery request, CancellationToken cancel) + { + var config = await _repo.Query.FirstOrDefaultAsync(cancel) ?? throw new InvalidOperationException("No configuration found."); + return _mapper.Map(config); + } +} \ No newline at end of file