update to create key by EncodeEnvelopeReceiverId

This commit is contained in:
2025-09-01 15:42:33 +02:00
parent 87c5e7e4de
commit 20d312a84e
3 changed files with 46 additions and 30 deletions

View File

@@ -1,4 +1,6 @@
using DigitalData.Core.Abstraction.Application.Repository;
using AutoMapper;
using DigitalData.Core.Abstraction.Application.Repository;
using EnvelopeGenerator.Application.Dto.Receiver;
using EnvelopeGenerator.Domain.Entities;
using MediatR;
using Microsoft.AspNetCore.Mvc;
@@ -13,7 +15,7 @@ namespace EnvelopeGenerator.Application.Receivers.Commands;
///
/// </summary>
[ApiExplorerSettings(IgnoreApi = true)]
public record CreateReceiverCommand : IRequest<(int Id, bool AlreadyExists)>
public record CreateReceiverCommand : IRequest<(ReceiverReadDto Receiver, bool AlreadyExists)>
{
/// <summary>
///
@@ -52,20 +54,23 @@ public record CreateReceiverCommand : IRequest<(int Id, bool AlreadyExists)>
/// <summary>
///
/// </summary>
public class CreateReceiverCommandHandler : IRequestHandler<CreateReceiverCommand, (int Id, bool AlreadyExists)>
public class CreateReceiverCommandHandler : IRequestHandler<CreateReceiverCommand, (ReceiverReadDto Receiver, bool AlreadyExists)>
{
/// <summary>
///
/// </summary>
private readonly IRepository<Receiver> _repo;
private readonly IMapper _mapper;
/// <summary>
///
/// </summary>
/// <param name="repo"></param>
public CreateReceiverCommandHandler(IRepository<Receiver> repo)
public CreateReceiverCommandHandler(IRepository<Receiver> repo, IMapper mapper)
{
_repo = repo;
_mapper = mapper;
}
/// <summary>
@@ -74,7 +79,7 @@ public class CreateReceiverCommandHandler : IRequestHandler<CreateReceiverComman
/// <param name="request"></param>
/// <param name="cancel"></param>
/// <returns></returns>
public async Task<(int Id, bool AlreadyExists)> Handle(CreateReceiverCommand request, CancellationToken cancel)
public async Task<(ReceiverReadDto Receiver, bool AlreadyExists)> Handle(CreateReceiverCommand request, CancellationToken cancel)
{
var receiver = await _repo.ReadOnly()
.Where(r => r.EmailAddress == request.EmailAddress)
@@ -85,6 +90,7 @@ public class CreateReceiverCommandHandler : IRequestHandler<CreateReceiverComman
if (!alreadyExists)
receiver = await _repo.CreateAsync(request, cancel);
return (receiver!.Id, alreadyExists);
var receiverDto = _mapper.Map<ReceiverReadDto>(receiver);
return (receiverDto, alreadyExists);
}
}