2018-02-26 15:08:44 +00:00
|
|
|
using System;
|
2017-01-02 19:15:13 +00:00
|
|
|
using System.Collections.Generic;
|
2013-02-23 21:29:22 +00:00
|
|
|
using System.Linq;
|
2013-05-10 22:33:04 +00:00
|
|
|
using Marr.Data.QGen;
|
2013-02-23 21:29:22 +00:00
|
|
|
using NzbDrone.Core.Datastore;
|
2013-09-14 06:36:07 +00:00
|
|
|
using NzbDrone.Core.Messaging.Events;
|
2014-01-18 11:44:36 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
2018-03-14 20:41:36 +00:00
|
|
|
using NzbDrone.Core.Movies;
|
2013-02-23 21:29:22 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.History
|
|
|
|
{
|
|
|
|
public interface IHistoryRepository : IBasicRepository<History>
|
|
|
|
{
|
2018-02-26 15:08:44 +00:00
|
|
|
List<QualityModel> GetBestQualityInHistory(int movieId);
|
2014-12-19 00:26:42 +00:00
|
|
|
History MostRecentForDownloadId(string downloadId);
|
|
|
|
List<History> FindByDownloadId(string downloadId);
|
2018-02-26 15:08:44 +00:00
|
|
|
List<History> FindDownloadHistory(int idMovieId, QualityModel quality);
|
2018-09-10 19:25:10 +00:00
|
|
|
List<History> FindByMovieId(int movieId);
|
2017-03-09 23:45:08 +00:00
|
|
|
void DeleteForMovie(int movieId);
|
2017-01-02 19:15:13 +00:00
|
|
|
History MostRecentForMovie(int movieId);
|
2013-02-23 21:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
|
|
|
|
{
|
2013-09-18 05:28:05 +00:00
|
|
|
|
2015-05-03 19:46:21 +00:00
|
|
|
public HistoryRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
2013-09-14 06:36:07 +00:00
|
|
|
: base(database, eventAggregator)
|
2013-02-23 21:29:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-26 15:08:44 +00:00
|
|
|
public List<QualityModel> GetBestQualityInHistory(int movieId)
|
2013-02-23 21:29:22 +00:00
|
|
|
{
|
2018-02-26 15:08:44 +00:00
|
|
|
var history = Query.Where(c => c.MovieId == movieId);
|
2013-02-23 21:29:22 +00:00
|
|
|
|
2013-05-14 05:40:06 +00:00
|
|
|
return history.Select(h => h.Quality).ToList();
|
2013-02-23 21:29:22 +00:00
|
|
|
}
|
2013-05-07 02:32:43 +00:00
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
public History MostRecentForDownloadId(string downloadId)
|
|
|
|
{
|
|
|
|
return Query.Where(h => h.DownloadId == downloadId)
|
|
|
|
.OrderByDescending(h => h.Date)
|
|
|
|
.FirstOrDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<History> FindByDownloadId(string downloadId)
|
2014-04-01 20:07:41 +00:00
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
return Query.Where(h => h.DownloadId == downloadId);
|
2014-04-01 20:07:41 +00:00
|
|
|
}
|
|
|
|
|
2018-02-26 15:08:44 +00:00
|
|
|
public List<History> FindDownloadHistory(int idMovieId, QualityModel quality)
|
2014-04-01 20:07:41 +00:00
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
return Query.Where(h =>
|
2018-02-26 15:08:44 +00:00
|
|
|
h.MovieId == idMovieId &&
|
2014-12-19 00:26:42 +00:00
|
|
|
h.Quality == quality &&
|
|
|
|
(h.EventType == HistoryEventType.Grabbed ||
|
|
|
|
h.EventType == HistoryEventType.DownloadFailed ||
|
|
|
|
h.EventType == HistoryEventType.DownloadFolderImported)
|
|
|
|
).ToList();
|
2014-04-01 20:07:41 +00:00
|
|
|
}
|
|
|
|
|
2018-09-10 19:25:10 +00:00
|
|
|
public List<History> FindByMovieId(int movieId)
|
|
|
|
{
|
|
|
|
return Query.Where(h => h.MovieId == movieId);
|
|
|
|
}
|
|
|
|
|
2017-03-09 23:45:08 +00:00
|
|
|
public void DeleteForMovie(int movieId)
|
|
|
|
{
|
|
|
|
Delete(c => c.MovieId == movieId);
|
|
|
|
}
|
|
|
|
|
2014-02-01 22:09:22 +00:00
|
|
|
protected override SortBuilder<History> GetPagedQuery(QueryBuilder<History> query, PagingSpec<History> pagingSpec)
|
2013-10-04 06:01:02 +00:00
|
|
|
{
|
2018-03-14 20:41:36 +00:00
|
|
|
var baseQuery = query.Join<History, Movie>(JoinType.Inner, h => h.Movie, (h, e) => h.MovieId == e.Id);
|
2013-10-06 18:06:39 +00:00
|
|
|
|
2014-02-01 22:09:22 +00:00
|
|
|
return base.GetPagedQuery(baseQuery, pagingSpec);
|
2013-05-10 22:33:04 +00:00
|
|
|
}
|
2017-01-02 19:15:13 +00:00
|
|
|
|
|
|
|
public History MostRecentForMovie(int movieId)
|
|
|
|
{
|
|
|
|
return Query.Where(h => h.MovieId == movieId)
|
|
|
|
.OrderByDescending(h => h.Date)
|
|
|
|
.FirstOrDefault();
|
|
|
|
}
|
2013-02-23 21:29:22 +00:00
|
|
|
}
|
2018-02-26 15:08:44 +00:00
|
|
|
}
|