feat(api): appInWorkContoller добавлен метод Update
This commit is contained in:
@@ -290,8 +290,6 @@
|
|||||||
public const string GetAll = Base + "/jobs/";
|
public const string GetAll = Base + "/jobs/";
|
||||||
public const string Get = Base + "/jobs/" + getParam;
|
public const string Get = Base + "/jobs/" + getParam;
|
||||||
|
|
||||||
public const string GetScheduler = Base + "/jobs/" + getParam + "/scheduller";
|
|
||||||
|
|
||||||
public const string Delete = Base + "/jobs/" + getParam;
|
public const string Delete = Base + "/jobs/" + getParam;
|
||||||
public const string Create = Base + "/jobs/";
|
public const string Create = Base + "/jobs/";
|
||||||
public const string Update = Base + "/jobs/" + getParam;
|
public const string Update = Base + "/jobs/" + getParam;
|
||||||
|
|||||||
@@ -131,6 +131,8 @@ namespace PARR.API.Controllers.V1
|
|||||||
public async Task<IActionResult> GetById([FromRoute] Guid id)
|
public async Task<IActionResult> GetById([FromRoute] Guid id)
|
||||||
{
|
{
|
||||||
var applicationInWork = await applicationsInWorkService.Get()
|
var applicationInWork = await applicationsInWorkService.Get()
|
||||||
|
.Include(t => t.Application)
|
||||||
|
.Include(t => t.Work)
|
||||||
.FirstOrDefaultAsync(t => t.Id == id);
|
.FirstOrDefaultAsync(t => t.Id == id);
|
||||||
|
|
||||||
if (applicationInWork == null)
|
if (applicationInWork == null)
|
||||||
@@ -140,5 +142,46 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
return Ok(new Response<ApplicationInWorkResponse>(response, true));
|
return Ok(new Response<ApplicationInWorkResponse>(response, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обновить задание на выполнение работ
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut(ApiRoutes.Job.Update)]
|
||||||
|
public async Task<IActionResult> Update([FromRoute] Guid id, [FromBody] ApplicationInWorkRequest request)
|
||||||
|
{
|
||||||
|
var resultValidate = await validator.ValidateAsync(request);
|
||||||
|
if (!resultValidate.IsValid)
|
||||||
|
return BadRequest(new Response(resultValidate.Errors));
|
||||||
|
|
||||||
|
var orig = await applicationsInWorkService.GetAsync(id);
|
||||||
|
|
||||||
|
if (orig == null)
|
||||||
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при изменении задания на выполнение работ. Не найдено задание на выполнение работ Id: {id}" } }));
|
||||||
|
|
||||||
|
orig.WorkId = request.WorkId;
|
||||||
|
orig.ApplicationId = request.ApplicationId;
|
||||||
|
orig.TemplateDuration = request.TemplateDuration;
|
||||||
|
orig.ShortDescription = request.ShortDescription;
|
||||||
|
orig.FullDescription = request.FullDescription;
|
||||||
|
orig.Solution = request.Solution;
|
||||||
|
orig.NextRun = request.NextRun;
|
||||||
|
orig.IsAgent = request.IsAgent;
|
||||||
|
orig.AgentName = request.AgentName;
|
||||||
|
orig.AgentTimeOutSec = request.AgentTimeOutSec;
|
||||||
|
orig.AgentScript = request.AgentScript;
|
||||||
|
|
||||||
|
if (!await applicationsInWorkService.CommitAsync())
|
||||||
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка записи в базу данных изменений задания на выполнение работ." } }));
|
||||||
|
|
||||||
|
logger.LogInformation($"Пользователь {User.Identity?.Name} обновил задание на выполнение работ: {orig.Id}," +
|
||||||
|
$" {orig.WorkId}, {orig.ApplicationId}, {orig.TemplateDuration}, {orig.ShortDescription}," +
|
||||||
|
$" {orig.FullDescription}, {orig.Solution}, {orig.NextRun}, {orig.IsAgent}, {orig.AgentName}, {orig.AgentTimeOutSec}, {orig.AgentScript}");
|
||||||
|
|
||||||
|
return Ok(new Response<ApplicationInWorkResponse>(mapper.Map<ApplicationInWorkResponse>(orig), true));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user