Skip to content

Commit

Permalink
[DMS-428] Refactor Configuration Service Frontend (#355)
Browse files Browse the repository at this point in the history
* Move model classes to datamodel project

* Move models to folder

* Remove unused package
  • Loading branch information
simpat-adam authored Nov 21, 2024
1 parent d7e9319 commit 89f34f9
Show file tree
Hide file tree
Showing 43 changed files with 248 additions and 219 deletions.
4 changes: 2 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.32.0.97167" />
<PackageVersion Include="JsonSchema.Net" Version="7.2.2" />
<PackageVersion Include="JsonPath.Net" Version="1.1.6" />
<PackageVersion Include="FluentValidation" Version="11.10.0" />
<PackageVersion Include="FluentValidation" Version="11.11.0" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
</ItemGroup>
<!-- Testing Packages -->
Expand All @@ -62,4 +62,4 @@
<PackageVersion Include="Reqnroll.NUnit" Version="2.1.0" />
<PackageVersion Include="Testcontainers" Version="3.10.0" />
</ItemGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions src/config/EdFi.DmsConfigurationService.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdFi.DmsConfigurationServic
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "datamodel", "datamodel", "{F90FF019-91D3-462E-94A4-96B52681DB16}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EdFi.DmsConfigurationService.DataModel", "datamodel\EdFi.DmsConfigurationService.DataModel\EdFi.DmsConfigurationService.DataModel.csproj", "{E97DCC9F-C27F-497D-94FE-3DD39038C38B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdFi.DmsConfigurationService.DataModel", "datamodel\EdFi.DmsConfigurationService.DataModel\EdFi.DmsConfigurationService.DataModel.csproj", "{E97DCC9F-C27F-497D-94FE-3DD39038C38B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EdFi.DmsConfigurationService.Backend.Postgresql.Test.Integration", "backend\EdFi.DmsConfigurationService.Backend.Postgresql.Test.Integration\EdFi.DmsConfigurationService.Backend.Postgresql.Test.Integration.csproj", "{EE23DFFB-C61D-48FE-B821-2442D67D7AF9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdFi.DmsConfigurationService.Backend.Postgresql.Test.Integration", "backend\EdFi.DmsConfigurationService.Backend.Postgresql.Test.Integration\EdFi.DmsConfigurationService.Backend.Postgresql.Test.Integration.csproj", "{EE23DFFB-C61D-48FE-B821-2442D67D7AF9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using EdFi.DmsConfigurationService.Backend.Postgresql.Repositories;
using EdFi.DmsConfigurationService.Backend.Repositories;
using EdFi.DmsConfigurationService.DataModel;
using EdFi.DmsConfigurationService.DataModel.Application;
using EdFi.DmsConfigurationService.DataModel.Vendor;
using EdFi.DmsConfigurationService.DataModel.Model.Application;
using EdFi.DmsConfigurationService.DataModel.Model.Vendor;
using FluentAssertions;
using Microsoft.Extensions.Logging.Abstractions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using EdFi.DmsConfigurationService.Backend.Postgresql.Repositories;
using EdFi.DmsConfigurationService.Backend.Repositories;
using EdFi.DmsConfigurationService.DataModel;
using EdFi.DmsConfigurationService.DataModel.Vendor;
using EdFi.DmsConfigurationService.DataModel.Model.Vendor;
using FluentAssertions;
using Microsoft.Extensions.Logging.Abstractions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Dapper;
using EdFi.DmsConfigurationService.Backend.Repositories;
using EdFi.DmsConfigurationService.DataModel;
using EdFi.DmsConfigurationService.DataModel.Application;
using EdFi.DmsConfigurationService.DataModel.Model.Application;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Npgsql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using Dapper;
using EdFi.DmsConfigurationService.Backend.Repositories;
using EdFi.DmsConfigurationService.DataModel;
using EdFi.DmsConfigurationService.DataModel.Application;
using EdFi.DmsConfigurationService.DataModel.Vendor;
using EdFi.DmsConfigurationService.DataModel.Model.Application;
using EdFi.DmsConfigurationService.DataModel.Model.Vendor;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Npgsql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// See the LICENSE and NOTICES files in the project root for more information.

using EdFi.DmsConfigurationService.DataModel;
using EdFi.DmsConfigurationService.DataModel.Application;
using EdFi.DmsConfigurationService.DataModel.Model.Application;

namespace EdFi.DmsConfigurationService.Backend.Repositories;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// See the LICENSE and NOTICES files in the project root for more information.

using EdFi.DmsConfigurationService.DataModel;
using EdFi.DmsConfigurationService.DataModel.Application;
using EdFi.DmsConfigurationService.DataModel.Vendor;
using EdFi.DmsConfigurationService.DataModel.Model.Application;
using EdFi.DmsConfigurationService.DataModel.Model.Vendor;

namespace EdFi.DmsConfigurationService.Backend.Repositories;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentValidation" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using System.Diagnostics;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Nodes;
using FluentValidation.Results;
using Npgsql.Internal;

namespace EdFi.DmsConfigurationService.Frontend.AspNetCore.Infrastructure;

internal static class FailureResponse
public static class FailureResponse
{
private static readonly JsonSerializerOptions _serializerOptions =
new() { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using FluentValidation;

namespace EdFi.DmsConfigurationService.Frontend.AspNetCore.Infrastructure;
namespace EdFi.DmsConfigurationService.DataModel.Infrastructure;

public static class ValidatorExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using System.Text.Json.Serialization;

namespace EdFi.DmsConfigurationService.Frontend.AspNetCore.Model;
namespace EdFi.DmsConfigurationService.DataModel.Model.Action;

public class AdminAction
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

namespace EdFi.DmsConfigurationService.DataModel.Application;
namespace EdFi.DmsConfigurationService.DataModel.Model.Application;

public class ApiClientInsertCommand
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

namespace EdFi.DmsConfigurationService.DataModel.Application;
namespace EdFi.DmsConfigurationService.DataModel.Model.Application;

public class ApplicationCredentialsResponse
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

namespace EdFi.DmsConfigurationService.DataModel.Application;
using FluentValidation;

namespace EdFi.DmsConfigurationService.DataModel.Model.Application;

public class ApplicationInsertCommand
{
public string ApplicationName { get; set; } = "";
public long VendorId { get; set; }
public string ClaimSetName { get; set; } = "";
public long[] EducationOrganizationIds { get; set; } = [];

public class Validator : AbstractValidator<ApplicationInsertCommand>
{
public Validator()
{
RuleFor(a => a.ApplicationName).NotEmpty().MaximumLength(256);
RuleFor(a => a.ClaimSetName).NotEmpty().MaximumLength(256);
RuleForEach(a => a.EducationOrganizationIds).NotNull().GreaterThan(0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

namespace EdFi.DmsConfigurationService.DataModel.Application;
namespace EdFi.DmsConfigurationService.DataModel.Model.Application;

public class ApplicationResponse
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

namespace EdFi.DmsConfigurationService.DataModel.Application;
using FluentValidation;

namespace EdFi.DmsConfigurationService.DataModel.Model.Application;

public class ApplicationUpdateCommand
{
Expand All @@ -12,4 +14,15 @@ public class ApplicationUpdateCommand
public long VendorId { get; set; }
public required string ClaimSetName { get; set; }
public long[] EducationOrganizationIds { get; set; } = [];

public class Validator : AbstractValidator<ApplicationUpdateCommand>
{
public Validator()
{
RuleFor(a => a.Id).GreaterThan(0);
RuleFor(a => a.ApplicationName).NotEmpty().MaximumLength(256);
RuleFor(a => a.ClaimSetName).NotEmpty().MaximumLength(256);
RuleForEach(a => a.EducationOrganizationIds).NotNull().GreaterThan(0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
// See the LICENSE and NOTICES files in the project root for more information.

using System.Text.RegularExpressions;
using EdFi.DmsConfigurationService.Backend.Repositories;
using FluentValidation;

namespace EdFi.DmsConfigurationService.Frontend.AspNetCore.Model;
namespace EdFi.DmsConfigurationService.DataModel.Model.Register;

public class RegisterRequest
{
Expand All @@ -17,12 +16,8 @@ public class RegisterRequest

public class Validator : AbstractValidator<RegisterRequest>
{
private readonly IClientRepository _clientRepository;

public Validator(IClientRepository clientRepository)
public Validator()
{
_clientRepository = clientRepository;

RuleFor(m => m.ClientId).NotEmpty();
RuleFor(m => m.ClientSecret).NotEmpty();
RuleFor(m => m.ClientSecret)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using FluentValidation;

namespace EdFi.DmsConfigurationService.Frontend.AspNetCore.Model;
namespace EdFi.DmsConfigurationService.DataModel.Model.Token;

public class TokenRequest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using System.Text.Json.Serialization;

namespace EdFi.DmsConfigurationService.Frontend.AspNetCore.Model;
namespace EdFi.DmsConfigurationService.DataModel.Model.Token;

public class TokenResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: Apache-2.0
// Licensed to the Ed-Fi Alliance under one or more agreements.
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using FluentValidation;

namespace EdFi.DmsConfigurationService.DataModel.Model.Vendor;

public class VendorInsertCommand
{
public string Company { get; set; } = "";
public string ContactName { get; set; } = "";
public string ContactEmailAddress { get; set; } = "";
public string NamespacePrefixes { get; set; } = "";

public class Validator : AbstractValidator<VendorInsertCommand>
{
public Validator()
{
RuleFor(v => v.Company).NotEmpty().MaximumLength(256);
RuleFor(v => v.ContactName).NotEmpty().MaximumLength(128);
RuleFor(v => v.ContactEmailAddress).NotEmpty().EmailAddress().MaximumLength(320);
RuleFor(v => v.NamespacePrefixes)
.NotEmpty()
.Must(s =>
{
var split = s?.Split(
',',
StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries
);
return split != null && !split.Any(x => x.Length >= 128);
})
.WithMessage("Each NamespacePrefix length must be 128 characters or fewer.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

namespace EdFi.DmsConfigurationService.DataModel.Vendor;
namespace EdFi.DmsConfigurationService.DataModel.Model.Vendor;

public class VendorResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: Apache-2.0
// Licensed to the Ed-Fi Alliance under one or more agreements.
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using FluentValidation;

namespace EdFi.DmsConfigurationService.DataModel.Model.Vendor;

public class VendorUpdateCommand : VendorInsertCommand
{
public long Id { get; set; }

public new class Validator : AbstractValidator<VendorUpdateCommand>
{
public Validator()
{
RuleFor(v => v.Company).NotEmpty().MaximumLength(256);
RuleFor(v => v.ContactName).MaximumLength(128);
RuleFor(v => v.ContactEmailAddress).EmailAddress().MaximumLength(320);
RuleFor(v => v.NamespacePrefixes)
.NotEmpty()
.Must(s =>
{
var split = s?.Split(
',',
StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries
);
return split != null && !split.Any(x => x.Length >= 128);
})
.WithMessage("Each NamespacePrefix length must be 128 characters or fewer.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

namespace EdFi.DmsConfigurationService.Frontend.AspNetCore.Infrastructure;
namespace EdFi.DmsConfigurationService.DataModel;

public static class SecurityConstants
{
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 89f34f9

Please sign in to comment.