Skip to content

Commit

Permalink
Add option to search routes by intent
Browse files Browse the repository at this point in the history
  • Loading branch information
sandermvanvliet committed Nov 19, 2023
1 parent ca8252c commit f3573dc
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down
35 changes: 34 additions & 1 deletion src/RoadCaptain/Commands/SearchRouteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace RoadCaptain.Commands
{
public class SearchRouteCommand
{
public ImmutableArray<string> Repositories { get; }
public ImmutableArray<string> Repositories { get; } = ImmutableArray<string>.Empty;
public RetrieveRepositoriesIntent Intent { get; } = RetrieveRepositoriesIntent.Unknown;
public string? World { get; }
public string? Creator { get; }
public string? Name { get; }
Expand Down Expand Up @@ -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;
}
}
}
11 changes: 9 additions & 2 deletions src/RoadCaptain/UseCases/SearchRoutesUseCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ public SearchRoutesUseCase(IEnumerable<IRouteRepository> routeRepositories, Moni
public async Task<IEnumerable<RouteModel>> ExecuteAsync(SearchRouteCommand command)
{
var repositoriesToSearch = new List<IRouteRepository>();

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down

0 comments on commit f3573dc

Please sign in to comment.