Правка по результатам ревью - 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;
using System.Collections.Generic;
namespace AsbCloudApp.Exceptions namespace AsbCloudApp.Exceptions
{ {
@ -10,7 +11,7 @@ namespace AsbCloudApp.Exceptions
/// <summary> /// <summary>
/// название аргумента /// название аргумента
/// </summary> /// </summary>
public string[] ParamsNames { get; } = null!; public IDictionary<string, string[]> ParamsNames { get; } = null!;
/// <summary> /// <summary>
/// конструктор /// конструктор
@ -20,7 +21,9 @@ namespace AsbCloudApp.Exceptions
public ArgumentInvalidException(string paramName, string message) public ArgumentInvalidException(string paramName, string message)
: base(message) : base(message)
{ {
ParamsNames = new string[1] { paramName }; ParamsNames = new Dictionary<string, string[]>() {
{ paramName, new[]{ message } }
};
} }
/// <summary> /// <summary>
@ -31,7 +34,9 @@ namespace AsbCloudApp.Exceptions
public ArgumentInvalidException(string[] paramsNames, string message) public ArgumentInvalidException(string[] paramsNames, string message)
: base(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.Exceptions;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using Mapster; using Mapster;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@ -27,6 +26,7 @@ namespace AsbCloudInfrastructure.Repository
{ {
var query = db.DrillTests var query = db.DrillTests
.Where(d => d.IdTelemetry == idTelemetry) .Where(d => d.IdTelemetry == idTelemetry)
.Include(d => d.Telemetry)
.AsNoTracking(); .AsNoTracking();
if (request.GeDate.HasValue) if (request.GeDate.HasValue)
@ -41,7 +41,7 @@ namespace AsbCloudInfrastructure.Repository
} }
var entities = await query.ToListAsync(cancellationToken); var entities = await query.ToListAsync(cancellationToken);
var dtos = entities.Select(e => e.Adapt<DrillTestDto>()); var dtos = entities.Select(e => Convert(e));
return dtos; return dtos;
} }
@ -58,8 +58,7 @@ namespace AsbCloudInfrastructure.Repository
if (drillTest is null) if (drillTest is null)
throw new ArgumentInvalidException(new string[] { nameof(id), nameof(idTelemetry) }, $"Drill test with id: {id} and idTelemetry: {idTelemetry} does not exist."); 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>(); var dto = Convert(drillTest);
dto.TimeStampStart = dto.TimeStampStart.ToRemoteDateTime(dto.Telemetry?.TimeZone?.Hours ?? 0);
return dto; return dto;
} }
@ -72,5 +71,12 @@ namespace AsbCloudInfrastructure.Repository
var result = await db.SaveChangesAsync(token); var result = await db.SaveChangesAsync(token);
return result; 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 reports.Add(new DrillTestReportInfoDto
{ {
FileName = string.Format("Drill_test_{0}", remoteDateTime), FileName = string.Format("Drill_test_{0}", dto.TimeStampStart.DateTime),
DrillDepth = (dto.Params DrillDepth = (dto.Params
.Where(p => p.DepthDrillStep.HasValue) .Where(p => p.DepthDrillStep.HasValue)
.Sum(x => x.DepthDrillStep) ?? 0) + dto.DepthStart, .Sum(x => x.DepthDrillStep) ?? 0) + dto.DepthStart,
DateTime = remoteDateTime, DateTime = dto.TimeStampStart.DateTime,
Id = dto.Id, Id = dto.Id,
}); });
} }

View File

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

View File

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