diff --git a/src/RoadCaptain.App.RouteBuilder/ViewModels/DesignTimeMainWindowViewModel.cs b/src/RoadCaptain.App.RouteBuilder/ViewModels/DesignTimeMainWindowViewModel.cs index 131d946e..cca8c1af 100644 --- a/src/RoadCaptain.App.RouteBuilder/ViewModels/DesignTimeMainWindowViewModel.cs +++ b/src/RoadCaptain.App.RouteBuilder/ViewModels/DesignTimeMainWindowViewModel.cs @@ -30,7 +30,6 @@ public DesignTimeMainWindowViewModel() new DummyUserPreferences(), new DummyApplicationFeatures(), new StatusBarService(), - null!, null!) { // Route.OutputFilePath = @"C:\git\RoadCaptain\test\RoadCaptain.Tests.Unit\GameState\Repro\Rebel.Route-Italian.Villa.Sprint.Loop.json"; diff --git a/src/RoadCaptain.App.RouteBuilder/ViewModels/MainWindowViewModel.cs b/src/RoadCaptain.App.RouteBuilder/ViewModels/MainWindowViewModel.cs index ceea91c2..03f8b299 100644 --- a/src/RoadCaptain.App.RouteBuilder/ViewModels/MainWindowViewModel.cs +++ b/src/RoadCaptain.App.RouteBuilder/ViewModels/MainWindowViewModel.cs @@ -29,18 +29,16 @@ public class MainWindowViewModel : ViewModelBase private bool _haveCheckedLastOpenedVersion; private readonly IApplicationFeatures _applicationFeatures; private readonly SearchRoutesUseCase _searchRoutesUseCase; - private readonly RetrieveRepositoryNamesUseCase _retrieveRepositoryNamesUseCase; public MainWindowViewModel(IRouteStore routeStore, ISegmentStore segmentStore, IVersionChecker versionChecker, IWindowService windowService, IWorldStore worldStore, IUserPreferences userPreferences, - IApplicationFeatures applicationFeatures, IStatusBarService statusBarService, SearchRoutesUseCase searchRoutesUseCase, RetrieveRepositoryNamesUseCase retrieveRepositoryNamesUseCase) + IApplicationFeatures applicationFeatures, IStatusBarService statusBarService, SearchRoutesUseCase searchRoutesUseCase) { _versionChecker = versionChecker; _windowService = windowService; _userPreferences = userPreferences; _applicationFeatures = applicationFeatures; _searchRoutesUseCase = searchRoutesUseCase; - _retrieveRepositoryNamesUseCase = retrieveRepositoryNamesUseCase; Model = new MainWindowModel(); Route = new RouteViewModel(routeStore, segmentStore); @@ -197,8 +195,7 @@ public async Task CheckLastOpenedVersion() public async Task LoadMyRoutes() { var currentUser = "Sander van Vliet [RoadCaptain]"; - var repositories = _retrieveRepositoryNamesUseCase.Execute(new RetrieveRepositoryNamesCommand(RetrieveRepositoriesIntent.Manage)); - var result = await _searchRoutesUseCase.ExecuteAsync(new SearchRouteCommand(repositories, creator: currentUser)); + var result = await _searchRoutesUseCase.ExecuteAsync(new SearchRouteCommand(RetrieveRepositoriesIntent.Manage, creator: currentUser)); LandingPageViewModel.MyRoutes = result .Select(r => new Shared.ViewModels.RouteViewModel(r)) diff --git a/src/RoadCaptain/Commands/SearchRouteCommand.cs b/src/RoadCaptain/Commands/SearchRouteCommand.cs index 87263476..86551d90 100644 --- a/src/RoadCaptain/Commands/SearchRouteCommand.cs +++ b/src/RoadCaptain/Commands/SearchRouteCommand.cs @@ -9,7 +9,8 @@ namespace RoadCaptain.Commands { public class SearchRouteCommand { - public ImmutableArray Repositories { get; } + public ImmutableArray Repositories { get; } = ImmutableArray.Empty; + public RetrieveRepositoriesIntent Intent { get; } = RetrieveRepositoriesIntent.Unknown; public string? World { get; } public string? Creator { get; } public string? Name { get; } @@ -74,5 +75,37 @@ public SearchRouteCommand( KomSegments = komSegments; SprintSegments = sprintSegments; } + + public SearchRouteCommand( + RetrieveRepositoriesIntent intent, + string? world = null, + string? creator = null, + string? name = null, + string? zwiftRouteName = null, + int? minDistance = null, + int? maxDistance = null, + int? minAscent = null, + int? maxAscent = null, + int? minDescent = null, + int? maxDescent = null, + bool? isLoop = null, + string[]? komSegments = null, + string[]? sprintSegments = null) + { + Intent = intent; + World = world; + Creator = creator; + Name = name; + ZwiftRouteName = zwiftRouteName; + MinDistance = minDistance; + MaxDistance = maxDistance; + MinAscent = minAscent; + MaxAscent = maxAscent; + MinDescent = minDescent; + MaxDescent = maxDescent; + IsLoop = isLoop; + KomSegments = komSegments; + SprintSegments = sprintSegments; + } } } diff --git a/src/RoadCaptain/UseCases/SearchRoutesUseCase.cs b/src/RoadCaptain/UseCases/SearchRoutesUseCase.cs index 302cc70d..e1dcf2e5 100644 --- a/src/RoadCaptain/UseCases/SearchRoutesUseCase.cs +++ b/src/RoadCaptain/UseCases/SearchRoutesUseCase.cs @@ -25,9 +25,16 @@ public SearchRoutesUseCase(IEnumerable routeRepositories, Moni public async Task> ExecuteAsync(SearchRouteCommand command) { var repositoriesToSearch = new List(); + + if (!command.Repositories.Any() && command.Intent != RetrieveRepositoriesIntent.Unknown) + { + var repositoryNames = new RetrieveRepositoryNamesUseCase(_routeRepositories) + .Execute(new RetrieveRepositoryNamesCommand(command.Intent)); - if (command.Repositories.Length == 1 && - "all".Equals(command.Repositories[0], StringComparison.InvariantCultureIgnoreCase)) + repositoriesToSearch = _routeRepositories.Where(r => repositoryNames.Contains(r.Name)).ToList(); + } + else if (command.Repositories.Length == 1 && + "all".Equals(command.Repositories[0], StringComparison.InvariantCultureIgnoreCase)) { repositoriesToSearch.AddRange(_routeRepositories); } diff --git a/test/RoadCaptain.App.RouteBuilder.Tests.Unit/TestableMainWindowViewModel.cs b/test/RoadCaptain.App.RouteBuilder.Tests.Unit/TestableMainWindowViewModel.cs index 29601044..d7f5a59d 100644 --- a/test/RoadCaptain.App.RouteBuilder.Tests.Unit/TestableMainWindowViewModel.cs +++ b/test/RoadCaptain.App.RouteBuilder.Tests.Unit/TestableMainWindowViewModel.cs @@ -25,7 +25,7 @@ public TestableMainWindowViewModel( IStatusBarService statusBarService, SearchRoutesUseCase searchRoutesUseCase, RetrieveRepositoryNamesUseCase retrieveRepositoryNamesUseCase) - : base(routeStore, segmentStore, versionChecker, windowService, worldStore, userPreferences, applicationFeatures, statusBarService, searchRoutesUseCase, retrieveRepositoryNamesUseCase) + : base(routeStore, segmentStore, versionChecker, windowService, worldStore, userPreferences, applicationFeatures, statusBarService, searchRoutesUseCase) { }