-
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(menu): add multi-request elevator control option
Introduces a new option for multi-request elevator control in the menu. The `MenuSelection` enum is updated to include `MultiElevatorControl`, and a new `ElevatorControlMultipleRequestScreen` is implemented to handle multiple elevator requests through user input. This enhances user functionality by allowing simultaneous requests for elevators.
- Loading branch information
1 parent
4d8e0ac
commit 10fa607
Showing
7 changed files
with
83 additions
and
21 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
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
65 changes: 65 additions & 0 deletions
65
src/Presentation/Screens/ElevatorControl/ElevatorControlMultipleRequestScreen.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,65 @@ | ||
using Application.Abstractions.Screen; | ||
using Application.Elevators.Request; | ||
using Domain.Common; | ||
using Infrastructure.Persistence.SeedData; | ||
using MediatR; | ||
using Presentation.Extensions; | ||
using Spectre.Console; | ||
|
||
namespace Presentation.Screens.ElevatorControl; | ||
|
||
public class ElevatorControlMultipleRequestScreen(IMediator mediator): IScreen<bool> | ||
{ | ||
public async Task<Result<bool>> ShowAsync(CancellationToken token) | ||
{ | ||
Result<Guid>? result = null; | ||
var anotherRequest = true; | ||
while (anotherRequest) | ||
{ | ||
AnsiConsole.Clear(); | ||
AnsiConsole.Write( | ||
new FigletText("Elevator Control") | ||
.LeftJustified() | ||
.Color(Color.Blue) | ||
); | ||
|
||
var floors = AnsiConsole.Prompt( | ||
new TextPrompt<string>("What floors are you going to? (comma separated)")); | ||
|
||
var buildingId = ApplicationDbContextSeedData.GetSeedBuildings().First()!.Id; | ||
await AnsiConsole.Status() | ||
.StartAsync("Requesting elevators...", async ctx => | ||
{ | ||
var floorRequests = floors.Split(',').Select(int.Parse).ToList(); | ||
foreach (int floorRequest in floorRequests.AsParallel()) | ||
{ | ||
var request = new RequestElevatorCommand(buildingId, floorRequest); | ||
result = await mediator.Send(request, token); | ||
} | ||
}); | ||
|
||
anotherRequest = result?.Match( | ||
onSuccess: () => | ||
{ | ||
AnsiConsole.MarkupLine("[green]Elevators requested successfully[/]"); | ||
return AnsiConsole.Confirm("Do you want to request more elevators?"); | ||
}, | ||
onFailure: error => | ||
{ | ||
var friendlyError = GetErrorMessage(error); | ||
AnsiConsole.MarkupLine($"[red]{friendlyError}[/]"); | ||
return AnsiConsole.Confirm("Do you want to try again?"); | ||
}) ?? false; | ||
} | ||
return true; | ||
} | ||
|
||
private string GetErrorMessage(Result error) | ||
{ | ||
if (error.Error is ValidationError validationError) | ||
{ | ||
return string.Join(", ", validationError.Errors.Select(e => e.Description)); | ||
} | ||
return error.Error.Description; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -61,5 +61,4 @@ private string GetErrorMessage(Result error) | |
} | ||
return error.Error.Description; | ||
} | ||
|
||
} |
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