mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-05 10:32:35 +01:00
Merge pull request #1096 from geogolem/refactorFilteringExpression
refactor so that filteringExpressions are constructed in one place
This commit is contained in:
commit
3d9fd3ff25
@ -116,56 +116,9 @@ private PagingResource<MovieResource> GetMoviePaged(PagingResource<MovieResource
|
|||||||
{
|
{
|
||||||
var pagingSpec = pagingResource.MapToPagingSpec<MovieResource, Core.Tv.Movie>();
|
var pagingSpec = pagingResource.MapToPagingSpec<MovieResource, Core.Tv.Movie>();
|
||||||
|
|
||||||
if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
|
pagingSpec.FilterExpression = _moviesService.ConstructFilterExpression(pagingResource.FilterKey, pagingResource.FilterValue, pagingResource.FilterType);
|
||||||
{
|
|
||||||
pagingSpec.FilterExpression = v => v.Monitored == false;
|
|
||||||
}
|
|
||||||
else if (pagingResource.FilterKey == "monitored")
|
|
||||||
{
|
|
||||||
pagingSpec.FilterExpression = v => v.Monitored == true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pagingResource.FilterKey == "status")
|
return ApplyToPage(_moviesService.Paged, pagingSpec, MovieResourceMapper.ToResource);
|
||||||
{
|
|
||||||
switch (pagingResource.FilterValue)
|
|
||||||
{
|
|
||||||
case "released":
|
|
||||||
pagingSpec.FilterExpression = v => v.Status == MovieStatusType.Released;
|
|
||||||
break;
|
|
||||||
case "inCinemas":
|
|
||||||
pagingSpec.FilterExpression = v => v.Status == MovieStatusType.InCinemas;
|
|
||||||
break;
|
|
||||||
case "announced":
|
|
||||||
pagingSpec.FilterExpression = v => v.Status == MovieStatusType.Announced;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pagingResource.FilterKey == "downloaded")
|
|
||||||
{
|
|
||||||
pagingSpec.FilterExpression = v => v.MovieFileId == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pagingResource.FilterKey == "title")
|
|
||||||
{
|
|
||||||
if (pagingResource.FilterValue == string.Empty || pagingResource.FilterValue == null)
|
|
||||||
{
|
|
||||||
pagingSpec.FilterExpression = v => true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (pagingResource.FilterType == "contains")
|
|
||||||
{
|
|
||||||
pagingSpec.FilterExpression = v => v.CleanTitle.Contains(pagingResource.FilterValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pagingSpec.FilterExpression = v => v.CleanTitle == pagingResource.FilterValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ApplyToPage(_moviesService.Paged, pagingSpec, MovieResourceMapper.ToResource);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MovieResource MapToResource(Core.Tv.Movie movies)
|
protected MovieResource MapToResource(Core.Tv.Movie movies)
|
||||||
|
@ -41,7 +41,7 @@ public interface IMovieService
|
|||||||
bool MoviePathExists(string folder);
|
bool MoviePathExists(string folder);
|
||||||
void RemoveAddOptions(Movie movie);
|
void RemoveAddOptions(Movie movie);
|
||||||
List<Movie> MoviesWithFiles(int movieId);
|
List<Movie> MoviesWithFiles(int movieId);
|
||||||
System.Linq.Expressions.Expression<Func<Core.Tv.Movie, bool>> ConstructFilterExpression(string FilterKey, string FilterValue);
|
System.Linq.Expressions.Expression<Func<Core.Tv.Movie, bool>> ConstructFilterExpression(string FilterKey, string FilterValue, string filterType = null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MovieService : IMovieService, IHandle<MovieFileAddedEvent>,
|
public class MovieService : IMovieService, IHandle<MovieFileAddedEvent>,
|
||||||
@ -69,42 +69,65 @@ public MovieService(IMovieRepository movieRepository,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public System.Linq.Expressions.Expression<Func<Core.Tv.Movie, bool>> ConstructFilterExpression(string FilterKey, string FilterValue)
|
public System.Linq.Expressions.Expression<Func<Core.Tv.Movie, bool>> ConstructFilterExpression(string FilterKey, string FilterValue, string FilterType = null)
|
||||||
{
|
{
|
||||||
if (FilterKey == "all" && FilterValue == "all")
|
//if (FilterKey == "all" && FilterValue == "all")
|
||||||
{
|
//{
|
||||||
return v => v.Monitored == true || v.Monitored == false;
|
// return v => v.Monitored == true || v.Monitored == false;
|
||||||
}
|
//}
|
||||||
else if (FilterKey == "monitored" && FilterValue == "false")
|
if (FilterKey == "moviemonitored" && FilterValue == "false")
|
||||||
{
|
{
|
||||||
return v => v.Monitored == false;
|
return v => v.Monitored == false;
|
||||||
}
|
}
|
||||||
else if (FilterKey == "monitored" && FilterValue == "true")
|
else if (FilterKey == "moviemonitored" && FilterValue == "true")
|
||||||
{
|
{
|
||||||
return v => v.Monitored == true;
|
return v => v.Monitored == true;
|
||||||
}
|
}
|
||||||
else if (FilterKey == "moviestatus" && FilterValue == "available")
|
else if (FilterKey == "moviestatus")
|
||||||
{
|
{
|
||||||
//TODO: might need to handle PreDB here
|
switch (FilterValue)
|
||||||
return v => v.Monitored == true &&
|
{
|
||||||
|
case "released":
|
||||||
|
return v => v.Status == MovieStatusType.Released;
|
||||||
|
break;
|
||||||
|
case "inCinemas":
|
||||||
|
return v => v.Status == MovieStatusType.InCinemas;
|
||||||
|
break;
|
||||||
|
case "announced":
|
||||||
|
return v => v.Status == MovieStatusType.Announced;
|
||||||
|
break;
|
||||||
|
case "available":
|
||||||
|
return v => v.Monitored == true &&
|
||||||
((v.MinimumAvailability == MovieStatusType.Released && v.Status >= MovieStatusType.Released) ||
|
((v.MinimumAvailability == MovieStatusType.Released && v.Status >= MovieStatusType.Released) ||
|
||||||
(v.MinimumAvailability == MovieStatusType.InCinemas && v.Status >= MovieStatusType.InCinemas) ||
|
(v.MinimumAvailability == MovieStatusType.InCinemas && v.Status >= MovieStatusType.InCinemas) ||
|
||||||
(v.MinimumAvailability == MovieStatusType.Announced && v.Status >= MovieStatusType.Announced) ||
|
(v.MinimumAvailability == MovieStatusType.Announced && v.Status >= MovieStatusType.Announced) ||
|
||||||
(v.MinimumAvailability == MovieStatusType.PreDB && v.Status >= MovieStatusType.Released));
|
(v.MinimumAvailability == MovieStatusType.PreDB && v.Status >= MovieStatusType.Released));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (FilterKey == "moviestatus" && FilterValue == "announced")
|
else if (FilterKey == "moviedownloaded")
|
||||||
{
|
{
|
||||||
return v => v.Status == MovieStatusType.Announced;
|
return v => v.MovieFileId == 0;
|
||||||
}
|
}
|
||||||
else if (FilterKey == "moviestatus" && FilterValue == "incinemas")
|
else if (FilterKey == "title")
|
||||||
{
|
{
|
||||||
return v => v.Status == MovieStatusType.InCinemas;
|
if (FilterValue == string.Empty || FilterValue == null)
|
||||||
|
{
|
||||||
|
return v => true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (FilterType == "contains")
|
||||||
|
{
|
||||||
|
return v => v.CleanTitle.Contains(FilterValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return v => v.CleanTitle == FilterValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (FilterKey == "moviestatus" && FilterValue == "released")
|
return v => true;
|
||||||
{
|
|
||||||
return v => v.Status == MovieStatusType.Released;
|
|
||||||
}
|
|
||||||
return v => v.Monitored == true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Movie GetMovie(int movieId)
|
public Movie GetMovie(int movieId)
|
||||||
|
@ -19,33 +19,33 @@ var filterModes = {
|
|||||||
null
|
null
|
||||||
],
|
],
|
||||||
'continuing' : [
|
'continuing' : [
|
||||||
'status',
|
'moviestatus',
|
||||||
'continuing'
|
'continuing'
|
||||||
],
|
],
|
||||||
'ended' : [
|
'ended' : [
|
||||||
'status',
|
'moviestatus',
|
||||||
'ended'
|
'ended'
|
||||||
],
|
],
|
||||||
'monitored' : [
|
'monitored' : [
|
||||||
'monitored',
|
'moviemonitored',
|
||||||
true
|
true
|
||||||
],
|
],
|
||||||
'missing' : [
|
'missing' : [
|
||||||
'downloaded',
|
'moviedownloaded',
|
||||||
false
|
false
|
||||||
],
|
],
|
||||||
'released' : [
|
'released' : [
|
||||||
"status",
|
"moviestatus",
|
||||||
"released",
|
"released",
|
||||||
//function(model) { return model.getStatus() == "released"; }
|
//function(model) { return model.getStatus() == "released"; }
|
||||||
],
|
],
|
||||||
'announced' : [
|
'announced' : [
|
||||||
"status",
|
"moviestatus",
|
||||||
"announced",
|
"announced",
|
||||||
//function(model) { return model.getStatus() == "announced"; }
|
//function(model) { return model.getStatus() == "announced"; }
|
||||||
],
|
],
|
||||||
'cinemas' : [
|
'cinemas' : [
|
||||||
"status",
|
"moviestatus",
|
||||||
"inCinemas",
|
"inCinemas",
|
||||||
//function(model) { return model.getStatus() == "inCinemas"; }
|
//function(model) { return model.getStatus() == "inCinemas"; }
|
||||||
]
|
]
|
||||||
|
@ -31,11 +31,11 @@ var Collection = PagableCollection.extend({
|
|||||||
|
|
||||||
filterModes : {
|
filterModes : {
|
||||||
'monitored' : [
|
'monitored' : [
|
||||||
'monitored',
|
'moviemonitored',
|
||||||
'true'
|
'true'
|
||||||
],
|
],
|
||||||
'unmonitored' : [
|
'unmonitored' : [
|
||||||
'monitored',
|
'moviemonitored',
|
||||||
'false'
|
'false'
|
||||||
],
|
],
|
||||||
'announced' : [
|
'announced' : [
|
||||||
@ -44,7 +44,7 @@ var Collection = PagableCollection.extend({
|
|||||||
],
|
],
|
||||||
'incinemas' : [
|
'incinemas' : [
|
||||||
'moviestatus',
|
'moviestatus',
|
||||||
'incinemas'
|
'inCinemas'
|
||||||
],
|
],
|
||||||
'released' : [
|
'released' : [
|
||||||
'moviestatus',
|
'moviestatus',
|
||||||
@ -77,4 +77,4 @@ var Collection = PagableCollection.extend({
|
|||||||
Collection = AsFilteredCollection.call(Collection);
|
Collection = AsFilteredCollection.call(Collection);
|
||||||
Collection = AsSortedCollection.call(Collection);
|
Collection = AsSortedCollection.call(Collection);
|
||||||
|
|
||||||
module.exports = AsPersistedStateCollection.call(Collection);
|
module.exports = AsPersistedStateCollection.call(Collection);
|
||||||
|
@ -30,11 +30,11 @@ var Collection = PagableCollection.extend({
|
|||||||
|
|
||||||
filterModes : {
|
filterModes : {
|
||||||
'monitored' : [
|
'monitored' : [
|
||||||
'monitored',
|
'moviemonitored',
|
||||||
'true'
|
'true'
|
||||||
],
|
],
|
||||||
'unmonitored' : [
|
'unmonitored' : [
|
||||||
'monitored',
|
'moviemonitored',
|
||||||
'false'
|
'false'
|
||||||
],
|
],
|
||||||
'announced' : [
|
'announced' : [
|
||||||
@ -43,7 +43,7 @@ var Collection = PagableCollection.extend({
|
|||||||
],
|
],
|
||||||
'incinemas' : [
|
'incinemas' : [
|
||||||
'moviestatus',
|
'moviestatus',
|
||||||
'incinemas'
|
'inCinemas'
|
||||||
],
|
],
|
||||||
'released' : [
|
'released' : [
|
||||||
'moviestatus',
|
'moviestatus',
|
||||||
|
Loading…
Reference in New Issue
Block a user