feat(dal, api): в таблицу Units добавлено поле LastLogon. Переделана авторизация для хостов (ЭК), теперь берется ip из связанных Units. Переделаны запросы авторизации в кеш. Переделан запрос и модель в influxdb. Обновлена статистика по юнитам и полям.
This commit is contained in:
95
PARR.API/Controllers/V1/UnitController.cs
Normal file
95
PARR.API/Controllers/V1/UnitController.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Requests.Queries;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Extensions;
|
||||
using PARR.BLL.Helpers;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models.Unit;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class UnitController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IUnitService unitService;
|
||||
|
||||
public UnitController(
|
||||
IMapper mapper,
|
||||
IUnitService unitService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.unitService = unitService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить список ЭК постранично
|
||||
/// </summary>
|
||||
/// <param name="paginationQuery"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Unit.GetAll)]
|
||||
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] HostQuery request)
|
||||
{
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
|
||||
IQueryable<Unit> query = unitService.Get()
|
||||
.OrderBy(t => t.Name);
|
||||
|
||||
if (!string.IsNullOrEmpty(request.Mask))
|
||||
query = query.Where(t => EF.Functions.Like(t.Name.ToLower(), SqlHelpers.RegexToLike(request.Mask)));
|
||||
|
||||
if (request.IsFull)
|
||||
query = query
|
||||
.Include(t => t.UnitValues)
|
||||
.ThenInclude(uv => uv.Value)
|
||||
.Include(tf => tf.UnitValues)
|
||||
.ThenInclude(uv => uv.Field);
|
||||
|
||||
var units = await unitService.GetPage(query, paginationFilter).ToListAsync();
|
||||
|
||||
if (!units.Any())
|
||||
return NoContent();
|
||||
|
||||
var unitResponse = mapper.Map<List<UnitWithAttributesResponse>>(units);
|
||||
var paginationResponse = new PagedResponse<UnitWithAttributesResponse>(unitResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
return Ok(paginationResponse);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить ЭК по id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Unit.Get)]
|
||||
public async Task<IActionResult> GetById([FromRoute] Guid id)
|
||||
{
|
||||
var unit = await unitService.Get()
|
||||
.Include(t => t.UnitValues)
|
||||
.ThenInclude(uv => uv.Value)
|
||||
.Include(tf => tf.UnitValues)
|
||||
.ThenInclude(uv => uv.Field)
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (unit == null)
|
||||
return NotFound();
|
||||
|
||||
var response = mapper.Map<UnitWithAttributesResponse>(unit);
|
||||
|
||||
return Ok(new Response<UnitWithAttributesResponse>(response, true));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user