feat(api): JobGroupController добавлен метод Delete
This commit is contained in:
@@ -29,6 +29,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
private readonly IMapper mapper;
|
private readonly IMapper mapper;
|
||||||
private readonly IUriService uriService;
|
private readonly IUriService uriService;
|
||||||
private readonly IJobGroupService groupService;
|
private readonly IJobGroupService groupService;
|
||||||
|
private readonly IJobService jobService;
|
||||||
private readonly IValidator<JobGroupRequest> validator;
|
private readonly IValidator<JobGroupRequest> validator;
|
||||||
|
|
||||||
public JobGroupController(
|
public JobGroupController(
|
||||||
@@ -36,6 +37,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
IMapper mapper,
|
IMapper mapper,
|
||||||
IUriService uriService,
|
IUriService uriService,
|
||||||
IJobGroupService groupService,
|
IJobGroupService groupService,
|
||||||
|
IJobService jobService,
|
||||||
IValidator<JobGroupRequest> validator
|
IValidator<JobGroupRequest> validator
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -43,6 +45,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
this.uriService = uriService;
|
this.uriService = uriService;
|
||||||
this.groupService = groupService;
|
this.groupService = groupService;
|
||||||
|
this.jobService = jobService;
|
||||||
this.validator = validator;
|
this.validator = validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,32 +259,36 @@ namespace PARR.API.Controllers.V1
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
//[HttpDelete(ApiRoutes.JobGroup.Delete)]
|
[HttpDelete(ApiRoutes.JobGroup.Delete)]
|
||||||
//public async Task<IActionResult> Delete([FromRoute] Guid id)
|
public async Task<IActionResult> Delete([FromRoute] Guid id)
|
||||||
//{
|
{
|
||||||
// var jobGroup = await groupService.Get()
|
var jobGroup = await groupService.Get()
|
||||||
// .Include(t => t.Jobs)
|
.FirstOrDefaultAsync(t => t.Id == id);
|
||||||
// .ThenInclude(t => t.Tnk)
|
|
||||||
// .FirstOrDefaultAsync(t => t.Id == id);
|
|
||||||
|
|
||||||
// if (jobGroup == null)
|
if (jobGroup == null)
|
||||||
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel {
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel {
|
||||||
// Message = $"Ошибка при удалении группы заданий на выполнение работ. Не найдена группа заданий на выполнение работ Id: {id}"
|
Message = $"Ошибка при удалении группы заданий на выполнение работ. Не найдена группа заданий на выполнение работ Id: {id}"
|
||||||
// } }));
|
} }));
|
||||||
|
|
||||||
// if (!groupService.Delete(jobGroup) || !await groupService.CommitAsync())
|
var jobCount = await jobService.Get().CountAsync(t => t.GroupId == id);
|
||||||
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel {
|
if (jobCount > 0)
|
||||||
// Message = $"Ошибка при удалении группы заданий на выполнение работ"
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel {
|
||||||
// } }));
|
Message = $"Ошибка при удалении группы заданий на выполнение работ. С данным группой связаны задания: {jobCount} шт."
|
||||||
|
} }));
|
||||||
|
|
||||||
// logger.LogInformation($"Пользователь {User.Identity?.Name} удалил задание на выполнение работ: {jobGroup.Id},{jobGroup.GroupName}," +
|
if (!groupService.Delete(jobGroup) || !await groupService.CommitAsync())
|
||||||
// $" {jobGroup.IsUmbrella}, {jobGroup.ShortDescription}, {jobGroup.FullDescription}," +
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel {
|
||||||
// $" {jobGroup.Solution}, {jobGroup.TemplateDuration}, {jobGroup.ReferenceDate}" +
|
Message = $"Ошибка при удалении группы заданий на выполнение работ"
|
||||||
// $"{jobGroup.IsAutoDistributionEnabled}, {jobGroup.IsAgent}, {jobGroup.AgentName}" +
|
} }));
|
||||||
// $"{jobGroup.AgentTimeOutSec}, {jobGroup.AgentScript}");
|
|
||||||
|
|
||||||
// return NoContent();
|
logger.LogInformation($"Пользователь {User.Identity?.Name} удалил группу заданий на выполнение работ: {jobGroup.Id},{jobGroup.GroupName}," +
|
||||||
//}
|
$" {jobGroup.IsUmbrella}, {jobGroup.ShortDescription}, {jobGroup.FullDescription}," +
|
||||||
|
$" {jobGroup.Solution}, {jobGroup.TemplateDuration}, {jobGroup.ReferenceDate}" +
|
||||||
|
$"{jobGroup.IsAutoDistributionEnabled}, {jobGroup.IsAgent}, {jobGroup.AgentName}" +
|
||||||
|
$"{jobGroup.AgentTimeOutSec}, {jobGroup.AgentScript}");
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user