2021-01-24 19:41:48 +00:00
|
|
|
using System.Collections.Generic;
|
2014-02-23 00:17:19 +00:00
|
|
|
using NzbDrone.Core.Datastore;
|
2013-10-23 06:36:31 +00:00
|
|
|
using NzbDrone.Core.Messaging.Events;
|
2017-08-16 21:55:59 +00:00
|
|
|
using NzbDrone.Core.Music;
|
2013-10-23 06:36:31 +00:00
|
|
|
|
2021-08-19 21:35:06 +00:00
|
|
|
namespace NzbDrone.Core.Blocklisting
|
2013-10-23 06:36:31 +00:00
|
|
|
{
|
2021-08-19 21:35:06 +00:00
|
|
|
public interface IBlocklistRepository : IBasicRepository<Blocklist>
|
2013-10-23 06:36:31 +00:00
|
|
|
{
|
2021-08-19 21:35:06 +00:00
|
|
|
List<Blocklist> BlocklistedByTitle(int artistId, string sourceTitle);
|
|
|
|
List<Blocklist> BlocklistedByTorrentInfoHash(int artistId, string torrentInfoHash);
|
|
|
|
List<Blocklist> BlocklistedByArtists(List<int> artistIds);
|
2021-01-24 19:41:48 +00:00
|
|
|
void DeleteForArtists(List<int> artistIds);
|
2013-10-23 06:36:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 21:35:06 +00:00
|
|
|
public class BlocklistRepository : BasicRepository<Blocklist>, IBlocklistRepository
|
2013-10-23 06:36:31 +00:00
|
|
|
{
|
2021-08-19 21:35:06 +00:00
|
|
|
public BlocklistRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
2020-01-03 12:49:24 +00:00
|
|
|
: base(database, eventAggregator)
|
2013-10-23 06:36:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-19 21:35:06 +00:00
|
|
|
public List<Blocklist> BlocklistedByTitle(int artistId, string sourceTitle)
|
2013-10-23 06:36:31 +00:00
|
|
|
{
|
2020-08-18 20:11:44 +00:00
|
|
|
return Query(e => e.ArtistId == artistId && e.SourceTitle.Contains(sourceTitle));
|
2014-02-23 00:17:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 21:35:06 +00:00
|
|
|
public List<Blocklist> BlocklistedByTorrentInfoHash(int artistId, string torrentInfoHash)
|
2015-04-20 03:25:59 +00:00
|
|
|
{
|
2020-08-18 20:11:44 +00:00
|
|
|
return Query(e => e.ArtistId == artistId && e.TorrentInfoHash.Contains(torrentInfoHash));
|
2015-04-20 03:25:59 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 21:35:06 +00:00
|
|
|
public List<Blocklist> BlocklistedByArtists(List<int> artistIds)
|
2014-02-23 00:17:19 +00:00
|
|
|
{
|
2021-01-24 19:41:48 +00:00
|
|
|
return Query(x => artistIds.Contains(x.ArtistId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DeleteForArtists(List<int> artistIds)
|
|
|
|
{
|
|
|
|
Delete(x => artistIds.Contains(x.ArtistId));
|
2013-10-23 06:36:31 +00:00
|
|
|
}
|
2014-04-22 21:29:04 +00:00
|
|
|
|
2022-01-26 00:08:27 +00:00
|
|
|
protected override SqlBuilder PagedBuilder() => new SqlBuilder(_database.DatabaseType).Join<Blocklist, Artist>((b, m) => b.ArtistId == m.Id);
|
2021-08-19 21:35:06 +00:00
|
|
|
protected override IEnumerable<Blocklist> PagedQuery(SqlBuilder builder) => _database.QueryJoined<Blocklist, Artist>(builder, (bl, artist) =>
|
2020-08-18 20:11:44 +00:00
|
|
|
{
|
|
|
|
bl.Artist = artist;
|
|
|
|
return bl;
|
|
|
|
});
|
2013-10-23 06:36:31 +00:00
|
|
|
}
|
|
|
|
}
|