Merged in feature/batch-status (pull request #215)

Implement and test the batch status feature

* working
This commit is contained in:
Jay Brown
2026-03-12 18:53:42 +00:00
parent 8a4029058b
commit aafe7d5b5f
39 changed files with 4252 additions and 516 deletions
+44 -16
View File
@@ -254,13 +254,13 @@ func (s *Controllers) UploadDocumentBatch(ctx echo.Context, clientId ClientID) e
return ctx.JSON(http.StatusAccepted, response)
}
// GetDocumentBatch returns batch upload status
// GetDocumentBatch returns batch upload status including per-file document outcomes.
func (s *Controllers) GetDocumentBatch(ctx echo.Context, clientId ClientID, batchId BatchID) error {
// BatchID is already a UUID type
batchUUID := uuid.UUID(batchId)
// Get batch details
batch, err := s.svc.DocumentBatch.Get(ctx.Request().Context(), clientId, batchUUID)
// Get batch details (includes document outcomes)
batchDetails, err := s.svc.DocumentBatch.Get(ctx.Request().Context(), clientId, batchUUID)
if err != nil {
slog.Error("unable to get batch", "error", err, "batchId", batchId)
return echo.NewHTTPError(http.StatusNotFound, "batch not found")
@@ -268,22 +268,50 @@ func (s *Controllers) GetDocumentBatch(ctx echo.Context, clientId ClientID, batc
// Convert to API response format
details := BatchUploadDetails{
BatchId: BatchID(batch.ID),
ClientId: ClientID(batch.ClientID),
OriginalFilename: batch.OriginalFilename,
Status: BatchStatus(batch.Status),
TotalDocuments: batch.TotalDocuments,
ProcessedDocuments: batch.ProcessedDocuments,
FailedDocuments: batch.FailedDocuments,
InvalidTypeDocuments: batch.InvalidTypeDocuments,
ProgressPercent: batch.ProgressPercent,
FailedFilenames: &batch.FailedFilenames,
CreatedAt: batch.CreatedAt,
BatchId: BatchID(batchDetails.ID),
ClientId: ClientID(batchDetails.ClientID),
OriginalFilename: batchDetails.OriginalFilename,
Status: BatchStatus(batchDetails.Status),
TotalDocuments: batchDetails.TotalDocuments,
ProcessedDocuments: batchDetails.ProcessedDocuments,
FailedDocuments: batchDetails.FailedDocuments,
InvalidTypeDocuments: batchDetails.InvalidTypeDocuments,
ProgressPercent: batchDetails.ProgressPercent,
FailedFilenames: &batchDetails.FailedFilenames,
CreatedAt: batchDetails.CreatedAt,
}
// Handle nullable completed at
if batch.CompletedAt != nil {
details.CompletedAt = nullable.NewNullableWithValue(*batch.CompletedAt)
if batchDetails.CompletedAt != nil {
details.CompletedAt = nullable.NewNullableWithValue(*batchDetails.CompletedAt)
}
// Map document outcomes to API response format
if len(batchDetails.DocumentOutcomes) > 0 {
outcomes := make([]BatchDocumentOutcome, len(batchDetails.DocumentOutcomes))
for i, o := range batchDetails.DocumentOutcomes {
outcome := BatchDocumentOutcome{
Filename: o.Filename,
Outcome: BatchDocumentOutcomeOutcome(o.Outcome),
CreatedAt: &o.CreatedAt,
UpdatedAt: &o.UpdatedAt,
}
if o.ErrorDetail != nil {
outcome.ErrorDetail = nullable.NewNullableWithValue(*o.ErrorDetail)
}
if o.DocumentID != nil {
outcome.DocumentId = nullable.NewNullableWithValue(openapi_types.UUID(*o.DocumentID))
}
if o.CleanFail != nil {
outcome.CleanFailReason = nullable.NewNullableWithValue(*o.CleanFail)
}
outcomes[i] = outcome
}
details.DocumentOutcomes = &outcomes
}
return ctx.JSON(http.StatusOK, details)