diff --git a/src/InternshipSystem.Api/UseCases/UpdateInternshipRegistrationUseCase.cs b/src/InternshipSystem.Api/UseCases/UpdateInternshipRegistrationUseCase.cs index 10e579c..9f68e67 100644 --- a/src/InternshipSystem.Api/UseCases/UpdateInternshipRegistrationUseCase.cs +++ b/src/InternshipSystem.Api/UseCases/UpdateInternshipRegistrationUseCase.cs @@ -30,7 +30,7 @@ namespace InternshipSystem.Api.UseCases subjectRegistration = internshipRegistration; } - public async Task<(DocumentState State, IEnumerable)> UpdateInternshipRegistration( + public async Task<(DocumentState State, IEnumerable)> UpdateInternshipRegistration( UpdateRegistrationForm registrationCommand, CancellationToken cancellationToken) { diff --git a/src/InternshipSystem.Core/Entity/Internship/Extensions.cs b/src/InternshipSystem.Core/Entity/Internship/Extensions.cs new file mode 100644 index 0000000..4aa0001 --- /dev/null +++ b/src/InternshipSystem.Core/Entity/Internship/Extensions.cs @@ -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 ToErrorDescription(this ValidationResult result) + { + return result.Errors.Select(failure => new ErrorDescription { Key = failure.ErrorCode, Parameters = failure.FormattedMessagePlaceholderValues }); + } + } +} \ No newline at end of file diff --git a/src/InternshipSystem.Core/Entity/Internship/InternshipRegistration.cs b/src/InternshipSystem.Core/Entity/Internship/InternshipRegistration.cs index 595ab71..119075c 100644 --- a/src/InternshipSystem.Core/Entity/Internship/InternshipRegistration.cs +++ b/src/InternshipSystem.Core/Entity/Internship/InternshipRegistration.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; using FluentValidation; +using FluentValidation.Results; using InternshipSystem.Core.UglyOrmArtifacts; namespace InternshipSystem.Core.Entity.Internship @@ -27,7 +28,7 @@ namespace InternshipSystem.Core.Entity.Internship } - public (DocumentState State, IEnumerable) ValidateStatus(Edition edition) + public (DocumentState State, IEnumerable) ValidateStatus(Edition edition) { var validator = new Validator(edition); @@ -35,7 +36,7 @@ namespace InternshipSystem.Core.Entity.Internship State = result.IsValid ? DocumentState.Submitted : DocumentState.Draft; - return (State, result.Errors.Select(failure => failure.ToString())); + return (State, result.ToErrorDescription()); } public class Validator : AbstractValidator @@ -75,4 +76,10 @@ namespace InternshipSystem.Core.Entity.Internship } } } + + public class ErrorDescription + { + public string Key { get; set; } + public Dictionary Parameters { get; set; } + } } \ No newline at end of file