Fixed: RootFolderPath not set for Movies from API

pull/8462/head
Qstick 2 years ago
parent ff1449c01e
commit 850fef5c43

@ -43,7 +43,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
.Returns((string path) => Directory.GetParent(path).FullName);
Mocker.GetMock<IRootFolderService>()
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>()))
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>(), null))
.Returns(_rootFolder);
Mocker.GetMock<IMediaFileService>()

@ -57,7 +57,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieFileMovingServiceTests
.Returns(true);
Mocker.GetMock<IRootFolderService>()
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>()))
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>(), null))
.Returns(rootFolder);
}

@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
@ -36,7 +36,7 @@ namespace NzbDrone.Core.Test.MovieTests
public void GivenExistingRootFolder(string rootFolder)
{
Mocker.GetMock<IRootFolderService>()
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>()))
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>(), null))
.Returns(rootFolder);
}

@ -55,7 +55,7 @@ namespace NzbDrone.Core.Test.MovieTests
.Callback<int>((i) => { throw new MovieNotFoundException(i); });
Mocker.GetMock<IRootFolderService>()
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>()))
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>(), null))
.Returns(string.Empty);
}

@ -19,7 +19,7 @@ namespace NzbDrone.Core.RootFolders
RootFolder Add(RootFolder rootDir);
void Remove(int id);
RootFolder Get(int id, bool timeout);
string GetBestRootFolderPath(string path);
string GetBestRootFolderPath(string path, List<RootFolder> rootFolders = null);
}
public class RootFolderService : IRootFolderService
@ -180,9 +180,11 @@ namespace NzbDrone.Core.RootFolders
return rootFolder;
}
public string GetBestRootFolderPath(string path)
public string GetBestRootFolderPath(string path, List<RootFolder> rootFolders = null)
{
var possibleRootFolder = All().Where(r => r.Path.IsParentPath(path)).MaxBy(r => r.Path.Length);
var allRootFoldersToConsider = rootFolders ?? All();
var possibleRootFolder = allRootFoldersToConsider.Where(r => r.Path.IsParentPath(path)).MaxBy(r => r.Path.Length);
if (possibleRootFolder == null)
{

@ -20,6 +20,7 @@ using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.Commands;
using NzbDrone.Core.Movies.Events;
using NzbDrone.Core.Movies.Translations;
using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Validation;
using NzbDrone.Core.Validation.Paths;
using NzbDrone.SignalR;
@ -45,6 +46,7 @@ namespace Radarr.Api.V3.Movies
private readonly IAddMovieService _addMovieService;
private readonly IMapCoversToLocal _coverMapper;
private readonly IManageCommandQueue _commandQueueManager;
private readonly IRootFolderService _rootFolderService;
private readonly IUpgradableSpecification _qualityUpgradableSpecification;
private readonly IConfigService _configService;
private readonly Logger _logger;
@ -55,6 +57,7 @@ namespace Radarr.Api.V3.Movies
IAddMovieService addMovieService,
IMapCoversToLocal coverMapper,
IManageCommandQueue commandQueueManager,
IRootFolderService rootFolderService,
IUpgradableSpecification qualityUpgradableSpecification,
IConfigService configService,
RootFolderValidator rootFolderValidator,
@ -76,6 +79,7 @@ namespace Radarr.Api.V3.Movies
_configService = configService;
_coverMapper = coverMapper;
_commandQueueManager = commandQueueManager;
_rootFolderService = rootFolderService;
_logger = logger;
SharedValidator.RuleFor(s => s.QualityProfileId).ValidId();
@ -145,6 +149,10 @@ namespace Radarr.Api.V3.Movies
}
MapCoversToLocal(moviesResources, coverFileInfos);
var rootFolders = _rootFolderService.All();
moviesResources.ForEach(m => m.RootFolderPath = _rootFolderService.GetBestRootFolderPath(m.Path, rootFolders));
}
return moviesResources;
@ -171,6 +179,8 @@ namespace Radarr.Api.V3.Movies
var resource = movie.ToResource(availDelay, translation, _qualityUpgradableSpecification);
MapCoversToLocal(resource);
resource.RootFolderPath = _rootFolderService.GetBestRootFolderPath(resource.Path);
return resource;
}

Loading…
Cancel
Save