This commit is contained in:
KharchenkoVV 2021-08-13 14:50:27 +05:00
commit 5951953cb6
5 changed files with 18 additions and 3 deletions

View File

@ -13,5 +13,6 @@ namespace AsbCloudApp.Services
Task<IEnumerable<WellSectionDto>> InsertRangeAsync(int idWell, IEnumerable<WellSectionDto> newItems, CancellationToken token = default); Task<IEnumerable<WellSectionDto>> InsertRangeAsync(int idWell, IEnumerable<WellSectionDto> newItems, CancellationToken token = default);
Task<WellSectionDto> UpdateAsync(int idWell, int idSection, WellSectionDto item, CancellationToken token = default); Task<WellSectionDto> UpdateAsync(int idWell, int idSection, WellSectionDto item, CancellationToken token = default);
Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token = default); Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token = default);
Task<string[]> GetTypesAsync(CancellationToken token);
} }
} }

View File

@ -30,6 +30,7 @@ namespace AsbCloudDb.Model
public virtual DbSet<TelemetryOperation> TelemetryOperations { get; set; } public virtual DbSet<TelemetryOperation> TelemetryOperations { get; set; }
public virtual DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; } public virtual DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; }
public virtual DbSet<WellSection> WellSections { get; set; } public virtual DbSet<WellSection> WellSections { get; set; }
public virtual DbSet<WellSectionType> WellSectionTypes { get; set; }
public virtual DbSet<WellOperation> WellOperations { get; set; } public virtual DbSet<WellOperation> WellOperations { get; set; }
public virtual DbSet<WellType> WellTypes { get; set; } public virtual DbSet<WellType> WellTypes { get; set; }
public virtual DbSet<LastData> LastData { get; set; } public virtual DbSet<LastData> LastData { get; set; }

View File

@ -26,6 +26,7 @@ namespace AsbCloudDb.Model
DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; } DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; }
DbSet<Well> Wells { get; set; } DbSet<Well> Wells { get; set; }
DbSet<WellSection> WellSections { get; set; } DbSet<WellSection> WellSections { get; set; }
DbSet<WellSectionType> WellSectionTypes { get; set; }
DbSet<WellOperation> WellOperations { get; set; } DbSet<WellOperation> WellOperations { get; set; }
DbSet<WellType> WellTypes { get; set; } DbSet<WellType> WellTypes { get; set; }
DbSet<LastData> LastData { get; set; } DbSet<LastData> LastData { get; set; }

View File

@ -25,6 +25,9 @@ namespace AsbCloudInfrastructure.Services
cachedSectionsTypes = cache.GetCachedTable<WellSectionType>((DbContext)context); cachedSectionsTypes = cache.GetCachedTable<WellSectionType>((DbContext)context);
} }
public Task<string[]> GetTypesAsync(CancellationToken token) =>
context.WellSectionTypes.Select(e => e.Caption).Distinct().AsNoTracking().ToArrayAsync(token);
public async Task<PaginationContainer<WellSectionDto>> GetAllByWellIdAsync(int idWell, int skip, int take, CancellationToken token = default) public async Task<PaginationContainer<WellSectionDto>> GetAllByWellIdAsync(int idWell, int skip, int take, CancellationToken token = default)
{ {
var query = dbSet var query = dbSet

View File

@ -26,7 +26,16 @@ namespace AsbCloudWebApi.Controllers
} }
[HttpGet] [HttpGet]
[ProducesResponseType(typeof(IEnumerable<WellSectionDto>), (int)System.Net.HttpStatusCode.OK)] [Route("types")]
[ProducesResponseType(typeof(string[]), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetTypesAsync(CancellationToken token = default)
{
var result = await sectionsService.GetTypesAsync(token).ConfigureAwait(false);
return Ok(result);
}
[HttpGet]
[ProducesResponseType(typeof(PaginationContainer<WellSectionDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAllAsync(int idWell, int skip = 0, int take = 32, public async Task<IActionResult> GetAllAsync(int idWell, int skip = 0, int take = 32,
CancellationToken token = default) CancellationToken token = default)
{ {
@ -75,13 +84,13 @@ namespace AsbCloudWebApi.Controllers
[HttpDelete("{idSection}")] [HttpDelete("{idSection}")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> DeleteAsync(int idWell, int idSection, CancellationToken token = default) public async Task<IActionResult> DeleteAsync(int idWell, int idItem, CancellationToken token = default)
{ {
if (!await CanUserAccessToWellAsync(idWell, if (!await CanUserAccessToWellAsync(idWell,
token).ConfigureAwait(false)) token).ConfigureAwait(false))
return Forbid(); return Forbid();
var result = await sectionsService.DeleteAsync(new int[] { idSection }, token).ConfigureAwait(false); var result = await sectionsService.DeleteAsync(new int[] { idItem }, token).ConfigureAwait(false);
return Ok(result); return Ok(result);
} }