Правка по результатам ревью - 2

This commit is contained in:
Olga Nemt 2023-10-23 15:54:29 +05:00
parent fee782f08f
commit 01765d05ec
5 changed files with 22 additions and 14 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace AsbCloudApp.Exceptions
{
@ -10,7 +11,7 @@ namespace AsbCloudApp.Exceptions
/// <summary>
/// название аргумента
/// </summary>
public string[] ParamsNames { get; } = null!;
public IDictionary<string, string[]> ParamsNames { get; } = null!;
/// <summary>
/// конструктор
@ -20,7 +21,9 @@ namespace AsbCloudApp.Exceptions
public ArgumentInvalidException(string paramName, string message)
: base(message)
{
ParamsNames = new string[1] { paramName };
ParamsNames = new Dictionary<string, string[]>() {
{ paramName, new[]{ message } }
};
}
/// <summary>
@ -31,7 +34,9 @@ namespace AsbCloudApp.Exceptions
public ArgumentInvalidException(string[] paramsNames, string message)
: base(message)
{
ParamsNames = paramsNames;
ParamsNames = new Dictionary<string, string[]>() {
{ string.Join(", ", paramsNames), new[]{ message } }
};
}
}
}

View File

@ -2,7 +2,6 @@
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Mapster;
using Microsoft.EntityFrameworkCore;
@ -27,6 +26,7 @@ namespace AsbCloudInfrastructure.Repository
{
var query = db.DrillTests
.Where(d => d.IdTelemetry == idTelemetry)
.Include(d => d.Telemetry)
.AsNoTracking();
if (request.GeDate.HasValue)
@ -41,7 +41,7 @@ namespace AsbCloudInfrastructure.Repository
}
var entities = await query.ToListAsync(cancellationToken);
var dtos = entities.Select(e => e.Adapt<DrillTestDto>());
var dtos = entities.Select(e => Convert(e));
return dtos;
}
@ -58,8 +58,7 @@ namespace AsbCloudInfrastructure.Repository
if (drillTest is null)
throw new ArgumentInvalidException(new string[] { nameof(id), nameof(idTelemetry) }, $"Drill test with id: {id} and idTelemetry: {idTelemetry} does not exist.");
var dto = drillTest.Adapt<DrillTestDto>();
dto.TimeStampStart = dto.TimeStampStart.ToRemoteDateTime(dto.Telemetry?.TimeZone?.Hours ?? 0);
var dto = Convert(drillTest);
return dto;
}
@ -72,5 +71,12 @@ namespace AsbCloudInfrastructure.Repository
var result = await db.SaveChangesAsync(token);
return result;
}
private DrillTestDto Convert(DrillTest entity)
{
var dto = entity.Adapt<DrillTestDto>();
dto.TimeStampStart = dto.TimeStampStart.ToRemoteDateTime(dto.Telemetry?.TimeZone?.Hours ?? 0);
return dto;
}
}
}

View File

@ -82,11 +82,11 @@ namespace AsbCloudInfrastructure.Services.DrillTestReport
reports.Add(new DrillTestReportInfoDto
{
FileName = string.Format("Drill_test_{0}", remoteDateTime),
FileName = string.Format("Drill_test_{0}", dto.TimeStampStart.DateTime),
DrillDepth = (dto.Params
.Where(p => p.DepthDrillStep.HasValue)
.Sum(x => x.DepthDrillStep) ?? 0) + dto.DepthStart,
DateTime = remoteDateTime,
DateTime = dto.TimeStampStart.DateTime,
Id = dto.Id,
});
}

View File

@ -56,10 +56,7 @@ namespace AsbCloudWebApi.Middlewares
private static string MakeJsonBody(ArgumentInvalidException ex)
{
var errors = new Dictionary<string, string[]>() {
{ string.Join(", ", ex.ParamsNames), new[]{ ex.Message } }
};
var problem = new ValidationProblemDetails(errors);
var problem = new ValidationProblemDetails(ex.ParamsNames);
var buffer = System.Text.Json.JsonSerializer.Serialize(problem);
return buffer;
}

View File

@ -13,7 +13,7 @@ Content-Type: {{contentType}}
accept: */*
{
"id": @id,
"id": {{id}},
"timeStampStart": "2023-10-23T08:55:36.882Z",
"depthStart": 10,
"params": [