-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Configuration to Portal domain (#725)
- Loading branch information
Showing
21 changed files
with
743 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
"fusion-project-portal": minor | ||
--- | ||
|
||
feat: add Configuration to Portal domain | ||
|
||
To enable the configuration of pages such as the project page, facility page, and root page, it should be possible to add a route configuration to the portal. | ||
|
||
A configuration model as been added, currently only with a router property (but designed to be exteded if needed in the future) | ||
|
||
The following endpoints has been added: | ||
|
||
- GET /portal/ID/configuration | ||
- PUT /portal/ID/configuration | ||
|
||
In addition the data is now included in the following endpoint: | ||
|
||
- GET /portal/ID | ||
|
||
> [!IMPORTANT] | ||
> This change requires database migration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...pplication/Commands/Portals/UpdatePortalConfiguration/UpdatePortalConfigurationCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Equinor.ProjectExecutionPortal.Domain.Common.Exceptions; | ||
using Equinor.ProjectExecutionPortal.Domain.Entities; | ||
using Equinor.ProjectExecutionPortal.Infrastructure; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Equinor.ProjectExecutionPortal.Application.Commands.Portals.UpdatePortalConfiguration; | ||
|
||
public class UpdatePortalConfigurationCommand : IRequest<Guid> | ||
{ | ||
public UpdatePortalConfigurationCommand(Guid portalId, string? router) | ||
{ | ||
PortalId = portalId; | ||
Router = router; | ||
} | ||
|
||
public Guid PortalId { get; } | ||
public string? Router { get; } | ||
|
||
public class Handler : IRequestHandler<UpdatePortalConfigurationCommand, Guid> | ||
{ | ||
private readonly IReadWriteContext _readWriteContext; | ||
|
||
public Handler(IReadWriteContext readWriteContext) | ||
{ | ||
_readWriteContext = readWriteContext; | ||
} | ||
|
||
public async Task<Guid> Handle(UpdatePortalConfigurationCommand command, CancellationToken cancellationToken) | ||
{ | ||
var entity = await _readWriteContext.Set<Portal>() | ||
.Include(portal => portal.Configuration) | ||
.FirstOrDefaultAsync(portal => portal.Id == command.PortalId, cancellationToken); | ||
|
||
if (entity == null) | ||
{ | ||
throw new NotFoundException(nameof(PortalConfiguration), command.PortalId); | ||
} | ||
|
||
entity.Configuration.Update(command.Router); | ||
|
||
await _readWriteContext.SaveChangesAsync(cancellationToken); | ||
|
||
return entity.Id; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...nPortal.Application/Queries/Portals/GetPortalConfiguration/GetPortalConfigurationQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using AutoMapper; | ||
using Equinor.ProjectExecutionPortal.Domain.Entities; | ||
using Equinor.ProjectExecutionPortal.Domain.Infrastructure; | ||
using Equinor.ProjectExecutionPortal.Infrastructure; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Equinor.ProjectExecutionPortal.Application.Queries.Portals.GetPortalConfiguration; | ||
|
||
public class GetPortalConfigurationQuery : QueryBase<PortalConfigurationDto?> | ||
{ | ||
public GetPortalConfigurationQuery(Guid portalId) | ||
{ | ||
PortalId = portalId; | ||
} | ||
|
||
public Guid PortalId { get; } | ||
|
||
public class Handler : IRequestHandler<GetPortalConfigurationQuery, PortalConfigurationDto?> | ||
{ | ||
private readonly IReadWriteContext _readWriteContext; | ||
private readonly IMapper _mapper; | ||
|
||
public Handler(IReadWriteContext readWriteContext, IMapper mapper) | ||
{ | ||
_readWriteContext = readWriteContext; | ||
_mapper = mapper; | ||
} | ||
|
||
public async Task<PortalConfigurationDto?> Handle(GetPortalConfigurationQuery request, CancellationToken cancellationToken) | ||
{ | ||
var entity = await _readWriteContext.Set<PortalConfiguration>() | ||
.AsNoTracking() | ||
.FirstOrDefaultAsync(x => x.PortalId == request.PortalId, cancellationToken); | ||
|
||
var portal = _mapper.Map<PortalConfiguration?, PortalConfigurationDto?>(entity); | ||
|
||
return portal; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../src/Equinor.ProjectExecutionPortal.Application/Queries/Portals/PortalConfigurationDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Equinor.ProjectExecutionPortal.Application.Infrastructure.Mappings; | ||
|
||
namespace Equinor.ProjectExecutionPortal.Application.Queries.Portals | ||
{ | ||
public class PortalConfigurationDto : IMapFrom<Domain.Entities.PortalConfiguration> | ||
{ | ||
public Guid Id { get; set; } | ||
public string? Router { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
backend/src/Equinor.ProjectExecutionPortal.Domain/Entities/PortalConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Equinor.ProjectExecutionPortal.Domain.Common; | ||
using Equinor.ProjectExecutionPortal.Domain.Common.Audit; | ||
|
||
namespace Equinor.ProjectExecutionPortal.Domain.Entities; | ||
|
||
/// <summary> | ||
/// Each portal has their own configuration | ||
/// </summary> | ||
public class PortalConfiguration : AuditableEntityBase, ICreationAuditable, IModificationAuditable | ||
{ | ||
public const int RouterLengthMax = 8000; | ||
|
||
public PortalConfiguration(string? router) | ||
{ | ||
Router = router; | ||
} | ||
|
||
public string? Router { get; set; } | ||
|
||
public Guid PortalId { get; set; } | ||
public Portal Portal { get; set; } = null!; | ||
|
||
public void Update(string? router) | ||
{ | ||
Router = router; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...ctExecutionPortal.Infrastructure/EntityConfigurations/PortalConfigurationConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Equinor.ProjectExecutionPortal.Infrastructure.EntityConfigurations.Extensions; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Equinor.ProjectExecutionPortal.Infrastructure.EntityConfigurations; | ||
|
||
public class PortalConfigurationConfiguration : IEntityTypeConfiguration<Domain.Entities.PortalConfiguration> | ||
{ | ||
public void Configure(EntityTypeBuilder<Domain.Entities.PortalConfiguration> builder) | ||
{ | ||
builder.ConfigureCreationAudit(); | ||
builder.ConfigureModificationAudit(); | ||
|
||
builder.Property(t => t.Router) | ||
.HasMaxLength(Domain.Entities.PortalConfiguration.RouterLengthMax); | ||
} | ||
} |
Oops, something went wrong.