Using Services, not Repos

pull/6/head
Mark McDowall 12 years ago
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 @@ namespace NzbDrone.Api.Series
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 @@ namespace NzbDrone.Api.Series
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 @@ namespace NzbDrone.Api.Series
{
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 @@ namespace NzbDrone.Api.Series
else
series.CustomStartDate = null;
_seriesRepository.Update(series);
_seriesService.UpdateSeries(series);
return request.AsResponse();
}

@ -13,9 +13,10 @@ namespace NzbDrone.Core.RootFolders
{
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 @@ 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<UnmappedFolder> GetUnmappedFolders(string path)
@ -123,5 +124,10 @@ namespace NzbDrone.Core.RootFolders
return freeSpace;
}
public RootFolder Get(int id)
{
return _rootFolderRepository.Get(id);
}
}
}

@ -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<Series> GetAllSeries();
void UpdateSeries(Series series);
}
public class SeriesService : ISeriesService, IHandleAsync<SeriesAddedEvent>
@ -35,19 +37,19 @@ namespace NzbDrone.Core.Tv
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 @@ 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<Series> GetAllSeries()
{
return _seriesRepository.All().ToList();
}
public void UpdateSeries(Series series)
{
_seriesRepository.Update(series);
}
public void HandleAsync(SeriesAddedEvent message)
{
UpdateSeriesInfo(message.Series.Id);

Loading…
Cancel
Save