feat(api): Реализованы JobController, JobGroupController

This commit is contained in:
Mikhail Kuznetsov
2025-07-01 17:20:48 +10:00
parent f429b70410
commit 5bbf2e2db5
16 changed files with 855 additions and 44 deletions

View File

@@ -0,0 +1,48 @@
using FluentValidation;
using PARR.API.Contracts.V1.Requests;
using PARR.DAL.Services.Interfaces;
using PARR.DAL.Services.Interfaces.Job;
namespace PARR.API.Validators
{
public class JobValidator : AbstractValidator<JobRequest>
{
private readonly ITnkService tnkService;
private readonly IJobGroupService jobGroupService;
public JobValidator(
ITnkService tnkService,
IJobGroupService jobGroupService
)
{
this.tnkService = tnkService;
this.jobGroupService = jobGroupService;
RuleFor(t => t.Name)
.NotNull().NotEmpty();
RuleFor(t => t.WorkName)
.NotNull().NotEmpty();
RuleFor(t => t.TnkId)
.MustAsync(async (entity, value, c) => await IsTnkExist(entity))
.WithMessage("Указан несуществующий Id ТНК");
RuleFor(t => t.GroupId)
.MustAsync(async (entity, value, c) => await IsGroupExist(entity))
.WithMessage("Указан несуществующий Id группы работ");
}
private async Task<bool> IsGroupExist(JobRequest entity)
{
return await jobGroupService.GetAsync(entity.GroupId) != null;
}
private async Task<bool> IsTnkExist(JobRequest entity)
{
return await tnkService.GetAsync(entity.TnkId) != null;
}
}
}