mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
parent
f058b8f364
commit
f246fa87dd
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Datastore;
|
||||
@ -10,6 +10,7 @@ public interface IAlternativeTitleRepository : IBasicRepository<AlternativeTitle
|
||||
{
|
||||
AlternativeTitle FindBySourceId(int sourceId);
|
||||
List<AlternativeTitle> FindBySourceIds(List<int> sourceIds);
|
||||
List<AlternativeTitle> FindByMovieId(int movieId);
|
||||
}
|
||||
|
||||
public class AlternativeTitleRepository : BasicRepository<AlternativeTitle>, IAlternativeTitleRepository
|
||||
@ -31,5 +32,10 @@ public List<AlternativeTitle> FindBySourceIds(List<int> sourceIds)
|
||||
{
|
||||
return Query.Where(t => t.SourceId.In(sourceIds)).ToList();
|
||||
}
|
||||
|
||||
public List<AlternativeTitle> FindByMovieId(int movieId)
|
||||
{
|
||||
return Query.Where(t => t.MovieId == movieId).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Movies.Events;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Movies.Events;
|
||||
|
||||
namespace NzbDrone.Core.Movies.AlternativeTitles
|
||||
{
|
||||
public interface IAlternativeTitleService
|
||||
{
|
||||
List<AlternativeTitle> GetAllTitlesForMovie(Movie movie);
|
||||
List<AlternativeTitle> GetAllTitlesForMovie(int movieId);
|
||||
AlternativeTitle AddAltTitle(AlternativeTitle title, Movie movie);
|
||||
List<AlternativeTitle> AddAltTitles(List<AlternativeTitle> titles, Movie movie);
|
||||
AlternativeTitle GetById(int id);
|
||||
void DeleteNotEnoughVotes(List<AlternativeTitle> mappingsTitles);
|
||||
}
|
||||
|
||||
public class AlternativeTitleService : IAlternativeTitleService
|
||||
public class AlternativeTitleService : IAlternativeTitleService, IHandleAsync<MovieDeletedEvent>
|
||||
{
|
||||
private readonly IAlternativeTitleRepository _titleRepo;
|
||||
private readonly IConfigService _configService;
|
||||
@ -44,9 +35,9 @@ public AlternativeTitleService(IAlternativeTitleRepository titleRepo,
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<AlternativeTitle> GetAllTitlesForMovie(Movie movie)
|
||||
public List<AlternativeTitle> GetAllTitlesForMovie(int movieId)
|
||||
{
|
||||
return _titleRepo.All().ToList();
|
||||
return _titleRepo.FindByMovieId(movieId).ToList();
|
||||
}
|
||||
|
||||
public AlternativeTitle AddAltTitle(AlternativeTitle title, Movie movie)
|
||||
@ -78,5 +69,12 @@ public void DeleteNotEnoughVotes(List<AlternativeTitle> mappingsTitles)
|
||||
var realT = _titleRepo.FindBySourceIds(toRemove.Select(t => t.SourceId).ToList());
|
||||
_titleRepo.DeleteMany(realT);
|
||||
}
|
||||
|
||||
public void HandleAsync(MovieDeletedEvent message)
|
||||
{
|
||||
var title = GetAllTitlesForMovie(message.Movie.Id);
|
||||
_titleRepo.DeleteMany(title);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user