feat(api): Реализованы JobController, JobGroupController
This commit is contained in:
48
PARR.API/Validators/JobValidator.cs
Normal file
48
PARR.API/Validators/JobValidator.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user