добавлено логгирование

This commit is contained in:
gorbenko.pavel
2026-08-19 12:15:52 +05:00
parent 9d59074289
commit cf44ae3e2e
5 changed files with 30 additions and 3 deletions
@@ -1,13 +1,16 @@
using FluentResults;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Tnsu.ApprovalRoute.Application.Common.Errors;
using Tnsu.ApprovalRoute.Application.Common.Interfaces;
using Tnsu.ApprovalRoute.Domain.Entities;
using Tnsu.ApprovalRoute.Domain.Enums;
using Tnsu.ApprovalRoute.Infrastructure.Persistence;
namespace Tnsu.ApprovalRoute.Application.TemplateRouteSteps;
public sealed class TemplateRouteStepService(ApprovalRouteDbContext db)
public sealed class TemplateRouteStepService(
ApprovalRouteDbContext db, ICurrentUser currentUser, ILogger<TemplateRouteStepService> logger)
{
public async Task<Result<IReadOnlyList<TemplateRouteStepDto>>> ListAsync(int routeId, CancellationToken cancellationToken)
{
@@ -79,6 +82,8 @@ public sealed class TemplateRouteStepService(ApprovalRouteDbContext db)
};
db.TemplateRouteSteps.Add(entity);
await db.SaveChangesAsync(cancellationToken);
logger.LogInformation(
"Шаг {StepId} маршрута {RouteId} создан пользователем {Author}", entity.Id, route.Id, currentUser.Email);
return Result.Ok(await ToDtoWithWarningAsync(entity, route, cancellationToken));
}
@@ -130,6 +135,8 @@ public sealed class TemplateRouteStepService(ApprovalRouteDbContext db)
entity.SlaHours = r.SlaHours;
entity.AskOverdueReason = r.AskOverdueReason;
await db.SaveChangesAsync(cancellationToken);
logger.LogInformation(
"Шаг {StepId} маршрута {RouteId} изменён пользователем {Author}", entity.Id, route.Id, currentUser.Email);
return Result.Ok(await ToDtoWithWarningAsync(entity, route, cancellationToken));
}
@@ -199,6 +206,8 @@ public sealed class TemplateRouteStepService(ApprovalRouteDbContext db)
entity.SlaHours = r.SlaHours ?? entity.SlaHours;
entity.AskOverdueReason = r.AskOverdueReason ?? entity.AskOverdueReason;
await db.SaveChangesAsync(cancellationToken);
logger.LogInformation(
"Шаг {StepId} маршрута {RouteId} изменён пользователем {Author}", entity.Id, route.Id, currentUser.Email);
return Result.Ok(await ToDtoWithWarningAsync(entity, route, cancellationToken));
}
@@ -211,6 +220,8 @@ public sealed class TemplateRouteStepService(ApprovalRouteDbContext db)
db.TemplateRouteSteps.Remove(entity);
await db.SaveChangesAsync(cancellationToken);
logger.LogInformation(
"Шаг {StepId} маршрута {RouteId} удалён пользователем {Author}", id, routeId, currentUser.Email);
return Result.Ok();
}