From 034ed80363d7f0a6ad629d444ede939086baa160 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Thu, 17 Nov 2022 17:36:35 +0500 Subject: [PATCH] nit DailyReportService fix nullable warnings --- .../Services/DailyReport/DailyReportService.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs index 1ba5b36d..67e66eb5 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs @@ -12,6 +12,7 @@ using AsbCloudApp.Data.DailyReport; using AsbCloudApp.Requests; using AsbCloudInfrastructure.Services.DetectOperations; using AsbCloudApp.Data.DetectedOperation; +using AsbCloudApp.Exceptions; namespace AsbCloudInfrastructure.Services.DailyReport { @@ -34,7 +35,8 @@ namespace AsbCloudInfrastructure.Services.DailyReport { var well = wellService.GetOrDefault(idWell); if (well is null || well.Timezone is null) - return null; + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); + var query = db.DailyReports.Where(r => r.IdWell == idWell); DateTimeOffset ExtractDate(DateTime dateTime) @@ -65,9 +67,8 @@ namespace AsbCloudInfrastructure.Services.DailyReport public async Task GetOrGenerateAsync(int idWell, DateTime date, CancellationToken token) { var dateOnly = DateTime.SpecifyKind(date.Date, DateTimeKind.Utc); - var dailyReportDto = await GetAsync(idWell, dateOnly, token); - if (dailyReportDto is null) - dailyReportDto = await MakeDefaultDailyReportAsync(idWell, dateOnly, token); + var dailyReportDto = await GetOrDefaultAsync(idWell, dateOnly, token); + dailyReportDto ??= await MakeDefaultDailyReportAsync(idWell, dateOnly, token); return dailyReportDto; } @@ -105,7 +106,7 @@ namespace AsbCloudInfrastructure.Services.DailyReport public async Task MakeReportAsync(int idWell, DateTime date, CancellationToken token = default) { - var dailyReportDto = await GetAsync(idWell, date, token); + var dailyReportDto = await GetOrDefaultAsync(idWell, date, token); if (dailyReportDto is null) return null; @@ -113,7 +114,7 @@ namespace AsbCloudInfrastructure.Services.DailyReport return memoryStream; } - private async Task GetAsync(int idWell, DateTime date, CancellationToken token) + private async Task GetOrDefaultAsync(int idWell, DateTime date, CancellationToken token) { var dateOffset = date.Date; var entity = await db.DailyReports