Skip to content

Commit

Permalink
Added Post Code validation for creating a SWMS project
Browse files Browse the repository at this point in the history
  • Loading branch information
Phalanx123 committed Jan 22, 2024
1 parent afe9388 commit 63eecad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 2 additions & 5 deletions SimpliClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ private ProblemDetails GenerateServerErrorProblemDetails(RestRequest request)
{ "address1", simpliProject.Address1 },
{ "suburb", simpliProject.Suburb },
{ "state", simpliProject.State.GetDescription() },
{ "country", simpliProject.Country.GetDescription() }
{ "country", simpliProject.Country.GetDescription() },
{"postcode", simpliProject.PostCode}
};
if (!string.IsNullOrWhiteSpace(simpliProject.Address2))
{
Expand All @@ -400,10 +401,6 @@ private ProblemDetails GenerateServerErrorProblemDetails(RestRequest request)
{
jsonBody.Add("code", simpliProject.Code);
}
if (!string.IsNullOrWhiteSpace(simpliProject.PostCode))
{
jsonBody.Add("postcode", simpliProject.PostCode);
}

request.AddJsonBody(jsonBody);

Expand Down
18 changes: 18 additions & 0 deletions Validation/SimpliProjectValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using FluentValidation;
using simpliBuild.SWMS.Model;

namespace simpliBuild.Validation;

public class SimpliProjectValidator : AbstractValidator<SimpliProject>
{
public SimpliProjectValidator()
{
// Validation rules here
RuleFor(project => project.Name).NotEmpty().WithMessage("Project name is required.");
RuleFor(project => project.Address1).NotEmpty().WithMessage("Project address is required.");
RuleFor(project => project.Suburb).NotEmpty().WithMessage("Project suburb is required.");
RuleFor(project => project.PostCode).NotEmpty().WithMessage("Project postcode is required.");
RuleFor(project => project.State).NotEmpty().WithMessage("Project state is required.");
RuleFor(project => project.Country).NotEmpty().WithMessage("Project country is required.");
}
}

0 comments on commit 63eecad

Please sign in to comment.