diff --git a/src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs b/src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs index 2cd834624..056632efc 100644 --- a/src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs @@ -20,6 +20,9 @@ namespace Ombi.Core.Engine.Interfaces Task ApproveMovieById(int requestId); Task DenyMovieById(int modelId, string denyReason); Task> GetRequests(int count, int position, string sortProperty, string sortOrder); + + Task> GetUnavailableRequests(int count, int position, string sortProperty, + string sortOrder); Task UpdateAdvancedOptions(MovieAdvancedOptions options); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs index 33b45ed54..c7272605e 100644 --- a/src/Ombi.Core/Engine/MovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs @@ -209,13 +209,13 @@ namespace Ombi.Core.Engine { allRequests = MovieRepository.GetWithUser(shouldHide - .UserId); + .UserId); } else { allRequests = MovieRepository - .GetWithUser(); + .GetWithUser(); } var prop = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find(sortProperty, true); @@ -230,8 +230,8 @@ namespace Ombi.Core.Engine //var secondProp = TypeDescriptor.GetProperties(propType).Find(properties[1], true); } - allRequests = sortOrder.Equals("asc", StringComparison.InvariantCultureIgnoreCase) - ? allRequests.OrderBy(x => prop.GetValue(x)) + allRequests = sortOrder.Equals("asc", StringComparison.InvariantCultureIgnoreCase) + ? allRequests.OrderBy(x => prop.GetValue(x)) : allRequests.OrderByDescending(x => prop.GetValue(x)); var total = await allRequests.CountAsync(); var requests = await allRequests.Skip(position).Take(count) @@ -246,9 +246,55 @@ namespace Ombi.Core.Engine Collection = requests, Total = total }; + } + public async Task> GetUnavailableRequests(int count, int position, string sortProperty, string sortOrder) + { + var shouldHide = await HideFromOtherUsers(); + IQueryable allRequests; + if (shouldHide.Hide) + { + allRequests = + MovieRepository.GetWithUser(shouldHide + .UserId).Where(x => !x.Available); + } + else + { + allRequests = + MovieRepository + .GetWithUser().Where(x => !x.Available); + } + + var prop = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find(sortProperty, true); + if (sortProperty.Contains('.')) + { + // This is a navigation property currently not supported + prop = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find("RequestedDate", true); + //var properties = sortProperty.Split(new []{'.'}, StringSplitOptions.RemoveEmptyEntries); + //var firstProp = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find(properties[0], true); + //var propType = firstProp.PropertyType; + //var secondProp = TypeDescriptor.GetProperties(propType).Find(properties[1], true); + } + + allRequests = sortOrder.Equals("asc", StringComparison.InvariantCultureIgnoreCase) + ? allRequests.OrderBy(x => prop.GetValue(x)) + : allRequests.OrderByDescending(x => prop.GetValue(x)); + var total = await allRequests.CountAsync(); + var requests = await allRequests.Skip(position).Take(count) + .ToListAsync(); + requests.ForEach(async x => + { + x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath); + await CheckForSubscription(shouldHide, x); + }); + return new RequestsViewModel + { + Collection = requests, + Total = total + }; } + public async Task UpdateAdvancedOptions(MovieAdvancedOptions options) { var request = await MovieRepository.Find(options.RequestId); diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index b82335c80..ee9822fff 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -266,7 +266,61 @@ namespace Ombi.Core.Engine // Make sure we do not show duplicate child requests allRequests = allRequests.DistinctBy(x => x.ParentRequest.Title).ToList(); - + + allRequests = allRequests.Skip(position).Take(count).ToList(); + + return new RequestsViewModel + { + Collection = allRequests, + Total = total, + }; + } + public async Task> GetUnavailableRequests(int count, int position, string sortProperty, string sortOrder) + { + var shouldHide = await HideFromOtherUsers(); + List allRequests; + if (shouldHide.Hide) + { + allRequests = await TvRepository.GetChild(shouldHide.UserId).Where(x => !x.Available).ToListAsync(); + + // Filter out children + + FilterChildren(allRequests, shouldHide); + } + else + { + allRequests = await TvRepository.GetChild().Where(x => !x.Available).ToListAsync(); + + } + + if (allRequests == null) + { + return new RequestsViewModel(); + } + + var total = allRequests.Count; + + + var prop = TypeDescriptor.GetProperties(typeof(ChildRequests)).Find(sortProperty, true); + + if (sortProperty.Contains('.')) + { + // This is a navigation property currently not supported + prop = TypeDescriptor.GetProperties(typeof(ChildRequests)).Find("Title", true); + //var properties = sortProperty.Split(new []{'.'}, StringSplitOptions.RemoveEmptyEntries); + //var firstProp = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find(properties[0], true); + //var propType = firstProp.PropertyType; + //var secondProp = TypeDescriptor.GetProperties(propType).Find(properties[1], true); + } + allRequests = sortOrder.Equals("asc", StringComparison.InvariantCultureIgnoreCase) + ? allRequests.OrderBy(x => prop.GetValue(x)).ToList() + : allRequests.OrderByDescending(x => prop.GetValue(x)).ToList(); + allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + + // Make sure we do not show duplicate child requests + allRequests = allRequests.DistinctBy(x => x.ParentRequest.Title).ToList(); + allRequests = allRequests.Skip(position).Take(count).ToList(); + return new RequestsViewModel { Collection = allRequests, diff --git a/src/Ombi/Controllers/V2/RequestsController.cs b/src/Ombi/Controllers/V2/RequestsController.cs index 8acd40139..8c8c5bc5f 100644 --- a/src/Ombi/Controllers/V2/RequestsController.cs +++ b/src/Ombi/Controllers/V2/RequestsController.cs @@ -39,6 +39,19 @@ namespace Ombi.Controllers.V2 return await _movieRequestEngine.GetRequests(count, position, sort, sortOrder); } + /// + /// Gets the unavailable movie requests. + /// + /// The count of items you want to return. e.g. 30 + /// The position. e.g. position 60 for a 2nd page (since we have already got the first 30 items) + /// The item to sort on e.g. "requestDate" + /// asc or desc + [HttpGet("movie/unavailable/{count:int}/{position:int}/{sort}/{sortOrder}")] + public async Task> GetNotAvailableRequests(int count, int position, string sort, string sortOrder) + { + return await _movieRequestEngine.GetUnavailableRequests(count, position, sort, sortOrder); + } + /// /// Gets Tv requests. /// @@ -52,6 +65,19 @@ namespace Ombi.Controllers.V2 return await _tvRequestEngine.GetRequests(count, position, sort, sortOrder); } + /// + /// Gets unavailable Tv requests. + /// + /// The count of items you want to return. e.g. 30 + /// The position. e.g. position 60 for a 2nd page (since we have already got the first 30 items) + /// The item to sort on e.g. "requestDate" + /// asc or desc + [HttpGet("tv/{count:int}/{position:int}/{sort}/{sortOrder}")] + public async Task> GetNotAvailableTvRequests(int count, int position, string sort, string sortOrder) + { + return await _tvRequestEngine.GetRequests(count, position, sort, sortOrder); + } + [HttpPost("movie/advancedoptions")] public async Task UpdateAdvancedOptions([FromBody] MovieAdvancedOptions options) {