Add WellOperationController.GetSectionTypes()

This commit is contained in:
Фролов 2021-12-22 17:09:26 +05:00
parent ecfdbfc394
commit 95df836155
3 changed files with 33 additions and 13 deletions

View File

@ -32,5 +32,6 @@ namespace AsbCloudApp.Services
CancellationToken token); CancellationToken token);
Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token); Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token);
IDictionary<int, string> GetSectionTypes();
} }
} }

View File

@ -14,15 +14,20 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
{ {
public class WellOperationService : IWellOperationService public class WellOperationService : IWellOperationService
{ {
private readonly IAsbCloudDbContext context; private readonly IAsbCloudDbContext db;
private readonly CacheTable<WellOperationCategory> cachedOperationCategories; private readonly CacheTable<WellOperationCategory> cachedOperationCategories;
private readonly CacheTable<WellSectionType> cachedSectionTypes;
public WellOperationService(IAsbCloudDbContext context, CacheDb cache) public WellOperationService(IAsbCloudDbContext db, CacheDb cache)
{ {
this.context = context; this.db = db;
cachedOperationCategories = cache.GetCachedTable<WellOperationCategory>((DbContext)context); cachedOperationCategories = cache.GetCachedTable<WellOperationCategory>((DbContext)db);
cachedSectionTypes = cache.GetCachedTable<WellSectionType>((DbContext)db);
} }
public IDictionary<int, string> GetSectionTypes()
=> cachedSectionTypes.ToDictionary(s => s.Id, s => s.Caption);
public IEnumerable<WellOperationCategoryDto> GetCategories() public IEnumerable<WellOperationCategoryDto> GetCategories()
{ {
var operationTypes = cachedOperationCategories var operationTypes = cachedOperationCategories
@ -46,7 +51,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
int take = 32, int take = 32,
CancellationToken token = default) CancellationToken token = default)
{ {
var query = context.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 == idWell);
@ -104,7 +109,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
public async Task<WellOperationDto> GetAsync(int id, public async Task<WellOperationDto> GetAsync(int id,
CancellationToken token = default) CancellationToken token = default)
{ {
var entity = await context.WellOperations var entity = await db.WellOperations
.Include(s => s.WellSectionType) .Include(s => s.WellSectionType)
.Include(s => s.OperationCategory) .Include(s => s.OperationCategory)
.FirstOrDefaultAsync(e => e.Id == id, token) .FirstOrDefaultAsync(e => e.Id == id, token)
@ -128,10 +133,10 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
var entity = operationDto.Adapt<WellOperation>(); var entity = operationDto.Adapt<WellOperation>();
entity.Id = default; entity.Id = default;
entity.IdWell = idWell; entity.IdWell = idWell;
context.WellOperations.Add(entity); db.WellOperations.Add(entity);
} }
return await context.SaveChangesAsync(token) return await db.SaveChangesAsync(token)
.ConfigureAwait(false); .ConfigureAwait(false);
} }
@ -141,17 +146,17 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
var entity = item.Adapt<WellOperation>(); var entity = item.Adapt<WellOperation>();
entity.Id = idOperation; entity.Id = idOperation;
entity.IdWell = idWell; entity.IdWell = idWell;
context.WellOperations.Update(entity); db.WellOperations.Update(entity);
return await context.SaveChangesAsync(token) return await db.SaveChangesAsync(token)
.ConfigureAwait(false); .ConfigureAwait(false);
} }
public async Task<int> DeleteAsync(IEnumerable<int> ids, public async Task<int> DeleteAsync(IEnumerable<int> ids,
CancellationToken token = default) CancellationToken token = default)
{ {
var query = context.WellOperations.Where(e => ids.Contains(e.Id)); var query = db.WellOperations.Where(e => ids.Contains(e.Id));
context.WellOperations.RemoveRange(query); db.WellOperations.RemoveRange(query);
return await context.SaveChangesAsync(token) return await db.SaveChangesAsync(token)
.ConfigureAwait(false); .ConfigureAwait(false);
} }
} }

View File

@ -30,6 +30,20 @@ namespace AsbCloudWebApi.Controllers
this.wellOperationImportService = wellOperationImportService; this.wellOperationImportService = wellOperationImportService;
} }
/// <summary>
/// Возвращает словарь типов секций
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("sectionTypes")]
[ProducesResponseType(typeof(IDictionary<int, string>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetSectionTypes()
{
var result = operationService.GetSectionTypes();
return Ok(result);
}
/// <summary> /// <summary>
/// Возвращает список имен типов операций на скважине /// Возвращает список имен типов операций на скважине
/// </summary> /// </summary>