Skip to content

Commit

Permalink
fix review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Jul 16, 2024
1 parent 5b1d7cb commit 0c75148
Show file tree
Hide file tree
Showing 18 changed files with 1,487 additions and 2,126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Org.Eclipse.TractusX.Portal.Backend.Framework.Async;
using Org.Eclipse.TractusX.Portal.Backend.Framework.DateTimeProvider;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Linq;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Web;
using Org.Eclipse.TractusX.Portal.Backend.IssuerComponent.Library.BusinessLogic;
Expand Down Expand Up @@ -249,17 +250,19 @@ public async Task CreateCompanyCertificate(CompanyCertificateCreationData data,
throw new ControllerArgumentException("ExternalCertificateNumber must be alphanumeric and length should not be greater than 36");
}

if (data.Sites != null && data.Sites.Any() && data.Sites!.Any(bpn => !BpnsRegex.IsMatch(bpn)))
if (data.Sites != null && data.Sites.Any(bpn => !BpnsRegex.IsMatch(bpn)))
{
throw new ControllerArgumentException("BPN must contain exactly 16 characters and must be prefixed with BPNS");
}

if (data.ValidFrom?.ToUniversalTime() > DateTimeOffset.Now.ToUniversalTime())
var now = dateTimeProvider.OffsetNow;

if (data.ValidFrom > now)
{
throw new ControllerArgumentException("ValidFrom date should not be greater than current date");
}

if (data.ValidTill?.ToUniversalTime() < DateTimeOffset.Now.ToUniversalTime())
if (data.ValidTill < now)
{
throw new ControllerArgumentException("ValidTill date should be greater than current date");
}
Expand Down Expand Up @@ -305,14 +308,11 @@ private async Task HandleCompanyCertificateCreationAsync(CompanyCertificateTypeI
{
x.ExternalCertificateNumber = externalCertificateNumber;
x.Issuer = issuer;
x.ValidTill = validTill?.ToUniversalTime();
x.ValidFrom = validFrom?.ToUniversalTime();
x.ValidFrom = validFrom;
x.ValidTill = validTill;
});

if (sites != null && sites.Any())
{
companyCertificateRepository.CreateCompanyCertificateAssignedSites(companyCertificate.Id, sites);
}
sites?.IfAny(x => companyCertificateRepository.CreateCompanyCertificateAssignedSites(companyCertificate.Id, x));

await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Task<bool> CheckCompanyCertificateType(CompanyCertificateTypeId certifica
/// <inheritdoc />
public CompanyCertificate CreateCompanyCertificate(Guid companyId, CompanyCertificateTypeId companyCertificateTypeId, Guid docId, Action<CompanyCertificate>? setOptionalFields = null)
{
var companyCertificate = new CompanyCertificate(Guid.NewGuid(), DateTimeOffset.UtcNow, companyCertificateTypeId, CompanyCertificateStatusId.ACTIVE, companyId, docId);
var companyCertificate = new CompanyCertificate(Guid.NewGuid(), companyCertificateTypeId, CompanyCertificateStatusId.ACTIVE, companyId, docId);
setOptionalFields?.Invoke(companyCertificate);
return _context.CompanyCertificates.Add(companyCertificate).Entity;
}
Expand All @@ -71,7 +71,7 @@ public IAsyncEnumerable<CompanyCertificateBpnData> GetCompanyCertificateData(Gui
ccb.ValidFrom,
ccb.ValidTill,
ccb.ExternalCertificateNumber,
ccb.CompaniesCertificateAssignedSites.Select(x => x.Sites),
ccb.CompanyCertificateAssignedSites.Select(x => x.Site),
ccb.Issuer,
ccb.Validator))
.ToAsyncEnumerable();
Expand Down Expand Up @@ -102,7 +102,7 @@ public IAsyncEnumerable<CompanyCertificateBpnData> GetCompanyCertificateData(Gui
companyCertificate.ValidFrom,
companyCertificate.ValidTill,
companyCertificate.ExternalCertificateNumber,
companyCertificate.CompaniesCertificateAssignedSites.Select(x => x.Sites),
companyCertificate.CompanyCertificateAssignedSites.Select(x => x.Site),
companyCertificate.Issuer,
companyCertificate.Validator
))
Expand All @@ -128,7 +128,7 @@ public IAsyncEnumerable<CompanyCertificateBpnData> GetCompanyCertificateData(Gui

public void AttachAndModifyCompanyCertificateDetails(Guid id, Action<CompanyCertificate>? initialize, Action<CompanyCertificate> updateFields)
{
var entity = new CompanyCertificate(id, default, default, default, Guid.Empty, Guid.Empty);
var entity = new CompanyCertificate(id, default, default, Guid.Empty, Guid.Empty);
initialize?.Invoke(entity);
_context.Attach(entity);
updateFields.Invoke(entity);
Expand All @@ -151,5 +151,5 @@ public void AttachAndModifyCompanyCertificateDocumentDetails(Guid id, Action<Doc
.SingleOrDefaultAsync();

public void CreateCompanyCertificateAssignedSites(Guid companyCertificateId, IEnumerable<string> sites) =>
_context.AddRange(sites.Select(companyCertificateAssignedSite => new CompaniesCertificateAssignedSite(companyCertificateId, companyCertificateAssignedSite)));
_context.AddRange(sites.Select(companyCertificateAssignedSite => new CompanyCertificateAssignedSite(companyCertificateId, companyCertificateAssignedSite)));
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
********************************************************************************/

using Microsoft.EntityFrameworkCore.Migrations;
using System;

#nullable disable

Expand Down
Loading

0 comments on commit 0c75148

Please sign in to comment.