Developer 02 4615205aa5 refactor: Aktualisierung der Anwendungs- und Infrastrukturebenen, so dass die Infrastruktur von der Anwendung abhängig ist.
- Repository-Schnittstellen wurden in die Anwendungsschicht verschoben.
 - Erweiterungsmethoden für die Injektion von Repository-Abhängigkeiten wurden in die Infrastruktur verschoben.
2025-02-12 19:31:13 +01:00

51 lines
1.9 KiB
C#

using AutoMapper;
using DigitalData.Core.Application;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Application.DTOs.Receiver;
using DigitalData.Core.DTO;
using DigitalData.Core.Abstractions;
using Microsoft.Extensions.Logging;
using EnvelopeGenerator.Application.Contracts.Services;
namespace EnvelopeGenerator.Application.Services;
public class ReceiverService : CRUDService<IReceiverRepository, ReceiverCreateDto, ReceiverReadDto, ReceiverUpdateDto, Receiver, int>, IReceiverService
{
public ReceiverService(IReceiverRepository repository, IMapper mapper)
: base(repository, mapper)
{
}
public async Task<DataResult<ReceiverReadDto>> ReadByAsync(string? emailAddress = null, string? signature = null)
{
var rcv = await _repository.ReadByAsync(emailAddress: emailAddress, signature: signature);
if (rcv is null)
return Result.Fail<ReceiverReadDto>();
return Result.Success(_mapper.Map<ReceiverReadDto>(rcv));
}
public async Task<Result> DeleteByAsync(string? emailAddress = null, string? signature = null)
{
var rcv = await _repository.ReadByAsync(emailAddress: emailAddress, signature: signature);
if (rcv is null)
return Result.Fail();
return await _repository.DeleteAsync(rcv) ? Result.Success() : Result.Fail();
}
public virtual async Task<Result> UpdateAsync<TUpdateDto>(TUpdateDto updateDto) where TUpdateDto : IUnique<int>
{
var val = await _repository.ReadByIdAsync(updateDto.Id);
if (val == null)
{
return Result.Fail().Notice(LogLevel.Warning, Flag.NotFound, $"{updateDto.Id} is not found in update process of {GetType()} entity.");
}
var entity = _mapper.Map(updateDto, val);
return (await _repository.UpdateAsync(entity)) ? Result.Success() : Result.Fail();
}
}