Jostka
This commit is contained in:
@@ -7,6 +7,7 @@ public interface IUnitOfWork
|
||||
public IProductRepository ProductRepository { get; }
|
||||
public ICategoryRepository CategoryRepository { get; }
|
||||
public IProductVariantRepository ProductVariantRepository { get; }
|
||||
public IUserRepository UserRepository { get; }
|
||||
|
||||
Task SaveAsync(CancellationToken cancellationToken = default);
|
||||
Task BeginTransactionAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
31
src/Imprink.Application/Users/SyncUserHandler.cs
Normal file
31
src/Imprink.Application/Users/SyncUserHandler.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Imprink.Domain.Common.Models;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Users;
|
||||
|
||||
public record SyncUserCommand(Auth0User User) : IRequest<bool>;
|
||||
|
||||
public class SyncUserHandler(IUnitOfWork uw): IRequestHandler<SyncUserCommand, bool>
|
||||
{
|
||||
public async Task<bool> Handle(SyncUserCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await uw.BeginTransactionAsync(cancellationToken);
|
||||
|
||||
try
|
||||
{
|
||||
if (!await uw.UserRepository.UpdateOrCreateUserAsync(request.User, cancellationToken))
|
||||
{
|
||||
await uw.RollbackTransactionAsync(cancellationToken);
|
||||
}
|
||||
|
||||
await uw.SaveAsync(cancellationToken);
|
||||
await uw.CommitTransactionAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
await uw.RollbackTransactionAsync(cancellationToken);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user