Skip to content

Commit

Permalink
create tracker entry when creating upload
Browse files Browse the repository at this point in the history
  • Loading branch information
radek00 committed Feb 24, 2024
1 parent 363504f commit c3b9049
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ public sealed class CreateSecureUploadHandler: ICommandHandler<CreateSecureUploa
private readonly ISecureSendUploadFactory _secureSendUploadFactory;
private readonly ISecureUploadReadService _secureUploadReadService;
private readonly IOptions<FileStorageOptions> _fileStorageOptions;
private readonly IUploadSizeTrackerService _sizeTrackerService;

public CreateSecureUploadHandler(ISecureSendUploadRepository secureSendUploadRepository,
ISecureSendUploadFactory secureSendUploadFactory,
ISecureUploadReadService secureUploadReadService, IOptions<FileStorageOptions> fileStorageOptions)
ISecureUploadReadService secureUploadReadService, IOptions<FileStorageOptions> fileStorageOptions, IUploadSizeTrackerService sizeTrackerService)
{
_secureSendUploadRepository = secureSendUploadRepository;
_secureSendUploadFactory = secureSendUploadFactory;
_secureUploadReadService = secureUploadReadService;
_fileStorageOptions = fileStorageOptions;
_sizeTrackerService = sizeTrackerService;
}

public async Task<Unit> Handle (CreateSecureUpload command, CancellationToken cancellationToken)
Expand All @@ -38,6 +40,7 @@ public async Task<Unit> Handle (CreateSecureUpload command, CancellationToken ca
}
var persisted = await _secureUploadReadService.GetUploadId(command.uploadId, cancellationToken);
if (persisted is not null && persisted != Guid.Empty) throw new UploadAlreadyExistsException(persisted.Value);
_sizeTrackerService.TryUpdateUploadSize(command.uploadId, 0);
var secureUpload = _secureSendUploadFactory.CreateSecureSendUpload(command.uploadId, expiryDate, false, command.password);
await _secureSendUploadRepository.AddAsync(secureUpload, cancellationToken);
return Unit.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class CreateSecureUploadHandlerTests
private readonly Mock<ISecureUploadReadService> _secureUploadReadService;
private readonly ICommandHandler<CreateSecureUpload, Unit> _commandHandler;
private readonly Mock<IOptions<FileStorageOptions>> _fileStorageOptions;
private readonly Mock<IUploadSizeTrackerService> _sizeTrackerService;

private readonly FileStorageOptions _sampleOptions = new FileStorageOptions()
{
Expand All @@ -33,8 +34,9 @@ public CreateSecureUploadHandlerTests()
_secureSendUploadFactory = new Mock<ISecureSendUploadFactory>();
_secureUploadReadService = new Mock<ISecureUploadReadService>();
_fileStorageOptions = new Mock<IOptions<FileStorageOptions>>();
_sizeTrackerService = new Mock<IUploadSizeTrackerService>();
_commandHandler = new CreateSecureUploadHandler(_secureSendUploadRepository.Object, _secureSendUploadFactory.Object,
_secureUploadReadService.Object, _fileStorageOptions.Object);
_secureUploadReadService.Object, _fileStorageOptions.Object, _sizeTrackerService.Object);
}


Expand Down

0 comments on commit c3b9049

Please sign in to comment.