fix/fix #81
@ -30,7 +30,7 @@ namespace InternshipSystem.Api.UseCases
|
|||||||
subjectRegistration = internshipRegistration;
|
subjectRegistration = internshipRegistration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<(DocumentState State, IEnumerable<string>)> UpdateInternshipRegistration(
|
public async Task<(DocumentState State, IEnumerable<ErrorDescription>)> UpdateInternshipRegistration(
|
||||||
UpdateRegistrationForm registrationCommand,
|
UpdateRegistrationForm registrationCommand,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
15
src/InternshipSystem.Core/Entity/Internship/Extensions.cs
Normal file
15
src/InternshipSystem.Core/Entity/Internship/Extensions.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using FluentValidation.Results;
|
||||||
|
using InternshipSystem.Core.Entity.Internship;
|
||||||
|
|
||||||
|
namespace InternshipSystem.Core
|
||||||
|
{
|
||||||
|
static internal class Extensions
|
||||||
|
{
|
||||||
|
public static IEnumerable<ErrorDescription> ToErrorDescription(this ValidationResult result)
|
||||||
|
{
|
||||||
|
return result.Errors.Select(failure => new ErrorDescription { Key = failure.ErrorCode, Parameters = failure.FormattedMessagePlaceholderValues });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
using FluentValidation.Results;
|
||||||
using InternshipSystem.Core.UglyOrmArtifacts;
|
using InternshipSystem.Core.UglyOrmArtifacts;
|
||||||
|
|
||||||
namespace InternshipSystem.Core.Entity.Internship
|
namespace InternshipSystem.Core.Entity.Internship
|
||||||
@ -27,7 +28,7 @@ namespace InternshipSystem.Core.Entity.Internship
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public (DocumentState State, IEnumerable<string>) ValidateStatus(Edition edition)
|
public (DocumentState State, IEnumerable<ErrorDescription>) ValidateStatus(Edition edition)
|
||||||
{
|
{
|
||||||
var validator = new Validator(edition);
|
var validator = new Validator(edition);
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ namespace InternshipSystem.Core.Entity.Internship
|
|||||||
|
|
||||||
State = result.IsValid ? DocumentState.Submitted : DocumentState.Draft;
|
State = result.IsValid ? DocumentState.Submitted : DocumentState.Draft;
|
||||||
|
|
||||||
return (State, result.Errors.Select(failure => failure.ToString()));
|
return (State, result.ToErrorDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Validator : AbstractValidator<InternshipRegistration>
|
public class Validator : AbstractValidator<InternshipRegistration>
|
||||||
@ -75,4 +76,10 @@ namespace InternshipSystem.Core.Entity.Internship
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ErrorDescription
|
||||||
|
{
|
||||||
|
public string Key { get; set; }
|
||||||
|
public Dictionary<string, object> Parameters { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user