From 9903f4d36c20b47e2db47e73374f818df5616e85 Mon Sep 17 00:00:00 2001 From: TidusJar Date: Tue, 31 Jul 2018 09:57:58 +0100 Subject: [PATCH] Removed all the references to the tree nodes! At last can get rid of that !wip --- .../Engine/Interfaces/ITvRequestEngine.cs | 2 - .../Engine/Interfaces/ITvSearchEngine.cs | 6 -- src/Ombi.Core/Engine/TreeNode.cs | 23 ------ src/Ombi.Core/Engine/TvRequestEngine.cs | 75 +------------------ src/Ombi.Core/Engine/TvSearchEngine.cs | 53 ------------- src/Ombi/Controllers/RequestController.cs | 23 ------ src/Ombi/Controllers/SearchController.cs | 72 +----------------- 7 files changed, 3 insertions(+), 251 deletions(-) delete mode 100644 src/Ombi.Core/Engine/TreeNode.cs diff --git a/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs b/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs index 348dc91e7..3f456a4a4 100644 --- a/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs @@ -15,9 +15,7 @@ namespace Ombi.Core.Engine.Interfaces Task DenyChildRequest(int requestId); Task> GetRequestsLite(int count, int position, OrderFilterModel type); Task> SearchTvRequest(string search); - Task>>> SearchTvRequestTree(string search); Task UpdateTvRequest(TvRequests request); - Task>>> GetRequestsTreeNode(int count, int position); Task> GetAllChldren(int tvId); Task UpdateChildRequest(ChildRequests request); Task RemoveTvChild(int requestId); diff --git a/src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs b/src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs index 53721f792..0926a7f9a 100644 --- a/src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs @@ -7,16 +7,10 @@ namespace Ombi.Core.Engine.Interfaces public interface ITvSearchEngine { Task> Search(string searchTerm); - Task>> SearchTreeNode(string searchTerm); - Task> GetShowInformationTreeNode(int tvdbid); Task GetShowInformation(int tvdbid); - Task>> PopularTree(); Task> Popular(); - Task>> AnticipatedTree(); Task> Anticipated(); - Task>> MostWatchesTree(); Task> MostWatches(); - Task>> TrendingTree(); Task> Trending(); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/TreeNode.cs b/src/Ombi.Core/Engine/TreeNode.cs deleted file mode 100644 index 14f2f4cb0..000000000 --- a/src/Ombi.Core/Engine/TreeNode.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; - -namespace Ombi.Core.Engine -{ - - public class TreeNode - { - public string Label { get; set; } - public T Data { get; set; } - public List> Children { get; set; } - public bool Leaf { get; set; } - public bool Expanded { get; set; } - } - - public class TreeNode - { - public string Label { get; set; } - public T Data { get; set; } - public List> Children { get; set; } - public bool Leaf { get; set; } - public bool Expanded { get; set; } - } -} \ No newline at end of file diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index e8fc65a26..76be03aff 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -196,38 +196,6 @@ namespace Ombi.Core.Engine Collection = allRequests }; } - - public async Task>>> GetRequestsTreeNode(int count, int position) - { - var shouldHide = await HideFromOtherUsers(); - List allRequests; - if (shouldHide.Hide) - { - allRequests = await TvRepository.Get(shouldHide.UserId) - .Include(x => x.ChildRequests) - .ThenInclude(x => x.SeasonRequests) - .ThenInclude(x => x.Episodes) - .Where(x => x.ChildRequests.Any()) - .OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate)) - .Skip(position).Take(count).ToListAsync(); - - FilterChildren(allRequests, shouldHide); - } - else - { - allRequests = await TvRepository.Get() - .Include(x => x.ChildRequests) - .ThenInclude(x => x.SeasonRequests) - .ThenInclude(x => x.Episodes) - .Where(x => x.ChildRequests.Any()) - .OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate)) - .Skip(position).Take(count).ToListAsync(); - } - - allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); - return ParseIntoTreeNode(allRequests); - } - public async Task> GetRequests() { var shouldHide = await HideFromOtherUsers(); @@ -350,24 +318,7 @@ namespace Ombi.Core.Engine return results; } - public async Task>>> SearchTvRequestTree(string search) - { - var shouldHide = await HideFromOtherUsers(); - IQueryable allRequests; - if (shouldHide.Hide) - { - allRequests = TvRepository.Get(shouldHide.UserId); - } - else - { - allRequests = TvRepository.Get(); - } - var results = await allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToListAsync(); - results.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); - return ParseIntoTreeNode(results); - } - - public async Task UpdateTvRequest(TvRequests request) + public async Task UpdateTvRequest(TvRequests request) { await Audit.Record(AuditType.Updated, AuditArea.TvRequest, $"Updated Request {request.Title}", Username); var allRequests = TvRepository.Get(); @@ -585,29 +536,7 @@ namespace Ombi.Core.Engine return await AfterRequest(model.ChildRequests.FirstOrDefault()); } - private static List>> ParseIntoTreeNode(IEnumerable result) - { - var node = new List>>(); - - foreach (var value in result) - { - node.Add(new TreeNode> - { - Data = value, - Children = new List>> - { - new TreeNode> - { - Data = SortEpisodes(value.ChildRequests), - Leaf = true - } - } - }); - } - return node; - } - - private static List SortEpisodes(List items) + private static List SortEpisodes(List items) { foreach (var value in items) { diff --git a/src/Ombi.Core/Engine/TvSearchEngine.cs b/src/Ombi.Core/Engine/TvSearchEngine.cs index bc5a2e984..253363ec1 100644 --- a/src/Ombi.Core/Engine/TvSearchEngine.cs +++ b/src/Ombi.Core/Engine/TvSearchEngine.cs @@ -59,11 +59,6 @@ namespace Ombi.Core.Engine return null; } - public async Task>> SearchTreeNode(string searchTerm) - { - var result = await Search(searchTerm); - return result.Select(ParseIntoTreeNode).ToList(); - } public async Task GetShowInformation(int tvdbid) { var show = await TvMazeApi.ShowLookupByTheTvDbId(tvdbid); @@ -116,19 +111,6 @@ namespace Ombi.Core.Engine return await ProcessResult(mapped); } - public async Task> GetShowInformationTreeNode(int tvdbid) - { - var result = await GetShowInformation(tvdbid); - return ParseIntoTreeNode(result); - } - - public async Task>> PopularTree() - { - var result = await Cache.GetOrAdd(CacheKeys.PopularTv, async () => await TraktApi.GetPopularShows(), DateTime.Now.AddHours(12)); - var processed = await ProcessResults(result); - return processed.Select(ParseIntoTreeNode).ToList(); - } - public async Task> Popular() { var result = await Cache.GetOrAdd(CacheKeys.PopularTv, async () => await TraktApi.GetPopularShows(), DateTime.Now.AddHours(12)); @@ -136,12 +118,6 @@ namespace Ombi.Core.Engine return processed; } - public async Task>> AnticipatedTree() - { - var result = await Cache.GetOrAdd(CacheKeys.AnticipatedTv, async () => await TraktApi.GetAnticipatedShows(), DateTime.Now.AddHours(12)); - var processed = await ProcessResults(result); - return processed.Select(ParseIntoTreeNode).ToList(); - } public async Task> Anticipated() { @@ -150,12 +126,6 @@ namespace Ombi.Core.Engine return processed; } - public async Task>> MostWatchesTree() - { - var result = await Cache.GetOrAdd(CacheKeys.MostWatchesTv, async () => await TraktApi.GetMostWatchesShows(), DateTime.Now.AddHours(12)); - var processed = await ProcessResults(result); - return processed.Select(ParseIntoTreeNode).ToList(); - } public async Task> MostWatches() { var result = await Cache.GetOrAdd(CacheKeys.MostWatchesTv, async () => await TraktApi.GetMostWatchesShows(), DateTime.Now.AddHours(12)); @@ -163,13 +133,6 @@ namespace Ombi.Core.Engine return processed; } - public async Task>> TrendingTree() - { - var result = await Cache.GetOrAdd(CacheKeys.TrendingTv, async () => await TraktApi.GetTrendingShows(), DateTime.Now.AddHours(12)); - var processed = await ProcessResults(result); - return processed.Select(ParseIntoTreeNode).ToList(); - } - public async Task> Trending() { var result = await Cache.GetOrAdd(CacheKeys.TrendingTv, async () => await TraktApi.GetTrendingShows(), DateTime.Now.AddHours(12)); @@ -177,22 +140,6 @@ namespace Ombi.Core.Engine return processed; } - private static TreeNode ParseIntoTreeNode(SearchTvShowViewModel result) - { - return new TreeNode - { - Data = result, - Children = new List> - { - new TreeNode - { - Data = result, Leaf = true - } - }, - Leaf = false - }; - } - private async Task> ProcessResults(IEnumerable items) { var retVal = new List(); diff --git a/src/Ombi/Controllers/RequestController.cs b/src/Ombi/Controllers/RequestController.cs index baeaefcd5..6f2187061 100644 --- a/src/Ombi/Controllers/RequestController.cs +++ b/src/Ombi/Controllers/RequestController.cs @@ -153,18 +153,6 @@ namespace Ombi.Controllers return await MovieRequestEngine.DenyMovieById(model.Id); } - /// - /// Gets the tv requests. - /// - /// The count of items you want to return. - /// The position. - /// - [HttpGet("tv/{count:int}/{position:int}/tree")] - public async Task>>> GetTvRequestsTree(int count, int position) - { - return await TvRequestEngine.GetRequestsTreeNode(count, position); - } - /// /// Gets the total amount of TV requests. /// @@ -267,17 +255,6 @@ namespace Ombi.Controllers return await TvRequestEngine.SearchTvRequest(searchTerm); } - /// - /// Searches for a specific tv request - /// - /// The search term. - /// - [HttpGet("tv/search/{searchTerm}/tree")] - public async Task>>> SearchTvTree(string searchTerm) - { - return await TvRequestEngine.SearchTvRequestTree(searchTerm); - } - /// /// Deletes the a specific tv request /// diff --git a/src/Ombi/Controllers/SearchController.cs b/src/Ombi/Controllers/SearchController.cs index 7060a973e..fe5399d78 100644 --- a/src/Ombi/Controllers/SearchController.cs +++ b/src/Ombi/Controllers/SearchController.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; @@ -127,31 +126,6 @@ namespace Ombi.Controllers return await TvEngine.Search(searchTerm); } - /// - /// Searches for a Tv Show. - /// - /// The search term. - /// We use TvMaze as the Provider - /// - [HttpGet("tv/{searchTerm}/tree")] - public async Task>> SearchTvTreeNode(string searchTerm) - { - return await TvEngine.SearchTreeNode(searchTerm); - } - - /// - /// Gets extra show information. - /// - /// The TVDB identifier. - /// We use TvMaze as the Provider - /// - [HttpGet("tv/info/{tvdbId}/tree")] - public async Task> GetShowInfoTreeNode(int tvdbId) - { - if (tvdbId == 0) return new TreeNode(); - return await TvEngine.GetShowInformationTreeNode(tvdbId); - } - /// /// Gets extra show information. /// @@ -164,17 +138,6 @@ namespace Ombi.Controllers return await TvEngine.GetShowInformation(tvdbId); } - /// - /// Returns Popular Tv Shows - /// - /// We use Trakt.tv as the Provider - /// - [HttpGet("tv/popular/tree")] - public async Task>> PopularTvTree() - { - return await TvEngine.PopularTree(); - } - /// /// Returns Popular Tv Shows /// @@ -186,18 +149,6 @@ namespace Ombi.Controllers return await TvEngine.Popular(); } - /// - /// Returns most Anticiplateds tv shows. - /// - /// We use Trakt.tv as the Provider - /// - [HttpGet("tv/anticipated/tree")] - public async Task>> AnticipatedTvTree() - { - return await TvEngine.AnticipatedTree(); - } - - /// /// Returns most Anticiplateds tv shows. /// @@ -209,16 +160,6 @@ namespace Ombi.Controllers return await TvEngine.Anticipated(); } - /// - /// Returns Most watched shows. - /// - /// We use Trakt.tv as the Provider - /// - [HttpGet("tv/mostwatched/tree")] - public async Task>> MostWatchedTree() - { - return await TvEngine.MostWatchesTree(); - } /// /// Returns Most watched shows. @@ -231,17 +172,6 @@ namespace Ombi.Controllers return await TvEngine.MostWatches(); } - /// - /// Returns trending shows - /// - /// We use Trakt.tv as the Provider - /// - [HttpGet("tv/trending/tree")] - public async Task>> TrendingTree() - { - return await TvEngine.TrendingTree(); - } - /// /// Returns trending shows ///