You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.3 KiB
62 lines
2.3 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NzbDrone.Core.Datastore;
|
|
using NzbDrone.Core.Messaging.Events;
|
|
using NzbDrone.Core.Movies;
|
|
|
|
namespace NzbDrone.Core.Blocklisting
|
|
{
|
|
public interface IBlocklistRepository : IBasicRepository<Blocklist>
|
|
{
|
|
List<Blocklist> BlocklistedByTitle(int movieId, string sourceTitle);
|
|
List<Blocklist> BlocklistedByTorrentInfoHash(int movieId, string torrentInfoHash);
|
|
List<Blocklist> BlocklistedByMovie(int movieId);
|
|
void DeleteForMovies(List<int> movieIds);
|
|
}
|
|
|
|
public class BlocklistRepository : BasicRepository<Blocklist>, IBlocklistRepository
|
|
{
|
|
public BlocklistRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
|
: base(database, eventAggregator)
|
|
{
|
|
}
|
|
|
|
public List<Blocklist> BlocklistedByTitle(int movieId, string sourceTitle)
|
|
{
|
|
return Query(x => x.MovieId == movieId && x.SourceTitle.Contains(sourceTitle));
|
|
}
|
|
|
|
public List<Blocklist> BlocklistedByTorrentInfoHash(int movieId, string torrentInfoHash)
|
|
{
|
|
return Query(x => x.MovieId == movieId && x.TorrentInfoHash.Contains(torrentInfoHash));
|
|
}
|
|
|
|
public List<Blocklist> BlocklistedByMovie(int movieId)
|
|
{
|
|
var builder = Builder().Join<Blocklist, Movie>((h, a) => h.MovieId == a.Id)
|
|
.Where<Blocklist>(h => h.MovieId == movieId);
|
|
|
|
return _database.QueryJoined<Blocklist, Movie>(builder, (blocklist, movie) =>
|
|
{
|
|
blocklist.Movie = movie;
|
|
return blocklist;
|
|
}).OrderByDescending(h => h.Date).ToList();
|
|
}
|
|
|
|
public void DeleteForMovies(List<int> movieIds)
|
|
{
|
|
Delete(x => movieIds.Contains(x.MovieId));
|
|
}
|
|
|
|
protected override SqlBuilder PagedBuilder() => new SqlBuilder(_database.DatabaseType)
|
|
.Join<Blocklist, Movie>((b, m) => b.MovieId == m.Id)
|
|
.LeftJoin<Movie, MovieMetadata>((m, mm) => m.MovieMetadataId == mm.Id);
|
|
|
|
protected override IEnumerable<Blocklist> PagedQuery(SqlBuilder sql) => _database.QueryJoined<Blocklist, Movie>(sql, (bl, movie) =>
|
|
{
|
|
bl.Movie = movie;
|
|
return bl;
|
|
});
|
|
}
|
|
}
|