IWellOperationService/Controller replace arguments by request class

This commit is contained in:
ngfrolov 2022-12-21 18:02:22 +05:00
parent 1afbafdf81
commit 7b0e6ce23d
5 changed files with 186 additions and 199 deletions

View File

@ -2,6 +2,7 @@
namespace AsbCloudApp.Requests namespace AsbCloudApp.Requests
{ {
#nullable enable
/// <summary> /// <summary>
/// Базовые параметры запроса /// Базовые параметры запроса
/// </summary> /// </summary>
@ -22,6 +23,7 @@ namespace AsbCloudApp.Requests
/// Содержат список названий полей сортировки /// Содержат список названий полей сортировки
/// Указать направление сортировки можно через пробел "asc" или "desc" /// Указать направление сортировки можно через пробел "asc" или "desc"
/// </summary> /// </summary>
public IEnumerable<string> SortFields { get; set; } public IEnumerable<string>? SortFields { get; set; }
} }
#nullable disable
} }

View File

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
namespace AsbCloudApp.Requests
{
#nullable enable
/// <summary>
/// параметры для запроса списка операций
/// </summary>
public class WellOperationRequestBase: RequestBase
{
/// <summary>
/// фильтр по дате начала операции
/// </summary>
public DateTime? GeDate { get; set; }
/// <summary>
/// фильтр по дате окончания операции
/// </summary>
public DateTime? LeDate { get; set; }
/// <summary>
/// фильтр по максимальной глубине скважины
/// </summary>
public double? LeDepth { get; set; }
/// <summary>
/// фильтр по минимальной глубине скважины
/// </summary>
public double? GeDepth { get; set; }
/// <summary>
/// фильтр по списку id категорий операции
/// </summary>
public IEnumerable<int>? OperationCategoryIds { get; set; }
/// <summary>
/// фильтр по план = 0, факт = 1
/// </summary>
public int? OperationType { get; set; }
/// <summary>
/// фильтр по списку id конструкций секции
/// </summary>
public IEnumerable<int>? SectionTypeIds { get; set; }
}
/// <summary>
/// Параметры для запроса списка операций (с id скважины)
/// </summary>
public class WellOperationRequest: WellOperationRequestBase
{
/// <summary>
/// id скважины
/// </summary>
public int IdWell { get; set; }
/// <summary>
/// ctor
/// </summary>
public WellOperationRequest(){}
/// <summary>
/// копирующий конструктор
/// </summary>
/// <param name="request"></param>
/// <param name="idWell"></param>
public WellOperationRequest(WellOperationRequestBase request, int idWell)
{
this.IdWell = idWell;
this.GeDepth = request.GeDepth;
this.LeDepth = request.LeDepth;
this.GeDate = request.GeDate;
this.LeDate = request.LeDate;
this.OperationCategoryIds = request.OperationCategoryIds;
this.OperationType = request.OperationType;
this.SectionTypeIds = request.SectionTypeIds;
this.Skip= request.Skip;
this.Take= request.Take;
this.SortFields = request.SortFields;
}
}
#nullable disable
}

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Requests;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
@ -6,6 +7,7 @@ using System.Threading.Tasks;
namespace AsbCloudApp.Services namespace AsbCloudApp.Services
{ {
#nullable enable
/// <summary> /// <summary>
/// сервис операций по скважине /// сервис операций по скважине
/// </summary> /// </summary>
@ -21,53 +23,21 @@ namespace AsbCloudApp.Services
/// <summary> /// <summary>
/// Получить список операций /// Получить список операций
/// </summary> /// </summary>
/// <param name="idWell"></param> /// <param name="request"></param>
/// <param name="operationType"></param>
/// <param name="sectionTypeIds"></param>
/// <param name="operationCategoryIds"></param>
/// <param name="begin"></param>
/// <param name="end"></param>
/// <param name="minDepth"></param>
/// <param name="maxDepth"></param>
/// <param name="skip"></param>
/// <param name="take"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<PaginationContainer<WellOperationDto>> GetOperationsAsync( Task<PaginationContainer<WellOperationDto>> GetOperationsAsync(
int idWell, WellOperationRequest request,
int? operationType = null,
IEnumerable<int> sectionTypeIds = null,
IEnumerable<int> operationCategoryIds = null,
DateTime begin = default,
DateTime end = default,
double minDepth = double.MinValue,
double maxDepth = double.MaxValue,
int skip = 0,
int take = 32,
CancellationToken token = default); CancellationToken token = default);
/// <summary> /// <summary>
/// Получить статистику операции по скважине с группировкой по категориям /// Получить статистику операции по скважине с группировкой по категориям
/// </summary> /// </summary>
/// <param name="idWell"></param> /// <param name="request"></param>
/// <param name="operationType"></param>
/// <param name="sectionTypeIds"></param>
/// <param name="operationCategoryIds"></param>
/// <param name="begin"></param>
/// <param name="end"></param>
/// <param name="minDepth"></param>
/// <param name="maxDepth"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync( Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(
int idWell, WellOperationRequest request,
int? operationType = null,
IEnumerable<int> sectionTypeIds = null,
IEnumerable<int> operationCategoryIds = null,
DateTime begin = default,
DateTime end = default,
double minDepth = double.MinValue,
double maxDepth = double.MaxValue,
CancellationToken token = default); CancellationToken token = default);
/// <summary> /// <summary>
@ -78,27 +48,22 @@ namespace AsbCloudApp.Services
/// <returns></returns> /// <returns></returns>
Task<WellOperationDto> GetOrDefaultAsync(int id, CancellationToken token); Task<WellOperationDto> GetOrDefaultAsync(int id, CancellationToken token);
//todo: idWell Не нужен
/// <summary> /// <summary>
/// Добавить несколько операций за один раз /// Добавить несколько операций за один раз
/// </summary> /// </summary>
/// <param name="idWell"></param>
/// <param name="wellOperationDtos"></param> /// <param name="wellOperationDtos"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<int> InsertRangeAsync(int idWell, Task<int> InsertRangeAsync(
IEnumerable<WellOperationDto> wellOperationDtos, CancellationToken token); IEnumerable<WellOperationDto> wellOperationDtos, CancellationToken token);
//todo: id Не нужны
/// <summary> /// <summary>
/// Обновить существующую операцию /// Обновить существующую операцию
/// </summary> /// </summary>
/// <param name="idWell"></param>
/// <param name="idOperation"></param>
/// <param name="item"></param> /// <param name="item"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<int> UpdateAsync(int idWell, int idOperation, WellOperationDto item, Task<int> UpdateAsync(WellOperationDto item,
CancellationToken token); CancellationToken token);
/// <summary> /// <summary>
@ -122,4 +87,5 @@ namespace AsbCloudApp.Services
/// <returns></returns> /// <returns></returns>
DateTimeOffset? FirstOperationDate(int idWell); DateTimeOffset? FirstOperationDate(int idWell);
} }
#nullable disable
} }

