feat(api): ResponseAreaController getAll. WorkGroupController, getAll, добавлен фильтр по ЗО.

This commit is contained in:
Mikhail Trubnikov
2024-08-16 13:59:27 +10:00
parent 0f3def4b3a
commit ecd24cd94b
7 changed files with 105 additions and 0 deletions

View File

@@ -115,6 +115,11 @@
public const string getParam = "{id}";
}
public static class ResponseArea
{
public const string GetAll = Base + "/response-areas/";
}
public static class RobotHistoryLevel
{
public const string GetAll = Base + "/robot-history-levels/";

View File

@@ -6,5 +6,10 @@
/// Поиск по имени, например "АСУ"
/// </summary>
public string? Name { get; set; }
/// <summary>
/// Поиск по коду зоны ответственности
/// </summary>
public int? ResponseAreaCode { get; set; }
}
}

View File

@@ -0,0 +1,54 @@
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.Constants;
using PARR.DAL.DomainModels;
using PARR.DAL.Services.Interfaces;
namespace PARR.API.Controllers.V1
{
/// <summary>
/// Зоны ответственности
/// </summary>
[Authorize(Roles = ParrRoles.Administrator.Role)]
public class ResponseAreaController : BaseApiController
{
private readonly IMapper mapper;
private readonly IResponseAreaService responseAreaService;
public ResponseAreaController(
IMapper mapper,
IResponseAreaService responseAreaService
)
{
this.mapper = mapper;
this.responseAreaService = responseAreaService;
}
/// <summary>
/// Список зон ответственности
/// </summary>
/// <returns></returns>
[HttpGet(ApiRoutes.ResponseArea.GetAll)]
public async Task<IActionResult> GetAll()
{
var query = responseAreaService.Get().OrderBy(t => t.Name);
var responseAreas = await query.ToListAsync();
if (!responseAreas.Any())
return NoContent();
var response = mapper.Map<List<ResponseAreaResponse>>(responseAreas);
return Ok(new Response<List<ResponseAreaResponse>>(response, true));
}
}
}

View File

@@ -9,6 +9,7 @@ using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.Base;
using PARR.API.Extensions;
using PARR.Constants;
using PARR.DAL.Contracts;
using PARR.DAL.DomainModels;
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces;
@@ -50,6 +51,15 @@ namespace PARR.API.Controllers.V1
if (!string.IsNullOrEmpty(filter.Name))
query = query.Where(t => t.Name.ToLower().Contains(filter.Name.ToLower()));
if (filter.ResponseAreaCode.HasValue)
{
//todo: validate ResponseAreaEnum
if (!Enum.IsDefined(typeof(ResponseAreaEnum), filter.ResponseAreaCode.Value))
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(filter.ResponseAreaCode), Message = "Неверное значение" } }));
query = query.Where(t => t.ResponseAreaCode == filter.ResponseAreaCode.Value);
}
var workGroups = await workGroupService.GetPage(query, paginationFilter).ToListAsync();
if (!workGroups.Any())