nit DailyReportService fix nullable warnings

This commit is contained in:
ngfrolov 2022-11-17 17:36:35 +05:00
parent 1c4a2f7922
commit 034ed80363

View File

@ -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<DailyReportDto> 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<Stream?> 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<DailyReportDto?> GetAsync(int idWell, DateTime date, CancellationToken token)
private async Task<DailyReportDto?> GetOrDefaultAsync(int idWell, DateTime date, CancellationToken token)
{
var dateOffset = date.Date;
var entity = await db.DailyReports