make proper result type for update (#67)
make proper result type for update Co-authored-by: MaxchilKH <m.w.bohdanowicz@gmail.com>
This commit is contained in:
parent
6e7bdb72af
commit
df1834d325
@ -71,11 +71,11 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await useCase.UpdateInternshipRegistration(registrationCommand, cancellationToken);
|
var (status, result) = await useCase.UpdateInternshipRegistration(registrationCommand, cancellationToken);
|
||||||
|
|
||||||
await _context.SaveChangesAsync(cancellationToken);
|
await _context.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
return Ok(result);
|
return new JsonResult(new {Status = status, Errors = result});
|
||||||
}
|
}
|
||||||
catch (ArgumentException e)
|
catch (ArgumentException e)
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,7 @@ namespace InternshipSystem.Api.UseCases
|
|||||||
subjectRegistration = internshipRegistration;
|
subjectRegistration = internshipRegistration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> UpdateInternshipRegistration(
|
public async Task<(DocumentState State, IEnumerable<string>)> UpdateInternshipRegistration(
|
||||||
UpdateRegistrationForm registrationCommand,
|
UpdateRegistrationForm registrationCommand,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
@ -31,8 +31,12 @@ namespace InternshipSystem.Core
|
|||||||
{
|
{
|
||||||
public Validator()
|
public Validator()
|
||||||
{
|
{
|
||||||
RuleFor(x => x.Nip).NotNull();
|
RuleFor(x => x.Nip)
|
||||||
RuleFor(x => x.Name).NotNull();
|
.NotEmpty()
|
||||||
|
.WithMessage("error.company.nip.empty");
|
||||||
|
RuleFor(x => x.Name)
|
||||||
|
.NotEmpty()
|
||||||
|
.WithMessage("error.company.name.empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using InternshipSystem.Core.UglyOrmArtifacts;
|
using InternshipSystem.Core.UglyOrmArtifacts;
|
||||||
@ -26,7 +27,7 @@ namespace InternshipSystem.Core.Entity.Internship
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string ValidateStatus(Edition edition)
|
public (DocumentState State, IEnumerable<string>) ValidateStatus(Edition edition)
|
||||||
{
|
{
|
||||||
var validator = new Validator(edition);
|
var validator = new Validator(edition);
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ namespace InternshipSystem.Core.Entity.Internship
|
|||||||
|
|
||||||
State = result.IsValid ? DocumentState.Submitted : DocumentState.Draft;
|
State = result.IsValid ? DocumentState.Submitted : DocumentState.Draft;
|
||||||
|
|
||||||
return result.ToString();
|
return (State, result.Errors.Select(failure => failure.ToString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Validator : AbstractValidator<InternshipRegistration>
|
public class Validator : AbstractValidator<InternshipRegistration>
|
||||||
@ -52,18 +53,25 @@ namespace InternshipSystem.Core.Entity.Internship
|
|||||||
.NotNull();
|
.NotNull();
|
||||||
RuleFor(x => x.Subjects)
|
RuleFor(x => x.Subjects)
|
||||||
.NotEmpty()
|
.NotEmpty()
|
||||||
.Must(s => edition.AreSubjectsAvailable(s.Select(su => su.InternshipSubjectId)));
|
.Must(s => edition.AreSubjectsAvailable(s.Select(su => su.InternshipSubjectId)))
|
||||||
|
.WithMessage("error.subjects.not_available");
|
||||||
RuleFor(x => x.Type)
|
RuleFor(x => x.Type)
|
||||||
.NotNull()
|
.NotNull()
|
||||||
.Must(edition.IsTypeAvailable);
|
.Must(edition.IsTypeAvailable)
|
||||||
|
.WithMessage("error.type.not_available");
|
||||||
RuleFor(x => x.Start)
|
RuleFor(x => x.Start)
|
||||||
.GreaterThanOrEqualTo(edition.EditionStart)
|
.GreaterThanOrEqualTo(edition.EditionStart)
|
||||||
.LessThan(x => x.End)
|
.LessThan(x => x.End)
|
||||||
.NotEmpty();
|
.NotEmpty()
|
||||||
|
.WithMessage("error.start_date.empty");
|
||||||
RuleFor(x => x.End)
|
RuleFor(x => x.End)
|
||||||
.LessThanOrEqualTo(edition.EditionFinish)
|
.LessThanOrEqualTo(edition.EditionFinish)
|
||||||
.GreaterThan(x => x.Start)
|
.GreaterThan(x => x.Start)
|
||||||
.NotEmpty();
|
.NotEmpty()
|
||||||
|
.WithMessage("error.end_date.empty");
|
||||||
|
RuleFor(x => x.DeclaredHours)
|
||||||
|
.NotEmpty()
|
||||||
|
.WithMessage("error.declared_hours.empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,15 +16,20 @@ namespace InternshipSystem.Core
|
|||||||
public Validator()
|
public Validator()
|
||||||
{
|
{
|
||||||
RuleFor(x => x.Country)
|
RuleFor(x => x.Country)
|
||||||
.NotEmpty();
|
.NotEmpty()
|
||||||
|
.WithMessage("error.branch.country.empty");
|
||||||
RuleFor(x => x.City)
|
RuleFor(x => x.City)
|
||||||
.NotEmpty();
|
.NotEmpty()
|
||||||
|
.WithMessage("error.branch.city.empty");
|
||||||
RuleFor(x => x.PostalCode)
|
RuleFor(x => x.PostalCode)
|
||||||
.NotEmpty();
|
.NotEmpty()
|
||||||
|
.WithMessage("error.branch.postal_code.empty");
|
||||||
RuleFor(x => x.Street)
|
RuleFor(x => x.Street)
|
||||||
.NotEmpty();
|
.NotEmpty()
|
||||||
|
.WithMessage("error.branch.street.empty");
|
||||||
RuleFor(x => x.Building)
|
RuleFor(x => x.Building)
|
||||||
.NotEmpty();
|
.NotEmpty()
|
||||||
|
.WithMessage("error.branch.building.empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,17 @@ namespace InternshipSystem.Core
|
|||||||
public Validate()
|
public Validate()
|
||||||
{
|
{
|
||||||
RuleFor(x => x.FirstName)
|
RuleFor(x => x.FirstName)
|
||||||
.NotEmpty();
|
.NotEmpty()
|
||||||
|
.WithMessage("error.mentor.first_name.empty");
|
||||||
RuleFor(x => x.LastName)
|
RuleFor(x => x.LastName)
|
||||||
.NotEmpty();
|
.NotEmpty()
|
||||||
|
.WithMessage("error.mentor.last_name.empty");
|
||||||
RuleFor(x => x.Email)
|
RuleFor(x => x.Email)
|
||||||
.NotEmpty();
|
.NotEmpty()
|
||||||
|
.WithMessage("error.mentor.email.empty");
|
||||||
RuleFor(x => x.PhoneNumber)
|
RuleFor(x => x.PhoneNumber)
|
||||||
.NotEmpty();
|
.NotEmpty()
|
||||||
|
.WithMessage("error.mentor.phone_number.empty");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user