From a6b66b7c90f099b92cc2c5ed8e1a77c465923bb5 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 11 Apr 2013 17:36:47 -0700 Subject: [PATCH] Using Services, not Repos --- NzbDrone.Api/Series/SeriesModule.cs | 12 +++++------ .../RootFolders/RootFolderService.cs | 12 ++++++++--- NzbDrone.Core/Tv/SeriesService.cs | 20 +++++++++++++++---- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/NzbDrone.Api/Series/SeriesModule.cs b/NzbDrone.Api/Series/SeriesModule.cs index 58ec784e9..166357fa1 100644 --- a/NzbDrone.Api/Series/SeriesModule.cs +++ b/NzbDrone.Api/Series/SeriesModule.cs @@ -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 @@ namespace NzbDrone.Api.Series private Response AllSeries() { - var series = _seriesRepository.All().ToList(); + var series = _seriesService.GetAllSeries().ToList(); var seriesModels = Mapper.Map, List>(series); return seriesModels.AsResponse(); @@ -45,7 +43,7 @@ namespace NzbDrone.Api.Series private Response GetSeries(int id) { - var series = _seriesRepository.Get(id); + var series = _seriesService.GetSeries(id); var seriesModels = Mapper.Map(series); return seriesModels.AsResponse(); @@ -69,7 +67,7 @@ namespace NzbDrone.Api.Series { var request = Request.Body.FromJson(); - var series = _seriesRepository.Get(request.Id); + var series = _seriesService.GetSeries(request.Id); series.Monitored = request.Monitored; series.SeasonFolder = request.SeasonFolder; @@ -87,7 +85,7 @@ namespace NzbDrone.Api.Series else series.CustomStartDate = null; - _seriesRepository.Update(series); + _seriesService.UpdateSeries(series); return request.AsResponse(); } diff --git a/NzbDrone.Core/RootFolders/RootFolderService.cs b/NzbDrone.Core/RootFolders/RootFolderService.cs index 97d1fc28a..c47be5c0f 100644 --- a/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -13,9 +13,10 @@ namespace NzbDrone.Core.RootFolders { List All(); RootFolder Add(RootFolder rootDir); - void Remove(int rootDirId); + void Remove(int id); List GetUnmappedFolders(string path); Dictionary FreeSpaceOnDrives(); + RootFolder Get(int id); } public class RootFolderService : IRootFolderService @@ -66,9 +67,9 @@ namespace NzbDrone.Core.RootFolders return rootFolder; } - public virtual void Remove(int rootDirId) + public virtual void Remove(int id) { - _rootFolderRepository.Delete(rootDirId); + _rootFolderRepository.Delete(id); } public virtual List GetUnmappedFolders(string path) @@ -123,5 +124,10 @@ namespace NzbDrone.Core.RootFolders return freeSpace; } + + public RootFolder Get(int id) + { + return _rootFolderRepository.Get(id); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index d66438f8b..6c929b389 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -27,6 +27,8 @@ namespace NzbDrone.Core.Tv Series FindByTvdbId(int tvdbId); void SetSeriesType(int seriesId, SeriesTypes seriesTypes); void DeleteSeries(int seriesId, bool deleteFiles); + List GetAllSeries(); + void UpdateSeries(Series series); } public class SeriesService : ISeriesService, IHandleAsync @@ -35,19 +37,19 @@ namespace NzbDrone.Core.Tv private readonly IConfigService _configService; private readonly IProvideSeriesInfo _seriesInfoProxy; private readonly IEventAggregator _eventAggregator; - private readonly IBasicRepository _rootFolderRepository; + private readonly IRootFolderService _rootFolderService; private readonly DiskProvider _diskProvider; private readonly Logger _logger; public SeriesService(ISeriesRepository seriesRepository, IConfigService configServiceService, IProvideSeriesInfo seriesInfoProxy, IEventAggregator eventAggregator, - IBasicRepository 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 @@ namespace NzbDrone.Core.Tv 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 @@ namespace NzbDrone.Core.Tv _eventAggregator.Publish(new SeriesDeletedEvent(series, deleteFiles)); } + public List GetAllSeries() + { + return _seriesRepository.All().ToList(); + } + + public void UpdateSeries(Series series) + { + _seriesRepository.Update(series); + } + public void HandleAsync(SeriesAddedEvent message) { UpdateSeriesInfo(message.Series.Id);