feat(api): jobGroup при создании и обновлении принимает поле GroupingUnitFieldId. Валидации. Контроллеры KiiUnitController, RegionalEkPtkGroupController
This commit is contained in:
@@ -517,6 +517,16 @@
|
|||||||
public const string GetAll = Base + "/shortcodes/";
|
public const string GetAll = Base + "/shortcodes/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class RegionalEkPtkGroup
|
||||||
|
{
|
||||||
|
public const string GetAll = Base + "/regional-ek-ptk-groups/";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class KiiUnit
|
||||||
|
{
|
||||||
|
public const string GetAll = Base + "/kii-units/";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,11 @@
|
|||||||
|
|
||||||
public Guid GroupTypeId { get; set; }
|
public Guid GroupTypeId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поле по которому групиируем, если тип - ГРУППА
|
||||||
|
/// </summary>
|
||||||
|
public Guid? GroupingUnitFieldId { get; set; }
|
||||||
|
|
||||||
public required string ShortDescription { get; set; }
|
public required string ShortDescription { get; set; }
|
||||||
|
|
||||||
public required string FullDescription { get; set; }
|
public required string FullDescription { get; set; }
|
||||||
|
|||||||
@@ -20,6 +20,11 @@
|
|||||||
|
|
||||||
public required JobGroupTypeResponse GroupType { get; set; }
|
public required JobGroupTypeResponse GroupType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// По какому полю грппируется, если используется тип ГРУППИРОВКА
|
||||||
|
/// </summary>
|
||||||
|
public FieldResponse? GroupingUnitField { get; set; }
|
||||||
|
|
||||||
// public bool IsAutoDistributionEnabled { get; set; }
|
// public bool IsAutoDistributionEnabled { get; set; }
|
||||||
|
|
||||||
// public bool IsAgent { get; set; }
|
// public bool IsAgent { get; set; }
|
||||||
|
|||||||
@@ -100,7 +100,8 @@ namespace PARR.API.Controllers.V1
|
|||||||
{
|
{
|
||||||
query = query
|
query = query
|
||||||
.Include(t => t.Tnk)
|
.Include(t => t.Tnk)
|
||||||
.Include(t => t.Group).ThenInclude(t => t.GroupType);
|
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
||||||
|
.Include(t => t.Group).ThenInclude(t => t.GroupingUnitField);
|
||||||
|
|
||||||
query = query
|
query = query
|
||||||
.Include(t => t.UnitFilters)
|
.Include(t => t.UnitFilters)
|
||||||
@@ -140,6 +141,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
var job = await jobService.Get()
|
var job = await jobService.Get()
|
||||||
.Include(t => t.Tnk)
|
.Include(t => t.Tnk)
|
||||||
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
||||||
|
.Include(t => t.Group).ThenInclude(t => t.GroupingUnitField)
|
||||||
.Include(t => t.UnitFilters)
|
.Include(t => t.UnitFilters)
|
||||||
.ThenInclude(t => t.FieldFilters)
|
.ThenInclude(t => t.FieldFilters)
|
||||||
.ThenInclude(t => t.UnitField)
|
.ThenInclude(t => t.UnitField)
|
||||||
@@ -178,14 +180,15 @@ namespace PARR.API.Controllers.V1
|
|||||||
return BadRequest(new Response(jobValidateResult.Errors));
|
return BadRequest(new Response(jobValidateResult.Errors));
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
//TODO: !!!!!!! проверить, если тип ЗОНТИК или ГРУППИРОВКА, то обязательно должны быть заполнены поля min max
|
||||||
|
|
||||||
#region Проверка существования работы с такими же параметрами
|
#region Проверка существования работы с такими же параметрами
|
||||||
|
|
||||||
var isExistTheSameLinks = await jobService.Get()
|
var isExistTheSameLinks = await jobService.Get()
|
||||||
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
||||||
.CountAsync(t =>
|
.CountAsync(t =>
|
||||||
//t.Group!.IsUmbrella == true &&
|
//t.Group!.GroupType!.Code == JobGroupTypesEnum.Umbrella
|
||||||
t.Group!.GroupType!.Code == JobGroupTypesEnum.Umbrella &&
|
(t.Group!.GroupType!.Code == JobGroupTypesEnum.Umbrella || t.Group!.GroupType!.Code == JobGroupTypesEnum.Group) &&
|
||||||
t.GroupId == request.GroupId &&
|
t.GroupId == request.GroupId &&
|
||||||
(t.MinValueRelationships == request.MinValueRelationships ||
|
(t.MinValueRelationships == request.MinValueRelationships ||
|
||||||
t.MaxValueRelationships == request.MaxValueRelationships)
|
t.MaxValueRelationships == request.MaxValueRelationships)
|
||||||
@@ -215,6 +218,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
var createdJob = await jobService.Get()
|
var createdJob = await jobService.Get()
|
||||||
.Include(t => t.Tnk)
|
.Include(t => t.Tnk)
|
||||||
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
||||||
|
.Include(t => t.Group).ThenInclude(t => t.GroupingUnitField)
|
||||||
.Include(t => t.UnitFilters)
|
.Include(t => t.UnitFilters)
|
||||||
.ThenInclude(t => t.FieldFilters)
|
.ThenInclude(t => t.FieldFilters)
|
||||||
.ThenInclude(t => t.UnitField)
|
.ThenInclude(t => t.UnitField)
|
||||||
@@ -249,6 +253,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
var orig = await jobService.Get()
|
var orig = await jobService.Get()
|
||||||
.Include(t => t.Tnk)
|
.Include(t => t.Tnk)
|
||||||
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
||||||
|
.Include(t => t.Group).ThenInclude(t => t.GroupingUnitField)
|
||||||
.Include(t => t.UnitFilters)
|
.Include(t => t.UnitFilters)
|
||||||
.ThenInclude(t => t.FieldFilters)
|
.ThenInclude(t => t.FieldFilters)
|
||||||
.Include(t => t.UnitFilters)
|
.Include(t => t.UnitFilters)
|
||||||
@@ -263,6 +268,11 @@ namespace PARR.API.Controllers.V1
|
|||||||
// если изменили маску шаблона, ниже отправим в очередь, на изменение связанных имен шаблонов
|
// если изменили маску шаблона, ниже отправим в очередь, на изменение связанных имен шаблонов
|
||||||
var isChangedTemplateNameMask = orig.TemplateNameMask != request.TemplateNameMask.Trim();
|
var isChangedTemplateNameMask = orig.TemplateNameMask != request.TemplateNameMask.Trim();
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: ВОТ ЭТО ВООБЩЕ МЫ БУДЕМ ПРОВЕРЯТЬ, АААА???? - Проверка существования работы с такими же параметрами
|
||||||
|
|
||||||
|
//TODO: !!!!!!! проверить, если тип ЗОНТИК или ГРУППИРОВКА, то обязательно должны быть заполнены поля min max
|
||||||
|
|
||||||
#region обновление полей задания на работу
|
#region обновление полей задания на работу
|
||||||
|
|
||||||
orig.Name = request.Name.Trim();
|
orig.Name = request.Name.Trim();
|
||||||
@@ -331,6 +341,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
var updatedJob = await jobService.Get()
|
var updatedJob = await jobService.Get()
|
||||||
.Include(t => t.Tnk)
|
.Include(t => t.Tnk)
|
||||||
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
||||||
|
.Include(t => t.Group).ThenInclude(t => t.GroupingUnitField)
|
||||||
.Include(t => t.UnitFilters)
|
.Include(t => t.UnitFilters)
|
||||||
.ThenInclude(t => t.FieldFilters)
|
.ThenInclude(t => t.FieldFilters)
|
||||||
.ThenInclude(t => t.UnitField)
|
.ThenInclude(t => t.UnitField)
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
private readonly IJobService jobService;
|
private readonly IJobService jobService;
|
||||||
private readonly IEsppSchTypeConfigService esppConfigService;
|
private readonly IEsppSchTypeConfigService esppConfigService;
|
||||||
private readonly IValidator<JobGroupRequest> validator;
|
private readonly IValidator<JobGroupRequest> validator;
|
||||||
|
private readonly IJobGroupTypeService jobGroupTypeService;
|
||||||
private readonly SettingsFromDb settingsFromDb;
|
private readonly SettingsFromDb settingsFromDb;
|
||||||
|
|
||||||
public JobGroupController(
|
public JobGroupController(
|
||||||
@@ -44,6 +45,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
IJobService jobService,
|
IJobService jobService,
|
||||||
IEsppSchTypeConfigService esppConfigService,
|
IEsppSchTypeConfigService esppConfigService,
|
||||||
IValidator<JobGroupRequest> validator,
|
IValidator<JobGroupRequest> validator,
|
||||||
|
IJobGroupTypeService jobGroupTypeService,
|
||||||
SettingsFromDb settingsFromDb
|
SettingsFromDb settingsFromDb
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -54,6 +56,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
this.jobService = jobService;
|
this.jobService = jobService;
|
||||||
this.esppConfigService = esppConfigService;
|
this.esppConfigService = esppConfigService;
|
||||||
this.validator = validator;
|
this.validator = validator;
|
||||||
|
this.jobGroupTypeService = jobGroupTypeService;
|
||||||
this.settingsFromDb = settingsFromDb;
|
this.settingsFromDb = settingsFromDb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +70,9 @@ namespace PARR.API.Controllers.V1
|
|||||||
{
|
{
|
||||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||||
|
|
||||||
IQueryable<JobGroup> query = groupService.Get().Include(t => t.GroupType);
|
IQueryable<JobGroup> query = groupService.Get()
|
||||||
|
.Include(t => t.GroupType)
|
||||||
|
.Include(t => t.GroupingUnitField);
|
||||||
|
|
||||||
query = query.OrderBy(t => t.GroupName);
|
query = query.OrderBy(t => t.GroupName);
|
||||||
|
|
||||||
@@ -105,6 +110,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
var jobGroup = await groupService.Get()
|
var jobGroup = await groupService.Get()
|
||||||
.Include(t => t.Jobs).ThenInclude(t => t.Tnk)
|
.Include(t => t.Jobs).ThenInclude(t => t.Tnk)
|
||||||
.Include(t => t.GroupType)
|
.Include(t => t.GroupType)
|
||||||
|
.Include(t => t.GroupingUnitField)
|
||||||
.FirstOrDefaultAsync(t => t.Id == id);
|
.FirstOrDefaultAsync(t => t.Id == id);
|
||||||
|
|
||||||
if (jobGroup == null)
|
if (jobGroup == null)
|
||||||
@@ -136,6 +142,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
GroupName = request.Name.Trim(),
|
GroupName = request.Name.Trim(),
|
||||||
//IsUmbrella = request.IsUmbrella,
|
//IsUmbrella = request.IsUmbrella,
|
||||||
GroupTypeId = request.GroupTypeId,
|
GroupTypeId = request.GroupTypeId,
|
||||||
|
GroupingUnitFieldId = await GetGroupingUnitFieldIdAsync(request),
|
||||||
ShortDescription = request.ShortDescription.Trim(),
|
ShortDescription = request.ShortDescription.Trim(),
|
||||||
FullDescription = request.FullDescription.Trim(),
|
FullDescription = request.FullDescription.Trim(),
|
||||||
Solution = request.Solution.Trim(),
|
Solution = request.Solution.Trim(),
|
||||||
@@ -167,6 +174,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
var createdJobGroup = await groupService.Get().Include(t => t.Jobs).ThenInclude(t => t.Tnk)
|
var createdJobGroup = await groupService.Get().Include(t => t.Jobs).ThenInclude(t => t.Tnk)
|
||||||
.Include(t => t.GroupType)
|
.Include(t => t.GroupType)
|
||||||
|
.Include(t => t.GroupingUnitField)
|
||||||
.FirstAsync(t => t.Id == jobGroup.Id);
|
.FirstAsync(t => t.Id == jobGroup.Id);
|
||||||
|
|
||||||
var locationUri = uriService.GetUri(ApiRoutes.JobGroup.Get, ApiRoutes.JobGroup.getParam, createdJobGroup.Id);
|
var locationUri = uriService.GetUri(ApiRoutes.JobGroup.Get, ApiRoutes.JobGroup.getParam, createdJobGroup.Id);
|
||||||
@@ -206,6 +214,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
orig.GroupName = request.Name.Trim();
|
orig.GroupName = request.Name.Trim();
|
||||||
//orig.IsUmbrella = request.IsUmbrella;
|
//orig.IsUmbrella = request.IsUmbrella;
|
||||||
orig.GroupTypeId = request.GroupTypeId;
|
orig.GroupTypeId = request.GroupTypeId;
|
||||||
|
orig.GroupingUnitFieldId = await GetGroupingUnitFieldIdAsync(request);
|
||||||
orig.ShortDescription = request.ShortDescription.Trim();
|
orig.ShortDescription = request.ShortDescription.Trim();
|
||||||
orig.FullDescription = request.FullDescription.Trim();
|
orig.FullDescription = request.FullDescription.Trim();
|
||||||
orig.Solution = request.Solution.Trim();
|
orig.Solution = request.Solution.Trim();
|
||||||
@@ -263,6 +272,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
.Include(t => t.Jobs)
|
.Include(t => t.Jobs)
|
||||||
.ThenInclude(t => t.Tnk)
|
.ThenInclude(t => t.Tnk)
|
||||||
.Include(t => t.GroupType)
|
.Include(t => t.GroupType)
|
||||||
|
.Include(t => t.GroupingUnitField)
|
||||||
.FirstAsync(t => t.Id == orig.Id);
|
.FirstAsync(t => t.Id == orig.Id);
|
||||||
|
|
||||||
var response = mapper.Map<JobGroupResponse>(updatedJobGroup);
|
var response = mapper.Map<JobGroupResponse>(updatedJobGroup);
|
||||||
@@ -361,7 +371,34 @@ namespace PARR.API.Controllers.V1
|
|||||||
jobGroupResponse.Schedule = scheduleResponse;
|
jobGroupResponse.Schedule = scheduleResponse;
|
||||||
|
|
||||||
jobGroupResponse.JobsCount = await jobService.Get().CountAsync(t => t.GroupId == jobGroupResponse.Id);
|
jobGroupResponse.JobsCount = await jobService.Get().CountAsync(t => t.GroupId == jobGroupResponse.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Смотрим на тип Группы, и возвращаем GroupingUnitFieldId или обнуляем его
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<Guid?> GetGroupingUnitFieldIdAsync(JobGroupRequest request)
|
||||||
|
{
|
||||||
|
// Если request.GroupingUnitFieldId == null, то ничего проверять не будем
|
||||||
|
if (request.GroupingUnitFieldId == null)
|
||||||
|
return request.GroupingUnitFieldId;
|
||||||
|
|
||||||
|
|
||||||
|
var groupingType = await jobGroupTypeService.Get().FirstAsync(t => t.Code == JobGroupTypesEnum.Group);
|
||||||
|
|
||||||
|
if (request.GroupTypeId == groupingType.Id)
|
||||||
|
{
|
||||||
|
// Это сгруппированный тип, все ок
|
||||||
|
return request.GroupingUnitFieldId;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Это не сгруппированный тип, обнуляем GroupingUnitFieldId
|
||||||
|
logger.LogWarning($"При сохраненни JobGroup, был передан {nameof(request.GroupingUnitFieldId)}: {request.GroupingUnitFieldId}, но при этом тип группы был не ГРУППА, а {request.GroupTypeId}. Обнулил request.GroupingUnitFieldId");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
57
PARR.API/Controllers/V1/KiiUnitController.cs
Normal file
57
PARR.API/Controllers/V1/KiiUnitController.cs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PARR.API.Contracts.V1;
|
||||||
|
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.Services.Interfaces.Unit;
|
||||||
|
|
||||||
|
namespace PARR.API.Controllers.V1
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Список КИИ ЭК
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||||
|
public class KiiUnitController : BaseApiController
|
||||||
|
{
|
||||||
|
private readonly IMapper mapper;
|
||||||
|
private readonly IUnitKiiUnitService unitKiiUnitService;
|
||||||
|
|
||||||
|
public KiiUnitController(
|
||||||
|
IMapper mapper,
|
||||||
|
IUnitKiiUnitService unitKiiUnitService
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.mapper = mapper;
|
||||||
|
this.unitKiiUnitService = unitKiiUnitService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Список КИИ ЭК
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet(ApiRoutes.KiiUnit.GetAll)]
|
||||||
|
public async Task<IActionResult> GetAll()
|
||||||
|
{
|
||||||
|
var query = unitKiiUnitService.Get()
|
||||||
|
.Include(t => t.Unit)
|
||||||
|
.Select(t => t.Unit)
|
||||||
|
.OrderBy(t => t.Name);
|
||||||
|
|
||||||
|
var units = await query.ToListAsync();
|
||||||
|
|
||||||
|
if (!units.Any())
|
||||||
|
return NoContent();
|
||||||
|
|
||||||
|
var response = mapper.Map<List<UnitBaseResponse>>(units);
|
||||||
|
|
||||||
|
return Ok(new Response<List<UnitBaseResponse>>(response, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
56
PARR.API/Controllers/V1/RegionalEkPtkGroupController.cs
Normal file
56
PARR.API/Controllers/V1/RegionalEkPtkGroupController.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PARR.API.Contracts.V1;
|
||||||
|
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.Services.Interfaces.Unit;
|
||||||
|
|
||||||
|
namespace PARR.API.Controllers.V1
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Региональные ЭК ПТК для групповых работ
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||||
|
public class RegionalEkPtkGroupController : BaseApiController
|
||||||
|
{
|
||||||
|
private readonly IMapper mapper;
|
||||||
|
private readonly IUnitRegionalEkPtkGroupService unitRegionalEkPtkGroupService;
|
||||||
|
|
||||||
|
public RegionalEkPtkGroupController(
|
||||||
|
IMapper mapper,
|
||||||
|
IUnitRegionalEkPtkGroupService unitRegionalEkPtkGroupService
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.mapper = mapper;
|
||||||
|
this.unitRegionalEkPtkGroupService = unitRegionalEkPtkGroupService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Региональные ЭК ПТК для групповых работ
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet(ApiRoutes.RegionalEkPtkGroup.GetAll)]
|
||||||
|
public async Task<IActionResult> GetAll()
|
||||||
|
{
|
||||||
|
var query = unitRegionalEkPtkGroupService.Get()
|
||||||
|
.Include(t => t.FieldValue)
|
||||||
|
.Select(t => t.FieldValue)
|
||||||
|
.OrderBy(t => t.Value);
|
||||||
|
|
||||||
|
var objs = await query.ToListAsync();
|
||||||
|
|
||||||
|
if (!objs.Any())
|
||||||
|
return NoContent();
|
||||||
|
|
||||||
|
var response = mapper.Map<List<UnitFieldValueResponse>>(objs);
|
||||||
|
|
||||||
|
return Ok(new Response<List<UnitFieldValueResponse>>(response, true));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -353,7 +353,8 @@ namespace PARR.API.MappingProfiles
|
|||||||
#region JobGroup
|
#region JobGroup
|
||||||
CreateMap<JobGroup, JobGroupBaseResponse>()
|
CreateMap<JobGroup, JobGroupBaseResponse>()
|
||||||
.Include<JobGroup, JobGroupResponse>()
|
.Include<JobGroup, JobGroupResponse>()
|
||||||
.ForMember(d => d.GroupType, o => o.MapFrom(s => s.GroupType));
|
.ForMember(d => d.GroupType, o => o.MapFrom(s => s.GroupType))
|
||||||
|
.ForMember(d => d.GroupingUnitField, o => o.MapFrom(s => s.GroupingUnitField));
|
||||||
|
|
||||||
CreateMap<JobGroup, JobGroupBaseResponse>()
|
CreateMap<JobGroup, JobGroupBaseResponse>()
|
||||||
.ForMember(d => d.Name, o => o.MapFrom(s => s.GroupName));
|
.ForMember(d => d.Name, o => o.MapFrom(s => s.GroupName));
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using PARR.API.Contracts.V1.Requests;
|
using PARR.API.Contracts.V1.Requests;
|
||||||
|
using PARR.DAL.Contracts;
|
||||||
using PARR.DAL.Services.Interfaces.Job;
|
using PARR.DAL.Services.Interfaces.Job;
|
||||||
|
using PARR.DAL.Services.Interfaces.Unit;
|
||||||
|
|
||||||
namespace PARR.API.Validators
|
namespace PARR.API.Validators
|
||||||
{
|
{
|
||||||
public class JobGroupValidator : AbstractValidator<JobGroupRequest>
|
public class JobGroupValidator : AbstractValidator<JobGroupRequest>
|
||||||
{
|
{
|
||||||
public JobGroupValidator(IJobGroupTypeService jobGroupTypeService)
|
public JobGroupValidator(
|
||||||
|
IJobGroupTypeService jobGroupTypeService,
|
||||||
|
IUnitFieldService unitFieldService
|
||||||
|
)
|
||||||
{
|
{
|
||||||
RuleFor(t => t.Name)
|
RuleFor(t => t.Name)
|
||||||
.NotNull().NotEmpty();
|
.NotNull().NotEmpty();
|
||||||
@@ -26,6 +33,33 @@ namespace PARR.API.Validators
|
|||||||
RuleFor(t => t.GroupTypeId)
|
RuleFor(t => t.GroupTypeId)
|
||||||
.MustAsync(async (entity, value, c) => await jobGroupTypeService.GetAsync(value) != null)
|
.MustAsync(async (entity, value, c) => await jobGroupTypeService.GetAsync(value) != null)
|
||||||
.WithMessage("Указан несуществующий Id типа");
|
.WithMessage("Указан несуществующий Id типа");
|
||||||
|
|
||||||
|
//Проверяем существует ли такой GroupingUnitFieldId в unitField
|
||||||
|
RuleFor(t => t.GroupingUnitFieldId)
|
||||||
|
.MustAsync(async (entity, value, c) =>
|
||||||
|
{
|
||||||
|
if (!value.HasValue)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await unitFieldService.GetAsync(value.Value) != null;
|
||||||
|
})
|
||||||
|
.WithMessage("Указано несуществующий Id поля");
|
||||||
|
|
||||||
|
|
||||||
|
RuleFor(t => t.GroupingUnitFieldId)
|
||||||
|
.MustAsync(async (entity, value, c) =>
|
||||||
|
{
|
||||||
|
var groupingJobType = await jobGroupTypeService.Get().FirstAsync(t => t.Code == JobGroupTypesEnum.Group);
|
||||||
|
|
||||||
|
// Если это сгруппированный тип, то у него обязательно должно быть заполнено поле GroupingUnitFieldId
|
||||||
|
if (entity.GroupTypeId == groupingJobType.Id)
|
||||||
|
return value.HasValue;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.WithMessage("Не указано поле для группировки");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user