From 4c3f638bfba7e9255f94a75bc56dec390a72ad56 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Tue, 26 Dec 2023 14:03:31 +0500 Subject: [PATCH] Fix DetectedOperationExportService.ExportAsync exception type/text --- .../DetectedOperationExportService.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs index a94726c1..b70f8cd4 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs @@ -12,6 +12,7 @@ using AsbCloudApp.Data.DetectedOperation; using AsbCloudInfrastructure.Services.DetectOperations.Detectors; using AsbCloudApp.Repositories; using Microsoft.AspNetCore.Http.Extensions; +using AsbCloudApp.Exceptions; namespace AsbCloudInfrastructure.Services.DetectOperations; @@ -57,21 +58,21 @@ public class DetectedOperationExportService /// ั…ะพัั‚ /// /// - /// + /// public async Task ExportAsync(int idWell, string host, CancellationToken cancellationToken) { - var well = await dbContext.Wells + var well = await dbContext.Set() .Include(w => w.Cluster) .ThenInclude(c => c.Deposit) - .SingleOrDefaultAsync(w => w.Id == idWell, cancellationToken); + .FirstOrDefaultAsync(w => w.Id == idWell, cancellationToken); if (well is null) - throw new ArgumentNullException(nameof(well)); + throw new ArgumentInvalidException(nameof(idWell), $"Well {idWell} does not exist"); if (!well.IdTelemetry.HasValue) - throw new ArgumentNullException(nameof(well)); + throw new ArgumentInvalidException(nameof(idWell), $"Well {idWell} has no telemetry"); - var operations = await DetectOperationsAsync(well.IdTelemetry.Value, DateTime.UnixEpoch, cancellationToken); + var operations = await DetectOperationsAsync(well.IdTelemetry.Value, DateTime.UnixEpoch, cancellationToken); return await GenerateExcelFileStreamAsync(well, host, operations, cancellationToken); }