-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add remove portal endpoint (#713)
Co-authored-by: Jossilainen <[email protected]>
- Loading branch information
1 parent
1587844
commit 73b2e3f
Showing
13 changed files
with
204 additions
and
19 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,5 @@ | ||
|
||
--- | ||
"fusion-project-portal": patch | ||
--- | ||
Added endpoint to delete a portal |
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
50 changes: 50 additions & 0 deletions
50
...r.ProjectExecutionPortal.Application/Commands/Portals/RemovePortal/RemovePortalCommand.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,50 @@ | ||
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.RemovePortal | ||
{ | ||
public class RemovePortalCommand : IRequest | ||
{ | ||
public RemovePortalCommand(Guid id) | ||
{ | ||
Id = id; | ||
} | ||
|
||
public Guid Id { get; } | ||
|
||
public class Handler : IRequestHandler<RemovePortalCommand> | ||
{ | ||
private readonly IReadWriteContext _context; | ||
|
||
public Handler(IReadWriteContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task Handle(RemovePortalCommand command, CancellationToken cancellationToken) | ||
{ | ||
var entity = await _context.Set<Portal>() | ||
.Include(x => x.Apps) | ||
.FirstOrDefaultAsync(portal => portal.Id == command.Id, cancellationToken); | ||
|
||
if (entity == null) | ||
{ | ||
throw new NotFoundException(nameof(Portal), command.Id); | ||
} | ||
|
||
if (entity.Apps.Any()) | ||
{ | ||
throw new InvalidOperationException("Cannot remove Portal, portal has onboarded apps"); | ||
} | ||
|
||
_context.Set<Portal>().Remove(entity); | ||
|
||
await _context.SaveChangesAsync(cancellationToken); | ||
|
||
} | ||
} | ||
} | ||
} |
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
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
13 changes: 13 additions & 0 deletions
13
...end/src/Equinor.ProjectExecutionPortal.WebApi/ViewModels/Portal/ApiRemovePortalRequest.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,13 @@ | ||
using Equinor.ProjectExecutionPortal.Application.Commands.Portals.RemovePortal; | ||
|
||
namespace Equinor.ProjectExecutionPortal.WebApi.ViewModels.Portal | ||
{ | ||
public class ApiRemovePortalRequest | ||
{ | ||
public RemovePortalCommand ToCommand(Guid id) | ||
{ | ||
return new RemovePortalCommand(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
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
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