forked from ddrilling/AsbCloudServer
refact finally
This commit is contained in:
parent
ff72a0cb88
commit
5a6ad78c21
@ -28,9 +28,20 @@ namespace AsbCloudApp.Services
|
||||
/// <param name="plannedTrajectoryRows"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> AddAsync(int idWell, int idUser,
|
||||
Task<int> AddRangeAsync(int idWell, int idUser,
|
||||
IEnumerable<PlannedTrajectoryDto> plannedTrajectoryRows, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Добавить одну строку с координатами
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="idUser"></param>
|
||||
/// <param name="plannedTrajectoryRow"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> AddAsync(int idWell, int idUser,
|
||||
PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Обновить строку с координатами
|
||||
/// </summary>
|
||||
|
@ -22,22 +22,26 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
||||
this.db = db;
|
||||
this.wellService = wellService;
|
||||
}
|
||||
public async Task<int> AddAsync(int idWell, int idUser,IEnumerable<PlannedTrajectoryDto> plannedTrajectoryRows, CancellationToken token)
|
||||
public async Task<int> AddRangeAsync(int idWell, int idUser,IEnumerable<PlannedTrajectoryDto> plannedTrajectoryRows, CancellationToken token)
|
||||
{
|
||||
var timezone = wellService.GetTimezone(idWell);
|
||||
foreach (var dto in plannedTrajectoryRows)
|
||||
{
|
||||
var entity = dto.Adapt<AsbCloudDb.Model.PlannedTrajectory>();
|
||||
entity.IdWell = idWell;
|
||||
entity.Id = default;
|
||||
entity.UpdateDate = DateTime.Today.ToUtcDateTimeOffset(timezone.Hours);
|
||||
entity.IdUser = idUser;
|
||||
db.PlannedTrajectorys.Add(entity);
|
||||
}
|
||||
var entitys = plannedTrajectoryRows
|
||||
.Select(e => Convert(e, timezone, idWell, idUser));
|
||||
db.PlannedTrajectorys.AddRange(entitys);
|
||||
return await db.SaveChangesAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<int> AddAsync(int idWell, int idUser, PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token)
|
||||
{
|
||||
var timezone = wellService.GetTimezone(idWell);
|
||||
var entity = Convert(plannedTrajectoryRow, timezone, idWell, idUser);
|
||||
db.PlannedTrajectorys.Add(entity);
|
||||
return await db.SaveChangesAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
public async Task<int> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token)
|
||||
{
|
||||
var query = db.PlannedTrajectorys
|
||||
@ -92,7 +96,19 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
||||
{
|
||||
var dto = entity.Adapt<PlannedTrajectoryDto>();
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
||||
private static AsbCloudDb.Model.PlannedTrajectory Convert(PlannedTrajectoryDto dto, SimpleTimezoneDto timezone, int idWell, int idUser)
|
||||
{
|
||||
var entity = dto.Adapt<AsbCloudDb.Model.PlannedTrajectory>();
|
||||
entity.IdWell = idWell;
|
||||
entity.Id = default;
|
||||
entity.UpdateDate = DateTime.Today.ToUtcDateTimeOffset(timezone.Hours);
|
||||
entity.IdUser = idUser;
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -30,8 +30,6 @@ namespace AsbCloudWebApi.Controllers
|
||||
this.plannedTrajectoryService = plannedTrajectoryService;
|
||||
}
|
||||
|
||||
// ---------FROM FILE-----------
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает шаблон для заполнения строк плановой траектории
|
||||
/// </summary>
|
||||
@ -113,10 +111,6 @@ namespace AsbCloudWebApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------MANUAL---------------
|
||||
// !!! методы не реализованы в сервисе, в контроллере заглушка !!!
|
||||
|
||||
/// <summary>
|
||||
/// Получаем список всех строк координат плановой траектории (для клиента)
|
||||
/// </summary>
|
||||
@ -138,12 +132,12 @@ namespace AsbCloudWebApi.Controllers
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var result = plannedTrajectoryService.GetAsync(idWell,token);
|
||||
var result = plannedTrajectoryService.GetOrDefaultAsync(idWell,token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавить новые координаты для плановой траектории
|
||||
/// Добавить одну новую строчку координат для плановой траектории
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="row"></param>
|
||||
@ -157,7 +151,34 @@ namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
var result = row;
|
||||
int? idUser = User.GetUserId();
|
||||
if (!idUser.HasValue)
|
||||
return Forbid();
|
||||
var result = await plannedTrajectoryService.AddAsync(idWell, idUser.Value, row, token)
|
||||
.ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавить массив строчек координат для плановой траектории
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="rows"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Permission]
|
||||
[ProducesResponseType(typeof(PlannedTrajectoryDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> AddRowAsync(int idWell, [FromBody] IEnumerable<PlannedTrajectoryDto> rows,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
int? idUser = User.GetUserId();
|
||||
if (!idUser.HasValue)
|
||||
return Forbid();
|
||||
var result = await plannedTrajectoryService.AddRangeAsync(idWell, idUser.Value, rows, token)
|
||||
.ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user