Rename ImportExclusion to ImportListExclusion

pull/10287/head
Bogdan 3 months ago committed by Qstick
parent f76c97c3ce
commit b1a7652753

@ -76,9 +76,9 @@ namespace NzbDrone.Core.Test.ImportList
.Setup(v => v.Enabled(It.IsAny<bool>())) .Setup(v => v.Enabled(It.IsAny<bool>()))
.Returns(_importLists); .Returns(_importLists);
Mocker.GetMock<IImportExclusionsService>() Mocker.GetMock<IImportListExclusionService>()
.Setup(v => v.GetAllExclusions()) .Setup(v => v.All())
.Returns(new List<ImportExclusion>()); .Returns(new List<ImportListExclusion>());
Mocker.GetMock<IMovieService>() Mocker.GetMock<IMovieService>()
.Setup(v => v.MovieExists(It.IsAny<Movie>())) .Setup(v => v.MovieExists(It.IsAny<Movie>()))
@ -167,8 +167,8 @@ namespace NzbDrone.Core.Test.ImportList
Mocker.GetMock<IMovieService>() Mocker.GetMock<IMovieService>()
.Verify(v => v.UpdateMovie(new List<Movie>(), true), Times.Never()); .Verify(v => v.UpdateMovie(new List<Movie>(), true), Times.Never());
Mocker.GetMock<IImportExclusionsService>() Mocker.GetMock<IImportListExclusionService>()
.Verify(v => v.GetAllExclusions(), Times.Never); .Verify(v => v.All(), Times.Never);
} }
[Test] [Test]
@ -427,9 +427,9 @@ namespace NzbDrone.Core.Test.ImportList
GivenCleanLevel("disabled"); GivenCleanLevel("disabled");
Mocker.GetMock<IImportExclusionsService>() Mocker.GetMock<IImportListExclusionService>()
.Setup(v => v.GetAllExclusions()) .Setup(v => v.All())
.Returns(new List<ImportExclusion> { new ImportExclusion { TmdbId = _existingMovies[0].TmdbId } }); .Returns(new List<ImportListExclusion> { new ImportListExclusion { TmdbId = _existingMovies[0].TmdbId } });
Subject.Execute(_commandAll); Subject.Execute(_commandAll);

@ -134,7 +134,7 @@ namespace NzbDrone.Core.Datastore
Mapper.Entity<Credit>("Credits").RegisterModel(); Mapper.Entity<Credit>("Credits").RegisterModel();
Mapper.Entity<ImportExclusion>("ImportExclusions").RegisterModel(); Mapper.Entity<ImportListExclusion>("ImportExclusions").RegisterModel();
Mapper.Entity<QualityDefinition>("QualityDefinitions").RegisterModel() Mapper.Entity<QualityDefinition>("QualityDefinitions").RegisterModel()
.Ignore(d => d.GroupName) .Ignore(d => d.GroupName)

