Skip to content

Commit ee7a489

Browse files
authored
Merge pull request #33 from DEFRA/develop
Develop 2 main
2 parents 046a198 + 456333f commit ee7a489

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

src/KeeperData.Bridge/Controllers/ImportController.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,71 @@ public async Task<IActionResult> StartBulkImport([FromQuery] string sourceType =
7171
}
7272
}
7373

74+
/// <summary>
75+
/// Gets a paginated list of import summaries in reverse chronological order (most recent first).
76+
/// Returns summary information including status, file counts, and record statistics for each import.
77+
/// </summary>
78+
/// <param name="skip">Number of records to skip for pagination (default: 0)</param>
79+
/// <param name="top">Number of records to return (default: 10, max: 100)</param>
80+
/// <param name="cancellationToken">Cancellation token</param>
81+
/// <returns>Paginated list of import summaries</returns>
82+
[HttpGet]
83+
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
84+
[ProducesResponseType(StatusCodes.Status400BadRequest)]
85+
public async Task<IActionResult> GetImportSummaries(
86+
[FromQuery] int skip = 0,
87+
[FromQuery] int top = 10,
88+
CancellationToken cancellationToken = default)
89+
{
90+
logger.LogInformation("Received request to get import summaries with skip={skip}, top={top}", skip, top);
91+
92+
// Validate parameters
93+
if (skip < 0)
94+
{
95+
logger.LogWarning("Invalid skip parameter: {skip}", skip);
96+
return BadRequest(new
97+
{
98+
Message = "Skip parameter must be greater than or equal to 0.",
99+
Timestamp = DateTime.UtcNow
100+
});
101+
}
102+
103+
if (top <= 0 || top > 100)
104+
{
105+
logger.LogWarning("Invalid top parameter: {top}", top);
106+
return BadRequest(new
107+
{
108+
Message = "Top parameter must be between 1 and 100.",
109+
Timestamp = DateTime.UtcNow
110+
});
111+
}
112+
113+
try
114+
{
115+
var summaries = await importReportingService.GetImportSummariesAsync(skip, top, cancellationToken);
116+
117+
logger.LogInformation("Successfully retrieved {count} import summaries", summaries.Count);
118+
119+
return Ok(new
120+
{
121+
Skip = skip,
122+
Top = top,
123+
Count = summaries.Count,
124+
Imports = summaries,
125+
Timestamp = DateTime.UtcNow
126+
});
127+
}
128+
catch (OperationCanceledException)
129+
{
130+
logger.LogWarning("Get import summaries request was cancelled");
131+
return StatusCode(499, new
132+
{
133+
Message = "Request was cancelled.",
134+
Timestamp = DateTime.UtcNow
135+
});
136+
}
137+
}
138+
74139
/// <summary>
75140
/// Gets the import report for a specific import ID.
76141
/// Includes overall import status, acquisition phase details, and ingestion phase details.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace KeeperData.Core.Reporting.Dtos;
2+
3+
public record ImportSummary
4+
{
5+
public required Guid ImportId { get; init; }
6+
public required ImportStatus Status { get; init; }
7+
public DateTime StartedAtUtc { get; init; }
8+
public DateTime? CompletedAtUtc { get; init; }
9+
public int FilesProcessed { get; init; }
10+
public int RecordsCreated { get; init; }
11+
public int RecordsUpdated { get; init; }
12+
public int RecordsDeleted { get; init; }
13+
}

src/KeeperData.Core/Reporting/IImportReportingService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ public interface IImportReportingService
2424
Task<IReadOnlyList<FileProcessingReport>> GetFileReportsAsync(Guid importId, CancellationToken ct);
2525
Task<RecordLifecycle?> GetRecordLifecycleAsync(string collectionName, string recordId, CancellationToken ct);
2626
Task<IReadOnlyList<RecordLineageEvent>> GetRecordLineageAsync(string collectionName, string recordId, CancellationToken ct);
27+
Task<IReadOnlyList<ImportSummary>> GetImportSummariesAsync(int skip = 0, int top = 10, CancellationToken ct = default);
2728
}

src/KeeperData.Core/Reporting/Impl/ImportReportingService.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,20 @@ public async Task<IReadOnlyList<RecordLineageEvent>> GetRecordLineageAsync(strin
309309
return lifecycle?.Events ?? Array.Empty<RecordLineageEvent>();
310310
}
311311

312+
public async Task<IReadOnlyList<ImportSummary>> GetImportSummariesAsync(int skip = 0, int top = 10, CancellationToken ct = default)
313+
{
314+
_logger.LogDebug("Getting import summaries with skip: {Skip}, top: {Top}", skip, top);
315+
316+
var documents = await _importReports
317+
.Find(Builders<ImportReportDocument>.Filter.Empty)
318+
.SortByDescending(x => x.StartedAtUtc)
319+
.Skip(skip)
320+
.Limit(top)
321+
.ToListAsync(ct);
322+
323+
return documents.Select(MapToImportSummary).ToList();
324+
}
325+
312326
private static ImportReport MapToImportReport(ImportReportDocument doc)
313327
{
314328
return new ImportReport
@@ -396,4 +410,19 @@ private static RecordLifecycle MapToRecordLifecycle(RecordLineageDocument doc)
396410
}).ToList()
397411
};
398412
}
413+
414+
private static ImportSummary MapToImportSummary(ImportReportDocument doc)
415+
{
416+
return new ImportSummary
417+
{
418+
ImportId = doc.ImportId,
419+
Status = Enum.Parse<ImportStatus>(doc.Status),
420+
StartedAtUtc = doc.StartedAtUtc,
421+
CompletedAtUtc = doc.CompletedAtUtc,
422+
FilesProcessed = doc.IngestionPhase?.FilesProcessed ?? 0,
423+
RecordsCreated = doc.IngestionPhase?.RecordsCreated ?? 0,
424+
RecordsUpdated = doc.IngestionPhase?.RecordsUpdated ?? 0,
425+
RecordsDeleted = doc.IngestionPhase?.RecordsDeleted ?? 0
426+
};
427+
}
399428
}

0 commit comments

Comments
 (0)