diff --git a/AsbCloudApp/Services/IWellSectionService.cs b/AsbCloudApp/Services/IWellSectionService.cs index 4e854d84..84693d4f 100644 --- a/AsbCloudApp/Services/IWellSectionService.cs +++ b/AsbCloudApp/Services/IWellSectionService.cs @@ -13,5 +13,6 @@ namespace AsbCloudApp.Services Task> InsertRangeAsync(int idWell, IEnumerable newItems, CancellationToken token = default); Task UpdateAsync(int idWell, int idSection, WellSectionDto item, CancellationToken token = default); Task DeleteAsync(IEnumerable ids, CancellationToken token = default); + Task GetTypesAsync(CancellationToken token); } } diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 849a3043..c2ec82c5 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -30,6 +30,7 @@ namespace AsbCloudDb.Model public virtual DbSet TelemetryOperations { get; set; } public virtual DbSet TelemetryAnalysis { get; set; } public virtual DbSet WellSections { get; set; } + public virtual DbSet WellSectionTypes { get; set; } public virtual DbSet WellOperations { get; set; } public virtual DbSet WellTypes { get; set; } public virtual DbSet LastData { get; set; } diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index 0e370c4d..d10b2320 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -26,6 +26,7 @@ namespace AsbCloudDb.Model DbSet TelemetryAnalysis { get; set; } DbSet Wells { get; set; } DbSet WellSections { get; set; } + DbSet WellSectionTypes { get; set; } DbSet WellOperations { get; set; } DbSet WellTypes { get; set; } DbSet LastData { get; set; } diff --git a/AsbCloudInfrastructure/Services/WellSectionService.cs b/AsbCloudInfrastructure/Services/WellSectionService.cs index 89fb10b2..f6d81900 100644 --- a/AsbCloudInfrastructure/Services/WellSectionService.cs +++ b/AsbCloudInfrastructure/Services/WellSectionService.cs @@ -25,6 +25,9 @@ namespace AsbCloudInfrastructure.Services cachedSectionsTypes = cache.GetCachedTable((DbContext)context); } + public Task GetTypesAsync(CancellationToken token) => + context.WellSectionTypes.Select(e => e.Caption).Distinct().AsNoTracking().ToArrayAsync(token); + public async Task> GetAllByWellIdAsync(int idWell, int skip, int take, CancellationToken token = default) { var query = dbSet diff --git a/AsbCloudWebApi/Controllers/WellSectionController.cs b/AsbCloudWebApi/Controllers/WellSectionController.cs index f3d453fe..a0daa41d 100644 --- a/AsbCloudWebApi/Controllers/WellSectionController.cs +++ b/AsbCloudWebApi/Controllers/WellSectionController.cs @@ -26,7 +26,16 @@ namespace AsbCloudWebApi.Controllers } [HttpGet] - [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + [Route("types")] + [ProducesResponseType(typeof(string[]), (int)System.Net.HttpStatusCode.OK)] + public async Task GetTypesAsync(CancellationToken token = default) + { + var result = await sectionsService.GetTypesAsync(token).ConfigureAwait(false); + return Ok(result); + } + + [HttpGet] + [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] public async Task GetAllAsync(int idWell, int skip = 0, int take = 32, CancellationToken token = default) { @@ -75,13 +84,13 @@ namespace AsbCloudWebApi.Controllers [HttpDelete("{idSection}")] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public async Task DeleteAsync(int idWell, int idSection, CancellationToken token = default) + public async Task DeleteAsync(int idWell, int idItem, CancellationToken token = default) { if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) 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); }