@ -1,95 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Movies.Events;
namespace NzbDrone.Core.ImportLists.ImportExclusions
{
public interface IImportExclusionsService
{
List<ImportExclusion> GetAllExclusions();
bool IsMovieExcluded(int tmdbId);
ImportExclusion AddExclusion(ImportExclusion exclusion);
List<ImportExclusion> AddExclusions(List<ImportExclusion> exclusions);
void RemoveExclusion(ImportExclusion exclusion);
ImportExclusion GetById(int id);
ImportExclusion Update(ImportExclusion exclusion);
}
public class ImportExclusionsService : IImportExclusionsService, IHandleAsync<MoviesDeletedEvent>
{
private readonly IImportExclusionsRepository _exclusionRepository;
private readonly Logger _logger;
public ImportExclusionsService(IImportExclusionsRepository exclusionRepository,
Logger logger)
{
_exclusionRepository = exclusionRepository;
_logger = logger;
}
public ImportExclusion AddExclusion(ImportExclusion exclusion)
{
if (_exclusionRepository.IsMovieExcluded(exclusion.TmdbId))
{
return _exclusionRepository.GetByTmdbid(exclusion.TmdbId);
}
return _exclusionRepository.Insert(exclusion);
}
public List<ImportExclusion> AddExclusions(List<ImportExclusion> exclusions)
{
_exclusionRepository.InsertMany(DeDupeExclusions(exclusions));
return exclusions;
}
public List<ImportExclusion> GetAllExclusions()
{
return _exclusionRepository.All().ToList();
}
public bool IsMovieExcluded(int tmdbId)
{
return _exclusionRepository.IsMovieExcluded(tmdbId);
}
public void RemoveExclusion(ImportExclusion exclusion)
{
_exclusionRepository.Delete(exclusion);
}
public ImportExclusion GetById(int id)
{
return _exclusionRepository.Get(id);
}
public ImportExclusion Update(ImportExclusion exclusion)
{
return _exclusionRepository.Update(exclusion);
}
public void HandleAsync(MoviesDeletedEvent message)
{
if (message.AddExclusion)
{
_logger.Debug("Adding {0} Deleted Movies to Import Exclusions", message.Movies.Count);
var exclusions = message.Movies.Select(m => new ImportExclusion { TmdbId = m.TmdbId, MovieTitle = m.Title, MovieYear = m.Year }).ToList();
_exclusionRepository.InsertMany(DeDupeExclusions(exclusions));
}
}
private List<ImportExclusion> DeDupeExclusions(List<ImportExclusion> exclusions)
{
var existingExclusions = _exclusionRepository.AllExcludedTmdbIds();
return exclusions
.DistinctBy(x => x.TmdbId)
.Where(x => !existingExclusions.Contains(x.TmdbId))
.ToList();
}
}
}

