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

View File

@ -30,6 +30,20 @@ namespace AsbCloudWebApi.Controllers
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>