View File

@ -1,5 +1,7 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudDb;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using Mapster; using Mapster;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@ -75,47 +77,24 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
} }
public async Task<PaginationContainer<WellOperationDto>> GetOperationsAsync( public async Task<PaginationContainer<WellOperationDto>> GetOperationsAsync(
int idWell, WellOperationRequest request,
int? operationType = default,
IEnumerable<int>? sectionTypeIds = null,
IEnumerable<int>? operationCategoryIds = null,
DateTime begin = default,
DateTime end = default,
double minDepth = double.MinValue,
double maxDepth = double.MaxValue,
int skip = 0,
int take = 32,
CancellationToken token = default) CancellationToken token = default)
{ {
var timezone = wellService.GetTimezone(idWell); var timezone = wellService.GetTimezone(request.IdWell);
var query = BuildQuery( var query = BuildQuery(request);
idWell,
operationType,
sectionTypeIds,
operationCategoryIds,
begin,
end,
minDepth,
maxDepth,
token);
var result = new PaginationContainer<WellOperationDto> var result = new PaginationContainer<WellOperationDto>
{ {
Skip = skip, Skip = request.Skip ?? 0,
Take = take, Take = request.Take ?? 32,
Count = await query.CountAsync(token).ConfigureAwait(false), Count = await query.CountAsync(token).ConfigureAwait(false),
}; };
query = query
.OrderBy(e => e.DateStart)
.ThenBy(e => e.DepthEnd)
.ThenBy(e => e.Id);
if (skip > 0) if (result.Skip > 0)
query = query.Skip(skip); query = query.Skip(result.Skip!);
var entities = await query.Take(take).AsNoTracking() var entities = await query.Take(result.Take).AsNoTracking()
.ToListAsync(token).ConfigureAwait(false); .ToListAsync(token).ConfigureAwait(false);
if (!entities.Any()) if (!entities.Any())
@ -144,26 +123,10 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
} }
public async Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync( public async Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(
int idWell, WellOperationRequest request,
int? operationType = default,
IEnumerable<int>? sectionTypeIds = default,
IEnumerable<int>? operationCategoryIds = default,
DateTime begin = default,
DateTime end = default,
double minDepth = double.MinValue,
double maxDepth = double.MaxValue,
CancellationToken token = default) CancellationToken token = default)
{ {
var query = BuildQuery( var query = BuildQuery(request);
idWell,
operationType,
sectionTypeIds,
operationCategoryIds,
begin,
end,
minDepth,
maxDepth,
token);
var entities = await query var entities = await query
.Select(o => new { .Select(o => new {
o.IdCategory, o.IdCategory,
@ -172,11 +135,12 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
}) })
.ToListAsync(token); .ToListAsync(token);
var parentRelationDictionary = GetCategories() var parentRelationDictionary = GetCategories()
.ToDictionary(c => c.Id, cc => new .ToDictionary(c => c.Id, c => new
{ {
Name = cc.Name, c.Name,
IdParent = cc.IdParent c.IdParent
}); });
var dtos = entities var dtos = entities
.GroupBy(o => o.IdCategory) .GroupBy(o => o.IdCategory)
.Select(g => new WellGroupOpertionDto .Select(g => new WellGroupOpertionDto
@ -206,7 +170,6 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
TotalMinutes = g.Sum(o => o.TotalMinutes), TotalMinutes = g.Sum(o => o.TotalMinutes),
Items = g.ToList(), Items = g.ToList(),
IdParent = g.Key.HasValue ? parentRelationDictionary[g.Key.Value].IdParent : defaultId, IdParent = g.Key.HasValue ? parentRelationDictionary[g.Key.Value].IdParent : defaultId,
}); });
} }
return dtos; return dtos;
@ -215,7 +178,6 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
public async Task<WellOperationDto?> GetOrDefaultAsync(int id, public async Task<WellOperationDto?> GetOrDefaultAsync(int id,
CancellationToken token = default) CancellationToken token = default)
{ {
var entity = await db.WellOperations var entity = await db.WellOperations
.Include(s => s.WellSectionType) .Include(s => s.WellSectionType)
.Include(s => s.OperationCategory) .Include(s => s.OperationCategory)
@ -234,10 +196,17 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
return dto; return dto;
} }
public async Task<int> InsertRangeAsync(int idWell, public async Task<int> InsertRangeAsync(
IEnumerable<WellOperationDto> wellOperationDtos, IEnumerable<WellOperationDto> wellOperationDtos,
CancellationToken token = default) CancellationToken token = default)
{ {
var firstOperation = wellOperationDtos
.FirstOrDefault();
if (firstOperation is null)
return 0;
var idWell = firstOperation.IdWell;
var timezone = wellService.GetTimezone(idWell); var timezone = wellService.GetTimezone(idWell);
foreach (var dto in wellOperationDtos) foreach (var dto in wellOperationDtos)
{ {
@ -252,12 +221,11 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
.ConfigureAwait(false); .ConfigureAwait(false);
} }
public async Task<int> UpdateAsync(int idWell, int idOperation, public async Task<int> UpdateAsync(
WellOperationDto dto, CancellationToken token = default) WellOperationDto dto, CancellationToken token = default)
{ {
var timezone = wellService.GetTimezone(idWell); var timezone = wellService.GetTimezone(dto.IdWell);
var entity = dto.Adapt<WellOperation>(); var entity = dto.Adapt<WellOperation>();
entity.Id = idOperation;
entity.DateStart = dto.DateStart.ToUtcDateTimeOffset(timezone.Hours); entity.DateStart = dto.DateStart.ToUtcDateTimeOffset(timezone.Hours);
db.WellOperations.Update(entity); db.WellOperations.Update(entity);
return await db.SaveChangesAsync(token) return await db.SaveChangesAsync(token)
@ -273,57 +241,55 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
.ConfigureAwait(false); .ConfigureAwait(false);
} }
private IQueryable<WellOperation> BuildQuery( private IQueryable<WellOperation> BuildQuery(WellOperationRequest request)
int idWell,
int? operationType = default,
IEnumerable<int>? sectionTypeIds = null,
IEnumerable<int>? operationCategoryIds = null,
DateTime begin = default,
DateTime end = default,
double minDepth = double.MinValue,
double maxDepth = double.MaxValue,
CancellationToken token = default)
{ {
var timezone = wellService.GetTimezone(idWell); var timezone = wellService.GetTimezone(request.IdWell);
var query = db.WellOperations var query = db.WellOperations
.Include(s => s.WellSectionType) .Include(s => s.WellSectionType)
.Include(s => s.OperationCategory) .Include(s => s.OperationCategory)
.Where(s => s.IdWell == idWell); .Where(s => s.IdWell == request.IdWell);
if (operationType.HasValue) if (request.OperationType.HasValue)
query = query.Where(e => e.IdType == operationType.Value); query = query.Where(e => e.IdType == request.OperationType.Value);
if (sectionTypeIds != default && sectionTypeIds.Any()) if (request.SectionTypeIds?.Any() == true)
query = query.Where(e => sectionTypeIds.Contains(e.IdWellSectionType)); query = query.Where(e => request.SectionTypeIds.Contains(e.IdWellSectionType));
if (operationCategoryIds != default && operationCategoryIds.Any()) if (request.OperationCategoryIds?.Any() == true)
query = query.Where(e => operationCategoryIds.Contains(e.IdCategory)); query = query.Where(e => request.OperationCategoryIds.Contains(e.IdCategory));
if (minDepth != double.MinValue) if (request.GeDepth.HasValue)
query = query.Where(e => e.DepthEnd >= minDepth); query = query.Where(e => e.DepthEnd >= request.GeDepth.Value);
if (maxDepth != double.MaxValue) if (request.LeDepth.HasValue)
query = query.Where(e => e.DepthEnd <= maxDepth); query = query.Where(e => e.DepthEnd <= request.LeDepth.Value);
if (begin != default) if (request.GeDate.HasValue)
{ {
var beginOffset = begin.ToUtcDateTimeOffset(timezone.Hours); var geDateOffset = request.GeDate.Value.ToUtcDateTimeOffset(timezone.Hours);
query = query.Where(e => e.DateStart >= beginOffset); query = query.Where(e => e.DateStart >= geDateOffset);
} }
if (end != default) if (request.LeDate.HasValue)
{ {
var endOffset = end.ToUtcDateTimeOffset(timezone.Hours); var leDateOffset = request.LeDate.Value.ToUtcDateTimeOffset(timezone.Hours);
query = query.Where(e => e.DateStart <= endOffset); query = query.Where(e => e.DateStart <= leDateOffset);
}
if (request.SortFields?.Any() == true)
{
query = query.SortBy(request.SortFields);
}
else
{
query = query
.OrderBy(e => e.DateStart)
.ThenBy(e => e.DepthEnd)
.ThenBy(e => e.Id);
} }
query = query
.OrderBy(e => e.DateStart)
.ThenBy(e => e.DepthEnd)
.ThenBy(e => e.Id);
return query; return query;
} }
} }
#nullable disable #nullable disable