@ -2,7 +2,7 @@
namespace NzbDrone.Core.ImportLists.ImportExclusions namespace NzbDrone.Core.ImportLists.ImportExclusions
{ {
public class ImportExclusion : ModelBase public class ImportListExclusion : ModelBase
{ {
public int TmdbId { get; set; } public int TmdbId { get; set; }
public string MovieTitle { get; set; } public string MovieTitle { get; set; }

@ -6,16 +6,16 @@ using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.ImportLists.ImportExclusions namespace NzbDrone.Core.ImportLists.ImportExclusions
{ {
public interface IImportExclusionsRepository : IBasicRepository<ImportExclusion> public interface IImportListExclusionRepository : IBasicRepository<ImportListExclusion>
{ {
bool IsMovieExcluded(int tmdbid); bool IsMovieExcluded(int tmdbid);
ImportExclusion GetByTmdbid(int tmdbid); ImportListExclusion FindByTmdbid(int tmdbid);
List<int> AllExcludedTmdbIds(); List<int> AllExcludedTmdbIds();
} }
public class ImportExclusionsRepository : BasicRepository<ImportExclusion>, IImportExclusionsRepository public class ImportListListExclusionRepository : BasicRepository<ImportListExclusion>, IImportListExclusionRepository
{ {
public ImportExclusionsRepository(IMainDatabase database, IEventAggregator eventAggregator) public ImportListListExclusionRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator) : base(database, eventAggregator)
{ {
} }
@ -25,9 +25,9 @@ namespace NzbDrone.Core.ImportLists.ImportExclusions
return Query(x => x.TmdbId == tmdbid).Any(); return Query(x => x.TmdbId == tmdbid).Any();
} }
public ImportExclusion GetByTmdbid(int tmdbid) public ImportListExclusion FindByTmdbid(int tmdbid)
{ {
return Query(x => x.TmdbId == tmdbid).First(); return Query(x => x.TmdbId == tmdbid).SingleOrDefault();
} }
public List<int> AllExcludedTmdbIds() public List<int> AllExcludedTmdbIds()

@ -0,0 +1,115 @@
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Movies.Events;
namespace NzbDrone.Core.ImportLists.ImportExclusions
{
public interface IImportListExclusionService
{
ImportListExclusion Add(ImportListExclusion importListExclusion);
List<ImportListExclusion> Add(List<ImportListExclusion> importListExclusions);
List<ImportListExclusion> All();
bool IsMovieExcluded(int tmdbId);
void Delete(int id);
void Delete(List<int> ids);
ImportListExclusion Get(int id);
ImportListExclusion Update(ImportListExclusion importListExclusion);
List<int> AllExcludedTmdbIds();
}
public class ImportListExclusionService : IImportListExclusionService, IHandleAsync<MoviesDeletedEvent>
{
private readonly IImportListExclusionRepository _repo;
private readonly Logger _logger;
public ImportListExclusionService(IImportListExclusionRepository repo,
Logger logger)
{
_repo = repo;
_logger = logger;
}
public ImportListExclusion Add(ImportListExclusion importListExclusion)
{
if (_repo.IsMovieExcluded(importListExclusion.TmdbId))
{
return _repo.FindByTmdbid(importListExclusion.TmdbId);
}
return _repo.Insert(importListExclusion);
}
public List<ImportListExclusion> Add(List<ImportListExclusion> importListExclusions)
{
_repo.InsertMany(DeDupeExclusions(importListExclusions));
return importListExclusions;
}
public bool IsMovieExcluded(int tmdbId)
{
return _repo.IsMovieExcluded(tmdbId);
}
public void Delete(int id)
{
_repo.Delete(id);
}
public void Delete(List<int> ids)
{
_repo.DeleteMany(ids);
}
public ImportListExclusion Get(int id)
{
return _repo.Get(id);
}
public ImportListExclusion Update(ImportListExclusion importListExclusion)
{
return _repo.Update(importListExclusion);
}
public List<ImportListExclusion> All()
{
return _repo.All().ToList();
}
public List<int> AllExcludedTmdbIds()
{
return _repo.AllExcludedTmdbIds();
}
public void HandleAsync(MoviesDeletedEvent message)
{
if (!message.AddImportListExclusion)
{
return;
}
_logger.Debug("Adding {0} deleted movies to import list exclusions.", message.Movies.Count);
var exclusionsToAdd = DeDupeExclusions(message.Movies.Select(m => new ImportListExclusion
{
TmdbId = m.TmdbId,
MovieTitle = m.Title,
MovieYear = m.Year
}).ToList());
_repo.InsertMany(exclusionsToAdd);
}
private List<ImportListExclusion> DeDupeExclusions(List<ImportListExclusion> exclusions)
{
var existingExclusions = _repo.AllExcludedTmdbIds();
return exclusions
.DistinctBy(x => x.TmdbId)
.Where(x => !existingExclusions.Contains(x.TmdbId))
.ToList();
}
}
}

@ -19,7 +19,7 @@ namespace NzbDrone.Core.ImportLists
private readonly IMovieService _movieService; private readonly IMovieService _movieService;
private readonly IAddMovieService _addMovieService; private readonly IAddMovieService _addMovieService;
private readonly IConfigService _configService; private readonly IConfigService _configService;
private readonly IImportExclusionsService _exclusionService; private readonly IImportListExclusionService _listExclusionService;
private readonly IImportListMovieService _listMovieService; private readonly IImportListMovieService _listMovieService;
public ImportListSyncService(IImportListFactory importListFactory, public ImportListSyncService(IImportListFactory importListFactory,
@ -27,7 +27,7 @@ namespace NzbDrone.Core.ImportLists
IMovieService movieService, IMovieService movieService,
IAddMovieService addMovieService, IAddMovieService addMovieService,
IConfigService configService, IConfigService configService,
IImportExclusionsService exclusionService, IImportListExclusionService listExclusionService,
IImportListMovieService listMovieService, IImportListMovieService listMovieService,
Logger logger) Logger logger)
{ {
@ -35,7 +35,7 @@ namespace NzbDrone.Core.ImportLists
_listFetcherAndParser = listFetcherAndParser; _listFetcherAndParser = listFetcherAndParser;
_movieService = movieService; _movieService = movieService;
_addMovieService = addMovieService; _addMovieService = addMovieService;
_exclusionService = exclusionService; _listExclusionService = listExclusionService;
_listMovieService = listMovieService; _listMovieService = listMovieService;
_logger = logger; _logger = logger;
_configService = configService; _configService = configService;
@ -74,7 +74,7 @@ namespace NzbDrone.Core.ImportLists
ProcessListItems(listItemsResult); ProcessListItems(listItemsResult);
} }
private void ProcessMovieReport(ImportListDefinition importList, ImportListMovie report, List<ImportExclusion> listExclusions, List<int> dbMovies, List<Movie> moviesToAdd) private void ProcessMovieReport(ImportListDefinition importList, ImportListMovie report, List<ImportListExclusion> listExclusions, List<int> dbMovies, List<Movie> moviesToAdd)
{ {
if (report.TmdbId == 0 || !importList.EnableAuto) if (report.TmdbId == 0 || !importList.EnableAuto)
{ {
@ -142,7 +142,7 @@ namespace NzbDrone.Core.ImportLists
var listedMovies = listFetchResult.Movies.ToList(); var listedMovies = listFetchResult.Movies.ToList();
var importExclusions = _exclusionService.GetAllExclusions(); var importExclusions = _listExclusionService.All();
var dbMovies = _movieService.AllMovieTmdbIds(); var dbMovies = _movieService.AllMovieTmdbIds();
var moviesToAdd = new List<Movie>(); var moviesToAdd = new List<Movie>();

@ -7,13 +7,13 @@ namespace NzbDrone.Core.Movies.Events
{ {
public List<Movie> Movies { get; private set; } public List<Movie> Movies { get; private set; }
public bool DeleteFiles { get; private set; } public bool DeleteFiles { get; private set; }
public bool AddExclusion { get; private set; } public bool AddImportListExclusion { get; private set; }
public MoviesDeletedEvent(List<Movie> movies, bool deleteFiles, bool addExclusion) public MoviesDeletedEvent(List<Movie> movies, bool deleteFiles, bool addImportListExclusion)
{ {
Movies = movies; Movies = movies;
DeleteFiles = deleteFiles; DeleteFiles = deleteFiles;
AddExclusion = addExclusion; AddImportListExclusion = addImportListExclusion;
} }
} }
} }

@ -36,8 +36,8 @@ namespace NzbDrone.Core.Movies
List<Movie> GetMoviesByCollectionTmdbId(int collectionId); List<Movie> GetMoviesByCollectionTmdbId(int collectionId);
List<Movie> GetMoviesBetweenDates(DateTime start, DateTime end, bool includeUnmonitored); List<Movie> GetMoviesBetweenDates(DateTime start, DateTime end, bool includeUnmonitored);
PagingSpec<Movie> MoviesWithoutFiles(PagingSpec<Movie> pagingSpec); PagingSpec<Movie> MoviesWithoutFiles(PagingSpec<Movie> pagingSpec);
void DeleteMovie(int movieId, bool deleteFiles, bool addExclusion = false); void DeleteMovie(int movieId, bool deleteFiles, bool addImportListExclusion = false);
void DeleteMovies(List<int> movieIds, bool deleteFiles, bool addExclusion = false); void DeleteMovies(List<int> movieIds, bool deleteFiles, bool addImportListExclusion = false);
List<Movie> GetAllMovies(); List<Movie> GetAllMovies();
Dictionary<int, List<int>> AllMovieTags(); Dictionary<int, List<int>> AllMovieTags();
Movie UpdateMovie(Movie movie); Movie UpdateMovie(Movie movie);
@ -210,22 +210,22 @@ namespace NzbDrone.Core.Movies
return _movieRepository.AllMovieTmdbIds(); return _movieRepository.AllMovieTmdbIds();
} }
public void DeleteMovie(int movieId, bool deleteFiles, bool addExclusion = false) public void DeleteMovie(int movieId, bool deleteFiles, bool addImportListExclusion = false)
{ {
var movie = _movieRepository.Get(movieId); var movie = _movieRepository.Get(movieId);
_movieRepository.Delete(movieId); _movieRepository.Delete(movieId);
_eventAggregator.PublishEvent(new MoviesDeletedEvent(new List<Movie> { movie }, deleteFiles, addExclusion)); _eventAggregator.PublishEvent(new MoviesDeletedEvent(new List<Movie> { movie }, deleteFiles, addImportListExclusion));
_logger.Info("Deleted movie {0}", movie); _logger.Info("Deleted movie {0}", movie);
} }
public void DeleteMovies(List<int> movieIds, bool deleteFiles, bool addExclusion = false) public void DeleteMovies(List<int> movieIds, bool deleteFiles, bool addImportListExclusion = false)
{ {
var moviesToDelete = _movieRepository.Get(movieIds).ToList(); var moviesToDelete = _movieRepository.Get(movieIds).ToList();
_movieRepository.DeleteMany(movieIds); _movieRepository.DeleteMany(movieIds);
_eventAggregator.PublishEvent(new MoviesDeletedEvent(moviesToDelete, deleteFiles, addExclusion)); _eventAggregator.PublishEvent(new MoviesDeletedEvent(moviesToDelete, deleteFiles, addImportListExclusion));
foreach (var movie in moviesToDelete) foreach (var movie in moviesToDelete)
{ {

@ -21,7 +21,7 @@ namespace NzbDrone.Core.Movies
private readonly IMovieService _movieService; private readonly IMovieService _movieService;
private readonly IMovieMetadataService _movieMetadataService; private readonly IMovieMetadataService _movieMetadataService;
private readonly IAddMovieService _addMovieService; private readonly IAddMovieService _addMovieService;
private readonly IImportExclusionsService _importExclusionService; private readonly IImportListExclusionService _importListExclusionService;
private readonly IEventAggregator _eventAggregator; private readonly IEventAggregator _eventAggregator;
private readonly Logger _logger; private readonly Logger _logger;
@ -31,7 +31,7 @@ namespace NzbDrone.Core.Movies
IMovieService movieService, IMovieService movieService,
IMovieMetadataService movieMetadataService, IMovieMetadataService movieMetadataService,
IAddMovieService addMovieService, IAddMovieService addMovieService,
IImportExclusionsService importExclusionsService, IImportListExclusionService importListExclusionService,
IEventAggregator eventAggregator, IEventAggregator eventAggregator,
Logger logger) Logger logger)
{ {
@ -40,7 +40,7 @@ namespace NzbDrone.Core.Movies
_movieService = movieService; _movieService = movieService;
_movieMetadataService = movieMetadataService; _movieMetadataService = movieMetadataService;
_addMovieService = addMovieService; _addMovieService = addMovieService;
_importExclusionService = importExclusionsService; _importListExclusionService = importListExclusionService;
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_logger = logger; _logger = logger;
} }
@ -127,7 +127,7 @@ namespace NzbDrone.Core.Movies
{ {
var existingMovies = _movieService.AllMovieTmdbIds(); var existingMovies = _movieService.AllMovieTmdbIds();
var collectionMovies = _movieMetadataService.GetMoviesByCollectionTmdbId(collection.TmdbId); var collectionMovies = _movieMetadataService.GetMoviesByCollectionTmdbId(collection.TmdbId);
var excludedMovies = _importExclusionService.GetAllExclusions().Select(e => e.TmdbId); var excludedMovies = _importListExclusionService.All().Select(e => e.TmdbId);
var moviesToAdd = collectionMovies.Where(m => !existingMovies.Contains(m.TmdbId)).Where(m => !excludedMovies.Contains(m.TmdbId)); var moviesToAdd = collectionMovies.Where(m => !existingMovies.Contains(m.TmdbId)).Where(m => !excludedMovies.Contains(m.TmdbId));
if (moviesToAdd.Any()) if (moviesToAdd.Any())

@ -31,7 +31,7 @@ namespace Radarr.Api.V3.Collections
private readonly IMovieService _movieService; private readonly IMovieService _movieService;
private readonly IMovieMetadataService _movieMetadataService; private readonly IMovieMetadataService _movieMetadataService;
private readonly IMovieTranslationService _movieTranslationService; private readonly IMovieTranslationService _movieTranslationService;
private readonly IImportExclusionsService _importExclusionService; private readonly IImportListExclusionService _importListExclusionService;
private readonly IConfigService _configService; private readonly IConfigService _configService;
private readonly IBuildFileNames _fileNameBuilder; private readonly IBuildFileNames _fileNameBuilder;
private readonly INamingConfigService _namingService; private readonly INamingConfigService _namingService;
@ -42,7 +42,7 @@ namespace Radarr.Api.V3.Collections
IMovieService movieService, IMovieService movieService,
IMovieMetadataService movieMetadataService, IMovieMetadataService movieMetadataService,
IMovieTranslationService movieTranslationService, IMovieTranslationService movieTranslationService,
IImportExclusionsService importExclusionsService, IImportListExclusionService importListExclusionService,
IConfigService configService, IConfigService configService,
IBuildFileNames fileNameBuilder, IBuildFileNames fileNameBuilder,
INamingConfigService namingService, INamingConfigService namingService,
@ -53,7 +53,7 @@ namespace Radarr.Api.V3.Collections
_movieService = movieService; _movieService = movieService;
_movieMetadataService = movieMetadataService; _movieMetadataService = movieMetadataService;
_movieTranslationService = movieTranslationService; _movieTranslationService = movieTranslationService;
_importExclusionService = importExclusionsService; _importListExclusionService = importListExclusionService;
_configService = configService; _configService = configService;
_fileNameBuilder = fileNameBuilder; _fileNameBuilder = fileNameBuilder;
_namingService = namingService; _namingService = namingService;
@ -158,7 +158,7 @@ namespace Radarr.Api.V3.Collections
var configLanguage = (Language)_configService.MovieInfoLanguage; var configLanguage = (Language)_configService.MovieInfoLanguage;
var existingMoviesTmdbIds = _movieService.AllMovieWithCollectionsTmdbIds(); var existingMoviesTmdbIds = _movieService.AllMovieWithCollectionsTmdbIds();
var listExclusions = _importExclusionService.GetAllExclusions(); var listExclusions = _importListExclusionService.All();
var allCollectionMovies = _movieMetadataService.GetMoviesWithCollections() var allCollectionMovies = _movieMetadataService.GetMoviesWithCollections()
.GroupBy(x => x.CollectionTmdbId) .GroupBy(x => x.CollectionTmdbId)
@ -209,7 +209,7 @@ namespace Radarr.Api.V3.Collections
var configLanguage = (Language)_configService.MovieInfoLanguage; var configLanguage = (Language)_configService.MovieInfoLanguage;
var existingMoviesTmdbIds = _movieService.AllMovieWithCollectionsTmdbIds(); var existingMoviesTmdbIds = _movieService.AllMovieWithCollectionsTmdbIds();
var listExclusions = _importExclusionService.GetAllExclusions(); var listExclusions = _importListExclusionService.All();
foreach (var movie in _movieMetadataService.GetMoviesByCollectionTmdbId(collection.TmdbId)) foreach (var movie in _movieMetadataService.GetMoviesByCollectionTmdbId(collection.TmdbId))
{ {

@ -1,67 +0,0 @@
using System.Collections.Generic;
using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Core.ImportLists.ImportExclusions;
using Radarr.Http;
using Radarr.Http.REST;
using Radarr.Http.REST.Attributes;
namespace Radarr.Api.V3.ImportLists
{
[V3ApiController("exclusions")]
public class ImportExclusionsController : RestController<ImportExclusionsResource>
{
private readonly IImportExclusionsService _exclusionService;
public ImportExclusionsController(IImportExclusionsService exclusionService)
{
_exclusionService = exclusionService;
SharedValidator.RuleFor(c => c.TmdbId).GreaterThan(0);
SharedValidator.RuleFor(c => c.MovieTitle).NotEmpty();
SharedValidator.RuleFor(c => c.MovieYear).GreaterThan(0);
}
[HttpGet]
public List<ImportExclusionsResource> GetAll()
{
return _exclusionService.GetAllExclusions().ToResource();
}
protected override ImportExclusionsResource GetResourceById(int id)
{
return _exclusionService.GetById(id).ToResource();
}
[RestPutById]
[Consumes("application/json")]
public ActionResult<ImportExclusionsResource> UpdateExclusion([FromBody] ImportExclusionsResource exclusionResource)
{
var model = exclusionResource.ToModel();
return Accepted(_exclusionService.Update(model));
}
[RestPostById]
[Consumes("application/json")]
public ActionResult<ImportExclusionsResource> AddExclusion([FromBody] ImportExclusionsResource exclusionResource)
{
var model = exclusionResource.ToModel();
return Created(_exclusionService.AddExclusion(model).Id);
}
[HttpPost("bulk")]
public object AddExclusions([FromBody] List<ImportExclusionsResource> resource)
{
var newMovies = resource.ToModel();
return _exclusionService.AddExclusions(newMovies).ToResource();
}
[RestDeleteById]
public void RemoveExclusion(int id)
{
_exclusionService.RemoveExclusion(new ImportExclusion { Id = id });
}
}
}

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace Radarr.Api.V3.ImportLists
{
public class ImportListExclusionBulkResource
{
public HashSet<int> Ids { get; set; }
}
}

@ -0,0 +1,78 @@
using System.Collections.Generic;
using System.Linq;
using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Core.ImportLists.ImportExclusions;
using Radarr.Http;
using Radarr.Http.REST;
using Radarr.Http.REST.Attributes;
namespace Radarr.Api.V3.ImportLists
{
[V3ApiController("exclusions")]
public class ImportListExclusionController : RestController<ImportListExclusionResource>
{
private readonly IImportListExclusionService _importListExclusionService;
public ImportListExclusionController(IImportListExclusionService importListExclusionService)
{
_importListExclusionService = importListExclusionService;
SharedValidator.RuleFor(c => c.TmdbId).GreaterThan(0);
SharedValidator.RuleFor(c => c.MovieTitle).NotEmpty();
SharedValidator.RuleFor(c => c.MovieYear).GreaterThan(0);
}
[HttpGet]
[Produces("application/json")]
public List<ImportListExclusionResource> GetImportListExclusions()
{
return _importListExclusionService.All().ToResource();
}
protected override ImportListExclusionResource GetResourceById(int id)
{
return _importListExclusionService.Get(id).ToResource();
}
[RestPostById]
[Consumes("application/json")]
public ActionResult<ImportListExclusionResource> AddImportListExclusion([FromBody] ImportListExclusionResource resource)
{
var importListExclusion = _importListExclusionService.Add(resource.ToModel());
return Created(importListExclusion.Id);
}
[RestPutById]
[Consumes("application/json")]
public ActionResult<ImportListExclusionResource> UpdateImportListExclusion([FromBody] ImportListExclusionResource resource)
{
_importListExclusionService.Update(resource.ToModel());
return Accepted(resource.Id);
}
[HttpPost("bulk")]
public object AddImportListExclusions([FromBody] List<ImportListExclusionResource> resources)
{
var importListExclusions = _importListExclusionService.Add(resources.ToModel());
return importListExclusions.ToResource();
}
[RestDeleteById]
public void DeleteImportListExclusion(int id)
{
_importListExclusionService.Delete(id);
}
[HttpDelete("bulk")]
[Produces("application/json")]
public object DeleteImportListExclusions([FromBody] ImportListExclusionBulkResource resource)
{
_importListExclusionService.Delete(resource.Ids.ToList());
return new { };
}
}
}

@ -4,7 +4,7 @@ using NzbDrone.Core.ImportLists.ImportExclusions;
namespace Radarr.Api.V3.ImportLists namespace Radarr.Api.V3.ImportLists
{ {
public class ImportExclusionsResource : ProviderResource<ImportExclusionsResource> public class ImportListExclusionResource : ProviderResource<ImportListExclusionResource>
{ {
// public int Id { get; set; } // public int Id { get; set; }
public int TmdbId { get; set; } public int TmdbId { get; set; }
@ -12,16 +12,16 @@ namespace Radarr.Api.V3.ImportLists
public int MovieYear { get; set; } public int MovieYear { get; set; }
} }
public static class ImportExclusionsResourceMapper public static class ImportListExclusionResourceMapper
{ {
public static ImportExclusionsResource ToResource(this ImportExclusion model) public static ImportListExclusionResource ToResource(this ImportListExclusion model)
{ {
if (model == null) if (model == null)
{ {
return null; return null;
} }
return new ImportExclusionsResource return new ImportListExclusionResource
{ {
Id = model.Id, Id = model.Id,
TmdbId = model.TmdbId, TmdbId = model.TmdbId,
@ -30,14 +30,14 @@ namespace Radarr.Api.V3.ImportLists
}; };
} }
public static List<ImportExclusionsResource> ToResource(this IEnumerable<ImportExclusion> exclusions) public static List<ImportListExclusionResource> ToResource(this IEnumerable<ImportListExclusion> exclusions)
{ {
return exclusions.Select(ToResource).ToList(); return exclusions.Select(ToResource).ToList();
} }
public static ImportExclusion ToModel(this ImportExclusionsResource resource) public static ImportListExclusion ToModel(this ImportListExclusionResource resource)
{ {
return new ImportExclusion return new ImportListExclusion
{ {
Id = resource.Id, Id = resource.Id,
TmdbId = resource.TmdbId, TmdbId = resource.TmdbId,
@ -46,7 +46,7 @@ namespace Radarr.Api.V3.ImportLists
}; };
} }
public static List<ImportExclusion> ToModel(this IEnumerable<ImportExclusionsResource> resources) public static List<ImportListExclusion> ToModel(this IEnumerable<ImportListExclusionResource> resources)
{ {
return resources.Select(ToModel).ToList(); return resources.Select(ToModel).ToList();
} }

@ -25,7 +25,7 @@ namespace Radarr.Api.V3.ImportLists
private readonly IBuildFileNames _fileNameBuilder; private readonly IBuildFileNames _fileNameBuilder;
private readonly IImportListMovieService _listMovieService; private readonly IImportListMovieService _listMovieService;
private readonly IImportListFactory _importListFactory; private readonly IImportListFactory _importListFactory;
private readonly IImportExclusionsService _importExclusionService; private readonly IImportListExclusionService _importListExclusionService;
private readonly INamingConfigService _namingService; private readonly INamingConfigService _namingService;
private readonly IMovieTranslationService _movieTranslationService; private readonly IMovieTranslationService _movieTranslationService;
private readonly IConfigService _configService; private readonly IConfigService _configService;
@ -36,7 +36,7 @@ namespace Radarr.Api.V3.ImportLists
IBuildFileNames fileNameBuilder, IBuildFileNames fileNameBuilder,
IImportListMovieService listMovieService, IImportListMovieService listMovieService,
IImportListFactory importListFactory, IImportListFactory importListFactory,
IImportExclusionsService importExclusionsService, IImportListExclusionService importListExclusionService,
INamingConfigService namingService, INamingConfigService namingService,
IMovieTranslationService movieTranslationService, IMovieTranslationService movieTranslationService,
IConfigService configService) IConfigService configService)
@ -47,7 +47,7 @@ namespace Radarr.Api.V3.ImportLists
_fileNameBuilder = fileNameBuilder; _fileNameBuilder = fileNameBuilder;
_listMovieService = listMovieService; _listMovieService = listMovieService;
_importListFactory = importListFactory; _importListFactory = importListFactory;
_importExclusionService = importExclusionsService; _importListExclusionService = importListExclusionService;
_namingService = namingService; _namingService = namingService;
_movieTranslationService = movieTranslationService; _movieTranslationService = movieTranslationService;
_configService = configService; _configService = configService;
@ -59,7 +59,7 @@ namespace Radarr.Api.V3.ImportLists
var movieLanguage = (Language)_configService.MovieInfoLanguage; var movieLanguage = (Language)_configService.MovieInfoLanguage;
var realResults = new List<ImportListMoviesResource>(); var realResults = new List<ImportListMoviesResource>();
var listExclusions = _importExclusionService.GetAllExclusions(); var listExclusions = _importListExclusionService.All();
var existingTmdbIds = _movieService.AllMovieTmdbIds(); var existingTmdbIds = _movieService.AllMovieTmdbIds();
if (includeRecommendations) if (includeRecommendations)

Loading…
Cancel
Save