Move validator
This commit is contained in:
parent
f0dba347c5
commit
7258c456ff
@ -1,9 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using InternshipSystem.Api.Queries;
|
using InternshipSystem.Api.Queries;
|
||||||
using InternshipSystem.Api.Validators;
|
|
||||||
using InternshipSystem.Core;
|
using InternshipSystem.Core;
|
||||||
using InternshipSystem.Repository;
|
using InternshipSystem.Repository;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
@ -41,7 +39,7 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
public async Task<ActionResult> AddDocumentToInternship([FromBody] DocumentPublishRequest documentRequest)
|
public async Task<ActionResult> AddDocumentToInternship([FromBody] DocumentPublishRequest documentRequest)
|
||||||
{
|
{
|
||||||
var validator = new DocumentPublishRequestValidator();
|
var validator = new DocumentPublishRequest.Validator();
|
||||||
var validationResult = await validator.ValidateAsync(documentRequest);
|
var validationResult = await validator.ValidateAsync(documentRequest);
|
||||||
|
|
||||||
if (!validationResult.IsValid)
|
if (!validationResult.IsValid)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using InternshipSystem.Core.ValueObject;
|
using FluentValidation;
|
||||||
|
using InternshipSystem.Core.ValueObject;
|
||||||
|
|
||||||
namespace InternshipSystem.Api.Queries
|
namespace InternshipSystem.Api.Queries
|
||||||
{
|
{
|
||||||
@ -8,5 +9,14 @@ namespace InternshipSystem.Api.Queries
|
|||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public byte[] Scan { get; set; }
|
public byte[] Scan { get; set; }
|
||||||
public DocumentType Type { get; set; }
|
public DocumentType Type { get; set; }
|
||||||
|
|
||||||
|
public class Validator : AbstractValidator<DocumentPublishRequest>
|
||||||
|
{
|
||||||
|
public Validator()
|
||||||
|
{
|
||||||
|
RuleFor(document => document.Scan).NotEmpty();
|
||||||
|
RuleFor(document => document.Type).NotEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,15 +0,0 @@
|
|||||||
using FluentValidation;
|
|
||||||
using InternshipSystem.Api.Queries;
|
|
||||||
using InternshipSystem.Core;
|
|
||||||
|
|
||||||
namespace InternshipSystem.Api.Validators
|
|
||||||
{
|
|
||||||
public class DocumentPublishRequestValidator : AbstractValidator<DocumentPublishRequest>
|
|
||||||
{
|
|
||||||
public DocumentPublishRequestValidator()
|
|
||||||
{
|
|
||||||
RuleFor(document => document.Scan).NotEmpty();
|
|
||||||
RuleFor(document => document.Type).NotEmpty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,8 +5,4 @@
|
|||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="AutoMapper" Version="10.0.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
Reference in New Issue
Block a user