1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-25 09:18:34 +00:00

Using Services, not Repos

This commit is contained in:
Mark McDowall 2013-04-11 17:36:47 -07:00
parent e11f8e6369
commit a6b66b7c90
3 changed files with 30 additions and 14 deletions

View file

@ -18,14 +18,12 @@ namespace NzbDrone.Api.Series
public class SeriesModule : NzbDroneApiModule public class SeriesModule : NzbDroneApiModule
{ {
private readonly ISeriesService _seriesService; private readonly ISeriesService _seriesService;
private readonly ISeriesRepository _seriesRepository;
private readonly IJobController _jobProvider; private readonly IJobController _jobProvider;
public SeriesModule(ISeriesService seriesService, ISeriesRepository seriesRepository, IJobController jobProvider) public SeriesModule(ISeriesService seriesService, IJobController jobProvider)
: base("/Series") : base("/Series")
{ {
_seriesService = seriesService; _seriesService = seriesService;
_seriesRepository = seriesRepository;
_jobProvider = jobProvider; _jobProvider = jobProvider;
Get["/"] = x => AllSeries(); Get["/"] = x => AllSeries();
Get["/{id}"] = x => GetSeries((int)x.id); Get["/{id}"] = x => GetSeries((int)x.id);
@ -37,7 +35,7 @@ namespace NzbDrone.Api.Series
private Response AllSeries() private Response AllSeries()
{ {
var series = _seriesRepository.All().ToList(); var series = _seriesService.GetAllSeries().ToList();
var seriesModels = Mapper.Map<List<Core.Tv.Series>, List<SeriesResource>>(series); var seriesModels = Mapper.Map<List<Core.Tv.Series>, List<SeriesResource>>(series);
return seriesModels.AsResponse(); return seriesModels.AsResponse();
@ -45,7 +43,7 @@ namespace NzbDrone.Api.Series
private Response GetSeries(int id) private Response GetSeries(int id)
{ {
var series = _seriesRepository.Get(id); var series = _seriesService.GetSeries(id);
var seriesModels = Mapper.Map<Core.Tv.Series, SeriesResource>(series); var seriesModels = Mapper.Map<Core.Tv.Series, SeriesResource>(series);
return seriesModels.AsResponse(); return seriesModels.AsResponse();
@ -69,7 +67,7 @@ namespace NzbDrone.Api.Series
{ {
var request = Request.Body.FromJson<SeriesResource>(); var request = Request.Body.FromJson<SeriesResource>();
var series = _seriesRepository.Get(request.Id); var series = _seriesService.GetSeries(request.Id);
series.Monitored = request.Monitored; series.Monitored = request.Monitored;
series.SeasonFolder = request.SeasonFolder; series.SeasonFolder = request.SeasonFolder;
@ -87,7 +85,7 @@ namespace NzbDrone.Api.Series
else else
series.CustomStartDate = null; series.CustomStartDate = null;
_seriesRepository.Update(series); _seriesService.UpdateSeries(series);
return request.AsResponse(); return request.AsResponse();
} }

View file

@ -13,9 +13,10 @@ namespace NzbDrone.Core.RootFolders
{ {
List<RootFolder> All(); List<RootFolder> All();
RootFolder Add(RootFolder rootDir); RootFolder Add(RootFolder rootDir);
void Remove(int rootDirId); void Remove(int id);
List<UnmappedFolder> GetUnmappedFolders(string path); List<UnmappedFolder> GetUnmappedFolders(string path);
Dictionary<string, ulong> FreeSpaceOnDrives(); Dictionary<string, ulong> FreeSpaceOnDrives();
RootFolder Get(int id);
} }
public class RootFolderService : IRootFolderService public class RootFolderService : IRootFolderService
@ -66,9 +67,9 @@ namespace NzbDrone.Core.RootFolders
return 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) public virtual List<UnmappedFolder> GetUnmappedFolders(string path)
@ -123,5 +124,10 @@ namespace NzbDrone.Core.RootFolders
return freeSpace; return freeSpace;
} }
public RootFolder Get(int id)
{
return _rootFolderRepository.Get(id);
}
} }
} }

View file

@ -27,6 +27,8 @@ namespace NzbDrone.Core.Tv
Series FindByTvdbId(int tvdbId); Series FindByTvdbId(int tvdbId);
void SetSeriesType(int seriesId, SeriesTypes seriesTypes); void SetSeriesType(int seriesId, SeriesTypes seriesTypes);
void DeleteSeries(int seriesId, bool deleteFiles); void DeleteSeries(int seriesId, bool deleteFiles);
List<Series> GetAllSeries();
void UpdateSeries(Series series);
} }
public class SeriesService : ISeriesService, IHandleAsync<SeriesAddedEvent> public class SeriesService : ISeriesService, IHandleAsync<SeriesAddedEvent>
@ -35,19 +37,19 @@ namespace NzbDrone.Core.Tv
private readonly IConfigService _configService; private readonly IConfigService _configService;
private readonly IProvideSeriesInfo _seriesInfoProxy; private readonly IProvideSeriesInfo _seriesInfoProxy;
private readonly IEventAggregator _eventAggregator; private readonly IEventAggregator _eventAggregator;
private readonly IBasicRepository<RootFolder> _rootFolderRepository; private readonly IRootFolderService _rootFolderService;
private readonly DiskProvider _diskProvider; private readonly DiskProvider _diskProvider;
private readonly Logger _logger; private readonly Logger _logger;
public SeriesService(ISeriesRepository seriesRepository, IConfigService configServiceService, public SeriesService(ISeriesRepository seriesRepository, IConfigService configServiceService,
IProvideSeriesInfo seriesInfoProxy, IEventAggregator eventAggregator, IProvideSeriesInfo seriesInfoProxy, IEventAggregator eventAggregator,
IBasicRepository<RootFolder> rootFolderRepository, DiskProvider diskProvider, Logger logger) IRootFolderService rootFolderService, DiskProvider diskProvider, Logger logger)
{ {
_seriesRepository = seriesRepository; _seriesRepository = seriesRepository;
_configService = configServiceService; _configService = configServiceService;
_seriesInfoProxy = seriesInfoProxy; _seriesInfoProxy = seriesInfoProxy;
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_rootFolderRepository = rootFolderRepository; _rootFolderService = rootFolderService;
_diskProvider = diskProvider; _diskProvider = diskProvider;
_logger = logger; _logger = logger;
} }
@ -94,7 +96,7 @@ namespace NzbDrone.Core.Tv
if(String.IsNullOrWhiteSpace(newSeries.FolderName)) if(String.IsNullOrWhiteSpace(newSeries.FolderName))
{ {
newSeries.FolderName = FileNameBuilder.CleanFilename(newSeries.Title); 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); _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)); _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) public void HandleAsync(SeriesAddedEvent message)
{ {
UpdateSeriesInfo(message.Series.Id); UpdateSeriesInfo(message.Series.Id);