feat(api): ResponseAreaController getAll. WorkGroupController, getAll, добавлен фильтр по ЗО.
This commit is contained in:
@@ -115,6 +115,11 @@
|
|||||||
public const string getParam = "{id}";
|
public const string getParam = "{id}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ResponseArea
|
||||||
|
{
|
||||||
|
public const string GetAll = Base + "/response-areas/";
|
||||||
|
}
|
||||||
|
|
||||||
public static class RobotHistoryLevel
|
public static class RobotHistoryLevel
|
||||||
{
|
{
|
||||||
public const string GetAll = Base + "/robot-history-levels/";
|
public const string GetAll = Base + "/robot-history-levels/";
|
||||||
|
|||||||
@@ -6,5 +6,10 @@
|
|||||||
/// Поиск по имени, например "АСУ"
|
/// Поиск по имени, например "АСУ"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск по коду зоны ответственности
|
||||||
|
/// </summary>
|
||||||
|
public int? ResponseAreaCode { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
54
PARR.API/Controllers/V1/ResponseAreaController.cs
Normal file
54
PARR.API/Controllers/V1/ResponseAreaController.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ using PARR.API.Contracts.V1.Responses.Base;
|
|||||||
using PARR.API.Controllers.V1.Base;
|
using PARR.API.Controllers.V1.Base;
|
||||||
using PARR.API.Extensions;
|
using PARR.API.Extensions;
|
||||||
using PARR.Constants;
|
using PARR.Constants;
|
||||||
|
using PARR.DAL.Contracts;
|
||||||
using PARR.DAL.DomainModels;
|
using PARR.DAL.DomainModels;
|
||||||
using PARR.DAL.Models;
|
using PARR.DAL.Models;
|
||||||
using PARR.DAL.Services.Interfaces;
|
using PARR.DAL.Services.Interfaces;
|
||||||
@@ -50,6 +51,15 @@ namespace PARR.API.Controllers.V1
|
|||||||
if (!string.IsNullOrEmpty(filter.Name))
|
if (!string.IsNullOrEmpty(filter.Name))
|
||||||
query = query.Where(t => t.Name.ToLower().Contains(filter.Name.ToLower()));
|
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();
|
var workGroups = await workGroupService.GetPage(query, paginationFilter).ToListAsync();
|
||||||
|
|
||||||
if (!workGroups.Any())
|
if (!workGroups.Any())
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ namespace PARR.DAL
|
|||||||
services.AddTransient<IWeekendDayService, WeekendDayService>();
|
services.AddTransient<IWeekendDayService, WeekendDayService>();
|
||||||
services.AddTransient<IDistributionPeriodService, DistributionPeriodService>();
|
services.AddTransient<IDistributionPeriodService, DistributionPeriodService>();
|
||||||
services.AddTransient<IEsppSchTypeValueService, EsppSchTypeValueService>();
|
services.AddTransient<IEsppSchTypeValueService, EsppSchTypeValueService>();
|
||||||
|
services.AddTransient<IResponseAreaService, ResponseAreaService>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
21
PARR.DAL/Services/Implementations/ResponseAreaService.cs
Normal file
21
PARR.DAL/Services/Implementations/ResponseAreaService.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using PARR.DAL.Context;
|
||||||
|
using PARR.DAL.Models;
|
||||||
|
using PARR.DAL.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace PARR.DAL.Services.Implementations
|
||||||
|
{
|
||||||
|
internal class ResponseAreaService : IResponseAreaService
|
||||||
|
{
|
||||||
|
private readonly DataContext dataContext;
|
||||||
|
|
||||||
|
public ResponseAreaService(DataContext dataContext)
|
||||||
|
{
|
||||||
|
this.dataContext = dataContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IQueryable<ResponseArea> Get()
|
||||||
|
{
|
||||||
|
return dataContext.ResponseAreas;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
PARR.DAL/Services/Interfaces/IResponseAreaService.cs
Normal file
9
PARR.DAL/Services/Interfaces/IResponseAreaService.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using PARR.DAL.Models;
|
||||||
|
|
||||||
|
namespace PARR.DAL.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface IResponseAreaService
|
||||||
|
{
|
||||||
|
IQueryable<ResponseArea> Get();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user