-
Notifications
You must be signed in to change notification settings - Fork 16
Add Customer Deletion with Confirmation Dialog #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
7
commits into
main
Choose a base branch
from
copilot/fix-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,943
−6
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f1ab653
Initial plan for issue
Copilot 97d8309
Add customer deletion functionality
Copilot 2c823bb
Update navigation after customer deletion to use absolute path
Copilot d6a1da5
Update navigation to use relative paths with ActivatedRoute
Copilot 2ffa42a
fix: use relative navigation with ActivatedRoute
Copilot ceb2633
Extended Playwright test to include customer deletion
Copilot d96f675
Revert package-lock.json and delete DeleteCustomerTests.cs
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,24 @@ | ||
| .actions { | ||
| display: flex; | ||
| gap: 10px; | ||
| margin-bottom: 20px; | ||
| } | ||
|
|
||
| .confirmation-dialog { | ||
| border: 1px solid #ccc; | ||
| padding: 15px; | ||
| margin: 10px 0; | ||
| background-color: #f9f9f9; | ||
| border-radius: 5px; | ||
| } | ||
|
|
||
| .confirmation-actions { | ||
| display: flex; | ||
| gap: 10px; | ||
| margin-top: 10px; | ||
| } | ||
|
|
||
| .error { | ||
| color: red; | ||
| margin-top: 10px; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
77 changes: 77 additions & 0 deletions
77
Sandbox.Modules.CustomerManagement.Tests/DeleteCustomerTests.cs
This file contains hidden or 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,77 @@ | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Http.HttpResults; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Sandbox.Modules.CustomerManagement.Application; | ||
| using Sandbox.Modules.CustomerManagement.Data; | ||
| using Sandbox.Modules.CustomerManagement.Domain; | ||
| using Sandbox.SharedKernel.StronglyTypedIds; | ||
| using Wolverine.EntityFrameworkCore; | ||
|
|
||
| namespace Sandbox.Modules.CustomerManagement.Tests; | ||
|
|
||
| internal sealed class DeleteCustomerTests | ||
| { | ||
| [Test] | ||
| public async Task Handle_deletes_customer_when_exists() | ||
| { | ||
| // Arrange | ||
| var customerId = CustomerId.New(); | ||
| var customer = Customer.Create(customerId, FullName.From("John", "Doe")); | ||
|
|
||
| var dbContextOptions = new DbContextOptionsBuilder<CustomerDbContext>() | ||
| .UseInMemoryDatabase("DeleteCustomerTest") | ||
| .Options; | ||
|
|
||
| await using var dbContext = new CustomerDbContext(dbContextOptions); | ||
| await dbContext.AddAsync(customer); | ||
| await dbContext.SaveChangesAsync(); | ||
|
|
||
| var serviceProvider = new ServiceCollection() | ||
| .AddDbContext<CustomerDbContext>(options => options.UseInMemoryDatabase("DeleteCustomerTest")) | ||
| .AddWolverine(options => options.UseEntityFrameworkCoreTransactions()) | ||
| .BuildServiceProvider(); | ||
|
|
||
| var httpContext = new DefaultHttpContext | ||
| { | ||
| RequestServices = serviceProvider, | ||
| }; | ||
|
|
||
| // Act | ||
| var result = await DeleteCustomer.Handle(customerId, httpContext, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| await Assert.That(result).IsInstanceOf<NoContent>(); | ||
|
|
||
| await using var verifyContext = new CustomerDbContext(dbContextOptions); | ||
| var customerExists = await verifyContext.Set<Customer>().AnyAsync(c => c.Id == customerId); | ||
| await Assert.That(customerExists).IsFalse(); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Handle_returns_not_found_when_customer_does_not_exist() | ||
| { | ||
| // Arrange | ||
| var customerId = CustomerId.New(); | ||
|
|
||
| var dbContextOptions = new DbContextOptionsBuilder<CustomerDbContext>() | ||
| .UseInMemoryDatabase("DeleteCustomerNotFoundTest") | ||
| .Options; | ||
|
|
||
| var serviceProvider = new ServiceCollection() | ||
| .AddDbContext<CustomerDbContext>(options => options.UseInMemoryDatabase("DeleteCustomerNotFoundTest")) | ||
| .AddWolverine(options => options.UseEntityFrameworkCoreTransactions()) | ||
| .BuildServiceProvider(); | ||
|
|
||
| var httpContext = new DefaultHttpContext | ||
| { | ||
| RequestServices = serviceProvider, | ||
| }; | ||
|
|
||
| // Act | ||
| var result = await DeleteCustomer.Handle(customerId, httpContext, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| await Assert.That(result).IsInstanceOf<NotFound>(); | ||
| } | ||
| } | ||
42 changes: 42 additions & 0 deletions
42
Sandbox.Modules.CustomerManagement/Application/DeleteCustomer.cs
This file contains hidden or 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,42 @@ | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Http.HttpResults; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Sandbox.Modules.CustomerManagement.Data; | ||
| using Sandbox.SharedKernel.StronglyTypedIds; | ||
| using Wolverine.EntityFrameworkCore; | ||
|
|
||
| namespace Sandbox.Modules.CustomerManagement.Application; | ||
|
|
||
| public static class DeleteCustomer | ||
| { | ||
| /// <summary> | ||
| /// Delete an existing customer. | ||
| /// </summary> | ||
| /// <returns>No content if successful.</returns> | ||
| public static async Task<Results<NoContent, NotFound>> Handle( | ||
| CustomerId customerId, | ||
| HttpContext httpContext, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(customerId); | ||
| ArgumentNullException.ThrowIfNull(httpContext); | ||
|
|
||
| // TODO: Should be injected, but this is a workaround for https://github.com/dotnet/aspnetcore/issues/61388 | ||
| var outbox = httpContext.RequestServices.GetRequiredService<IDbContextOutbox<CustomerDbContext>>(); | ||
| ArgumentNullException.ThrowIfNull(outbox); | ||
|
|
||
| var customer = await outbox.DbContext.Set<Domain.Customer>() | ||
| .FirstOrDefaultAsync(c => c.Id == customerId, cancellationToken); | ||
|
|
||
| if (customer == null) | ||
| { | ||
| return TypedResults.NotFound(); | ||
| } | ||
|
|
||
| outbox.DbContext.Remove(customer); | ||
| await outbox.SaveChangesAndFlushMessagesAsync(cancellationToken); | ||
|
|
||
| return TypedResults.NoContent(); | ||
| } | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot delete these tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've deleted the DeleteCustomerTests.cs file as requested. Commit: d96f675