feat(api): изменены респонсы Job и JobGroup.
This commit is contained in:
@@ -12,9 +12,11 @@ using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Extensions;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Models.Job;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
@@ -30,7 +32,9 @@ namespace PARR.API.Controllers.V1
|
||||
private readonly IUriService uriService;
|
||||
private readonly IJobGroupService groupService;
|
||||
private readonly IJobService jobService;
|
||||
private readonly IEsppSchTypeConfigService esppConfigService;
|
||||
private readonly IValidator<JobGroupRequest> validator;
|
||||
private readonly SettingsFromDb settingsFromDb;
|
||||
|
||||
public JobGroupController(
|
||||
ILogger<JobController> logger,
|
||||
@@ -38,7 +42,9 @@ namespace PARR.API.Controllers.V1
|
||||
IUriService uriService,
|
||||
IJobGroupService groupService,
|
||||
IJobService jobService,
|
||||
IValidator<JobGroupRequest> validator
|
||||
IEsppSchTypeConfigService esppConfigService,
|
||||
IValidator<JobGroupRequest> validator,
|
||||
SettingsFromDb settingsFromDb
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
@@ -46,7 +52,9 @@ namespace PARR.API.Controllers.V1
|
||||
this.uriService = uriService;
|
||||
this.groupService = groupService;
|
||||
this.jobService = jobService;
|
||||
this.esppConfigService = esppConfigService;
|
||||
this.validator = validator;
|
||||
this.settingsFromDb = settingsFromDb;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +74,7 @@ namespace PARR.API.Controllers.V1
|
||||
if (!string.IsNullOrEmpty(filter.Name))
|
||||
query = query.Where(t => t.GroupName.ToLower().Contains(filter.Name.ToLower()));
|
||||
|
||||
if (filter.IsFull)//TODO а зачем он тогда вообще???
|
||||
if (filter.IsFull)
|
||||
query = query.Include(t => t.Jobs).ThenInclude(t => t.Tnk);
|
||||
|
||||
var jobGroups = await groupService.GetPage(query, paginationFilter).ToListAsync();
|
||||
@@ -76,6 +84,10 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
var response = mapper.Map<List<JobGroupResponse>>(jobGroups);
|
||||
|
||||
if (filter.IsFull)
|
||||
foreach (var jobGroupResponse in response)
|
||||
await AppendMissingDataAsync(jobGroupResponse);
|
||||
|
||||
var paginationResponse = new PagedResponse<JobGroupResponse>(response, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
return Ok(paginationResponse);
|
||||
@@ -255,7 +267,7 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Удалить группу заданий на выполнение работ (только если нет связанных шаблонов)
|
||||
/// Удалить группу заданий на выполнение работ (только если нет связанных заданий)
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
@@ -322,5 +334,29 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
return isScheduleChanged;
|
||||
}
|
||||
|
||||
|
||||
private async Task AppendMissingDataAsync(JobGroupResponse jobGroupResponse)
|
||||
{
|
||||
var schedule = await esppConfigService.GetEsppScheduleDtoAsync(jobGroupResponse.Id);
|
||||
|
||||
if (schedule == null)
|
||||
{
|
||||
logger.LogError($"Не смог замапить расписание, так как оно null. JobGroupId: {jobGroupResponse.Id}");
|
||||
return;
|
||||
}
|
||||
|
||||
var scheduleResponse = new JobGroupScheduleResponse
|
||||
{
|
||||
Timezone = settingsFromDb.ScheduleTimezone,
|
||||
TypeSchedule = mapper.Map<EsppScheduleTypeScheduleResponse>(schedule.TypeSchedule),
|
||||
Values = mapper.Map<List<EsppScheduleValResponse>>(schedule.Values).OrderBy(t => t.Order).ToList()
|
||||
};
|
||||
|
||||
jobGroupResponse.Schedule = scheduleResponse;
|
||||
|
||||
jobGroupResponse.JobsCount = await jobService.Get().CountAsync(t => t.GroupId == jobGroupResponse.Id);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user