View File

@ -1,9 +1,9 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
@ -11,6 +11,7 @@ using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers namespace AsbCloudWebApi.Controllers
{ {
#nullable enable
/// <summary> /// <summary>
/// Буровые операции (вводимые вручную) /// Буровые операции (вводимые вручную)
/// </summary> /// </summary>
@ -44,7 +45,6 @@ namespace AsbCloudWebApi.Controllers
return Ok(result); return Ok(result);
} }
/// <summary> /// <summary>
/// Возвращает список имен типов операций на скважине /// Возвращает список имен типов операций на скважине
/// </summary> /// </summary>
@ -63,15 +63,7 @@ namespace AsbCloudWebApi.Controllers
/// Отфильтрованный список операций на скважине. Если не применять фильтр, то вернется весь список. Сортированный по глубине затем по дате /// Отфильтрованный список операций на скважине. Если не применять фильтр, то вернется весь список. Сортированный по глубине затем по дате
/// </summary> /// </summary>
/// <param name="idWell">id скважины</param> /// <param name="idWell">id скважины</param>
/// <param name="opertaionType">фильтр по план = 0, факт = 1</param> /// <param name="request"></param>
/// <param name="sectionTypeIds">фильтр по списку id конструкций секции</param>
/// <param name="operationCategoryIds">фильтр по списку id категорий операции</param>
/// <param name="begin">фильтр по началу операции</param>
/// <param name="end">фильтр по окончанию операции</param>
/// <param name="minDepth">фильтр по минимальной глубине скважины</param>
/// <param name="maxDepth">фильтр по максимальной глубине скважины</param>
/// <param name="skip"></param>
/// <param name="take"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns>Список операций на скважине в контейнере для постраничного просмотра</returns> /// <returns>Список операций на скважине в контейнере для постраничного просмотра</returns>
[HttpGet] [HttpGet]
@ -79,31 +71,15 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetOperationsAsync( public async Task<IActionResult> GetOperationsAsync(
[FromRoute] int idWell, [FromRoute] int idWell,
[FromQuery] int? opertaionType = default, [FromQuery] WellOperationRequestBase request,
[FromQuery] IEnumerable<int> sectionTypeIds = default, CancellationToken token)
[FromQuery] IEnumerable<int> operationCategoryIds = default,
[FromQuery] DateTime begin = default,
[FromQuery] DateTime end = default,
[FromQuery] double minDepth = double.MinValue,
[FromQuery] double maxDepth = double.MaxValue,
[FromQuery] int skip = 0,
[FromQuery] int take = 32,
CancellationToken token = default)
{ {
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid(); return Forbid();
var requestToService = new WellOperationRequest(request, idWell);
var result = await operationService.GetOperationsAsync( var result = await operationService.GetOperationsAsync(
idWell, requestToService,
opertaionType,
sectionTypeIds,
operationCategoryIds,
begin,
end,
minDepth,
maxDepth,
skip,
take,
token) token)
.ConfigureAwait(false); .ConfigureAwait(false);
return Ok(result); return Ok(result);
@ -113,13 +89,7 @@ namespace AsbCloudWebApi.Controllers
/// Статистика операций по скважине, группированая по категориям /// Статистика операций по скважине, группированая по категориям
/// </summary> /// </summary>
/// <param name="idWell">id скважины</param> /// <param name="idWell">id скважины</param>
/// <param name="opertaionType"></param> /// <param name="request"></param>
/// <param name="sectionTypeIds"></param>
/// <param name="operationCategoryIds"></param>
/// <param name="begin"></param>
/// <param name="end"></param>
/// <param name="minDepth"></param>
/// <param name="maxDepth"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
@ -128,27 +98,15 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<WellGroupOpertionDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<WellGroupOpertionDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetGroupOperationsAsync( public async Task<IActionResult> GetGroupOperationsAsync(
[FromRoute] int idWell, [FromRoute] int idWell,
[FromQuery] int? opertaionType = default, [FromQuery] WellOperationRequestBase request,
[FromQuery] IEnumerable<int> sectionTypeIds = default, CancellationToken token)
[FromQuery] IEnumerable<int> operationCategoryIds = default,
[FromQuery] DateTime begin = default,
[FromQuery] DateTime end = default,
[FromQuery] double minDepth = double.MinValue,
[FromQuery] double maxDepth = double.MaxValue,
CancellationToken token = default)
{ {
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid(); return Forbid();
var requestToService = new WellOperationRequest(request, idWell);
var result = await operationService.GetGroupOperationsStatAsync( var result = await operationService.GetGroupOperationsStatAsync(
idWell, requestToService,
opertaionType,
sectionTypeIds,
operationCategoryIds,
begin,
end,
minDepth,
maxDepth,
token) token)
.ConfigureAwait(false); .ConfigureAwait(false);
return Ok(result); return Ok(result);
@ -166,7 +124,7 @@ namespace AsbCloudWebApi.Controllers
[Permission] [Permission]
[ProducesResponseType(typeof(WellOperationDto), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(WellOperationDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAsync(int idWell, int idOperation, public async Task<IActionResult> GetAsync(int idWell, int idOperation,
CancellationToken token = default) CancellationToken token)
{ {
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid(); return Forbid();
@ -186,13 +144,17 @@ namespace AsbCloudWebApi.Controllers
[Permission] [Permission]
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> InsertRangeAsync(int idWell, [FromBody] IEnumerable<WellOperationDto> values, public async Task<IActionResult> InsertRangeAsync(int idWell, [FromBody] IEnumerable<WellOperationDto> values,
CancellationToken token = default) CancellationToken token)
{ {
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid(); return Forbid();
var result = await operationService.InsertRangeAsync(idWell, values, token) foreach(var value in values)
value.IdWell= idWell;
var result = await operationService.InsertRangeAsync(values, token)
.ConfigureAwait(false); .ConfigureAwait(false);
return Ok(result); return Ok(result);
} }
@ -208,12 +170,15 @@ namespace AsbCloudWebApi.Controllers
[Permission] [Permission]
[ProducesResponseType(typeof(WellOperationDto), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(WellOperationDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> UpdateAsync(int idWell, int idOperation, public async Task<IActionResult> UpdateAsync(int idWell, int idOperation,
[FromBody] WellOperationDto value, CancellationToken token = default) [FromBody] WellOperationDto value, CancellationToken token)
{ {
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid(); return Forbid();
var result = await operationService.UpdateAsync(idWell, idOperation, value, token) value.IdWell= idWell;
value.Id = idOperation;
var result = await operationService.UpdateAsync(value, token)
.ConfigureAwait(false); .ConfigureAwait(false);
return Ok(result); return Ok(result);
} }
@ -228,7 +193,7 @@ namespace AsbCloudWebApi.Controllers
[HttpDelete("{idOperation}")] [HttpDelete("{idOperation}")]
[Permission] [Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> DeleteAsync(int idWell, int idOperation, CancellationToken token = default) public async Task<IActionResult> DeleteAsync(int idWell, int idOperation, CancellationToken token)
{ {
if (!await CanUserAccessToWellAsync(idWell, if (!await CanUserAccessToWellAsync(idWell,
token).ConfigureAwait(false)) token).ConfigureAwait(false))
@ -254,8 +219,8 @@ namespace AsbCloudWebApi.Controllers
[Route("import/{options}")] [Route("import/{options}")]
public async Task<IActionResult> ImportAsync(int idWell, public async Task<IActionResult> ImportAsync(int idWell,
[FromForm] IFormFileCollection files, [FromForm] IFormFileCollection files,
int options = 0, int options,
CancellationToken token = default) CancellationToken token)
{ {
int? idCompany = User.GetCompanyId(); int? idCompany = User.GetCompanyId();
int? idUser = User.GetUserId(); int? idUser = User.GetUserId();
@ -297,7 +262,7 @@ namespace AsbCloudWebApi.Controllers
[Route("export")] [Route("export")]
[Permission] [Permission]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> ExportAsync([FromRoute] int idWell, CancellationToken token = default) public async Task<IActionResult> ExportAsync([FromRoute] int idWell, CancellationToken token)
{ {
int? idCompany = User.GetCompanyId(); int? idCompany = User.GetCompanyId();
@ -324,7 +289,7 @@ namespace AsbCloudWebApi.Controllers
[Route("scheduleReport")] [Route("scheduleReport")]
[Permission] [Permission]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> ScheduleReportAsync([FromRoute] int idWell, [FromServices] IScheduleReportService scheduleReportService, CancellationToken token = default) public async Task<IActionResult> ScheduleReportAsync([FromRoute] int idWell, [FromServices] IScheduleReportService scheduleReportService, CancellationToken token)
{ {
int? idCompany = User.GetCompanyId(); int? idCompany = User.GetCompanyId();
@ -362,4 +327,5 @@ namespace AsbCloudWebApi.Controllers
idWell, token).ConfigureAwait(false); idWell, token).ConfigureAwait(false);
} }
} }
#nullable disable
} }