mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-05 02:22:31 +01:00
Using Services, not Repos
This commit is contained in:
parent
e11f8e6369
commit
a6b66b7c90
@ -18,14 +18,12 @@ namespace NzbDrone.Api.Series
|
||||
public class SeriesModule : NzbDroneApiModule
|
||||
{
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
private readonly IJobController _jobProvider;
|
||||
|
||||
public SeriesModule(ISeriesService seriesService, ISeriesRepository seriesRepository, IJobController jobProvider)
|
||||
public SeriesModule(ISeriesService seriesService, IJobController jobProvider)
|
||||
: base("/Series")
|
||||
{
|
||||
_seriesService = seriesService;
|
||||
_seriesRepository = seriesRepository;
|
||||
_jobProvider = jobProvider;
|
||||
Get["/"] = x => AllSeries();
|
||||
Get["/{id}"] = x => GetSeries((int)x.id);
|
||||
@ -37,7 +35,7 @@ public SeriesModule(ISeriesService seriesService, ISeriesRepository seriesReposi
|
||||
|
||||
private Response AllSeries()
|
||||
{
|
||||
var series = _seriesRepository.All().ToList();
|
||||
var series = _seriesService.GetAllSeries().ToList();
|
||||
var seriesModels = Mapper.Map<List<Core.Tv.Series>, List<SeriesResource>>(series);
|
||||
|
||||
return seriesModels.AsResponse();
|
||||
@ -45,7 +43,7 @@ private Response AllSeries()
|
||||
|
||||
private Response GetSeries(int id)
|
||||
{
|
||||
var series = _seriesRepository.Get(id);
|
||||
var series = _seriesService.GetSeries(id);
|
||||
var seriesModels = Mapper.Map<Core.Tv.Series, SeriesResource>(series);
|
||||
|
||||
return seriesModels.AsResponse();
|
||||
@ -69,7 +67,7 @@ private Response UpdateSeries()
|
||||
{
|
||||
var request = Request.Body.FromJson<SeriesResource>();
|
||||
|
||||
var series = _seriesRepository.Get(request.Id);
|
||||
var series = _seriesService.GetSeries(request.Id);
|
||||
|
||||
series.Monitored = request.Monitored;
|
||||
series.SeasonFolder = request.SeasonFolder;
|
||||
@ -87,7 +85,7 @@ private Response UpdateSeries()
|
||||
else
|
||||
series.CustomStartDate = null;
|
||||
|
||||
_seriesRepository.Update(series);
|
||||
_seriesService.UpdateSeries(series);
|
||||
|
||||
return request.AsResponse();
|
||||
}
|
||||
|
@ -13,9 +13,10 @@ public interface IRootFolderService
|
||||
{
|
||||
List<RootFolder> All();
|
||||
RootFolder Add(RootFolder rootDir);
|
||||
void Remove(int rootDirId);
|
||||
void Remove(int id);
|
||||
List<UnmappedFolder> GetUnmappedFolders(string path);
|
||||
Dictionary<string, ulong> FreeSpaceOnDrives();
|
||||
RootFolder Get(int id);
|
||||
}
|
||||
|
||||
public class RootFolderService : IRootFolderService
|
||||
@ -66,9 +67,9 @@ public virtual RootFolder Add(RootFolder rootFolder)
|
||||
return rootFolder;
|
||||
}
|
||||
|
||||
public virtual void Remove(int rootDirId)
|
||||
public virtual void Remove(int id)
|
||||
{
|
||||
_rootFolderRepository.Delete(rootDirId);
|
||||
_rootFolderRepository.Delete(id);
|
||||
}
|
||||
|
||||
public virtual List<UnmappedFolder> GetUnmappedFolders(string path)
|
||||
@ -123,5 +124,10 @@ public virtual Dictionary<string, ulong> FreeSpaceOnDrives()
|
||||
|
||||
return freeSpace;
|
||||
}
|
||||
|
||||
public RootFolder Get(int id)
|
||||
{
|
||||
return _rootFolderRepository.Get(id);
|
||||
}
|
||||
}
|
||||
}
|
@ -27,6 +27,8 @@ public interface ISeriesService
|
||||
Series FindByTvdbId(int tvdbId);
|
||||
void SetSeriesType(int seriesId, SeriesTypes seriesTypes);
|
||||
void DeleteSeries(int seriesId, bool deleteFiles);
|
||||
List<Series> GetAllSeries();
|
||||
void UpdateSeries(Series series);
|
||||
}
|
||||
|
||||
public class SeriesService : ISeriesService, IHandleAsync<SeriesAddedEvent>
|
||||
@ -35,19 +37,19 @@ public class SeriesService : ISeriesService, IHandleAsync<SeriesAddedEvent>
|
||||
private readonly IConfigService _configService;
|
||||
private readonly IProvideSeriesInfo _seriesInfoProxy;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IBasicRepository<RootFolder> _rootFolderRepository;
|
||||
private readonly IRootFolderService _rootFolderService;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public SeriesService(ISeriesRepository seriesRepository, IConfigService configServiceService,
|
||||
IProvideSeriesInfo seriesInfoProxy, IEventAggregator eventAggregator,
|
||||
IBasicRepository<RootFolder> rootFolderRepository, DiskProvider diskProvider, Logger logger)
|
||||
IRootFolderService rootFolderService, DiskProvider diskProvider, Logger logger)
|
||||
{
|
||||
_seriesRepository = seriesRepository;
|
||||
_configService = configServiceService;
|
||||
_seriesInfoProxy = seriesInfoProxy;
|
||||
_eventAggregator = eventAggregator;
|
||||
_rootFolderRepository = rootFolderRepository;
|
||||
_rootFolderService = rootFolderService;
|
||||
_diskProvider = diskProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
@ -94,7 +96,7 @@ public void AddSeries(Series newSeries)
|
||||
if(String.IsNullOrWhiteSpace(newSeries.FolderName))
|
||||
{
|
||||
newSeries.FolderName = FileNameBuilder.CleanFilename(newSeries.Title);
|
||||
_diskProvider.CreateDirectory(Path.Combine(_rootFolderRepository.Get(newSeries.RootFolderId).Path, newSeries.FolderName));
|
||||
_diskProvider.CreateDirectory(Path.Combine(_rootFolderService.Get(newSeries.RootFolderId).Path, newSeries.FolderName));
|
||||
}
|
||||
|
||||
_logger.Info("Adding Series [{0}] Path: [{1}]", newSeries.Title, newSeries.Path);
|
||||
@ -153,6 +155,16 @@ public void DeleteSeries(int seriesId, bool deleteFiles)
|
||||
_eventAggregator.Publish(new SeriesDeletedEvent(series, deleteFiles));
|
||||
}
|
||||
|
||||
public List<Series> GetAllSeries()
|
||||
{
|
||||
return _seriesRepository.All().ToList();
|
||||
}
|
||||
|
||||
public void UpdateSeries(Series series)
|
||||
{
|
||||
_seriesRepository.Update(series);
|
||||
}
|
||||
|
||||
public void HandleAsync(SeriesAddedEvent message)
|
||||
{
|
||||
UpdateSeriesInfo(message.Series.Id);
|
||||
|
Loading…
Reference in New Issue
Block a user