diff --git a/src/protagonist/API.Tests/Integration/CustomerQueueTests.cs b/src/protagonist/API.Tests/Integration/CustomerQueueTests.cs index c4d7577cf..b88d59b25 100644 --- a/src/protagonist/API.Tests/Integration/CustomerQueueTests.cs +++ b/src/protagonist/API.Tests/Integration/CustomerQueueTests.cs @@ -580,6 +580,7 @@ public async Task Post_CreateBatch_201_IfLegacyModeEnabled_MembersEmpty() var model = await response.ReadAsHydraResponseAsync(); var dbBatch = dbContext.Batches.Single(a => a.Id == model.Id.GetLastPathElementAsInt()); dbBatch.Count.Should().Be(0); + dbBatch.Finished.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromMinutes(1)); } [Fact] diff --git a/src/protagonist/API/Features/Queues/Requests/CreateEmptyBatch.cs b/src/protagonist/API/Features/Queues/Requests/CreateEmptyBatch.cs index bf66ff479..d7a57bd57 100644 --- a/src/protagonist/API/Features/Queues/Requests/CreateEmptyBatch.cs +++ b/src/protagonist/API/Features/Queues/Requests/CreateEmptyBatch.cs @@ -29,7 +29,8 @@ public CreateEmptyBatchHandler(IBatchRepository batchRepository) public async Task> Handle(CreateEmptyBatch request, CancellationToken cancellationToken) { - var batch = await batchRepository.CreateBatch(request.CustomerId, Array.Empty(), cancellationToken); + var batch = await batchRepository.CreateBatch(request.CustomerId, Array.Empty(), cancellationToken, + batch => batch.Finished = batch.Submitted); return ModifyEntityResult.Success(batch, WriteResult.Created); } } \ No newline at end of file diff --git a/src/protagonist/DLCS.Model/Assets/IBatchRepository.cs b/src/protagonist/DLCS.Model/Assets/IBatchRepository.cs index e64d80664..6570277f4 100644 --- a/src/protagonist/DLCS.Model/Assets/IBatchRepository.cs +++ b/src/protagonist/DLCS.Model/Assets/IBatchRepository.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -16,6 +17,8 @@ public interface IBatchRepository /// Id of customer to create batch for. /// /// Current cancellation token + /// Optional action, will be called after Batch is created but before saving in db /// Created Batch object - Task CreateBatch(int customerId, IReadOnlyList assets, CancellationToken cancellationToken = default); + Task CreateBatch(int customerId, IReadOnlyList assets, CancellationToken cancellationToken, + Action? postCreate = null); } \ No newline at end of file diff --git a/src/protagonist/DLCS.Repository/Assets/BatchRepository.cs b/src/protagonist/DLCS.Repository/Assets/BatchRepository.cs index ef5da4a78..35c326e34 100644 --- a/src/protagonist/DLCS.Repository/Assets/BatchRepository.cs +++ b/src/protagonist/DLCS.Repository/Assets/BatchRepository.cs @@ -20,7 +20,7 @@ public BatchRepository(DlcsContext dlcsContext) /// public async Task CreateBatch(int customerId, IReadOnlyList assets, - CancellationToken cancellationToken = default) + CancellationToken cancellationToken, Action? postCreate = null) { var batch = new Batch { @@ -31,6 +31,8 @@ public async Task CreateBatch(int customerId, IReadOnlyList assets Submitted = DateTime.UtcNow, Superseded = false }; + + postCreate?.Invoke(batch); DlcsContext.Batches.Add(batch); await DlcsContext.SaveChangesAsync(cancellationToken);