From 3f7eb804709e7447a05a5e26b0a81de148190358 Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 28 Sep 2018 21:00:05 +0100 Subject: [PATCH] !wip done api --- src/Ombi.Core/Engine/IVoteEngine.cs | 5 +- src/Ombi.Core/Engine/VoteEngine.cs | 54 ++++++++++++++++++++ src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs | 4 +- src/Ombi/Controllers/VoteController.cs | 7 +++ 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/Ombi.Core/Engine/IVoteEngine.cs b/src/Ombi.Core/Engine/IVoteEngine.cs index 45b0761a4..681f333c5 100644 --- a/src/Ombi.Core/Engine/IVoteEngine.cs +++ b/src/Ombi.Core/Engine/IVoteEngine.cs @@ -1,6 +1,8 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Ombi.Core.Models; +using Ombi.Core.Models.UI; using Ombi.Store.Entities; namespace Ombi.Core.Engine @@ -12,5 +14,6 @@ namespace Ombi.Core.Engine IQueryable GetVotes(int requestId, RequestType requestType); Task RemoveCurrentVote(Votes currentVote); Task UpVote(int requestId, RequestType requestType); + Task> GetMovieViewModel(); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/VoteEngine.cs b/src/Ombi.Core/Engine/VoteEngine.cs index ecd22e848..3875b6705 100644 --- a/src/Ombi.Core/Engine/VoteEngine.cs +++ b/src/Ombi.Core/Engine/VoteEngine.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Principal; +using System.Text; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Ombi.Core.Authentication; @@ -10,6 +11,7 @@ using Ombi.Core.Models; using Ombi.Core.Models.UI; using Ombi.Core.Rule.Interfaces; using Ombi.Core.Settings; +using Ombi.Schedule.Jobs.Ombi; using Ombi.Settings.Settings.Models; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -38,6 +40,8 @@ namespace Ombi.Core.Engine { var vm = new List(); var movieRequests = await _movieRequestEngine.GetRequests(); + var tvRequestsTask = _tvRequestEngine.GetRequestsLite(); + var musicRequestsTask = _musicRequestEngine.GetRequests(); foreach (var r in movieRequests) { // Make model @@ -57,6 +61,56 @@ namespace Ombi.Core.Engine }); } + foreach (var r in await musicRequestsTask) + { + // Make model + var votes = GetVotes(r.Id, RequestType.Movie); + var upVotes = await votes.Where(x => x.VoteType == VoteType.Upvote).CountAsync(); + var downVotes = await votes.Where(x => x.VoteType == VoteType.Downvote).CountAsync(); + vm.Add(new VoteViewModel + { + Upvotes = upVotes, + Downvotes = downVotes, + RequestId = r.Id, + RequestType = RequestType.Movie, + Title = r.Title, + Image = r.Disk, + Background = r.Cover, + Description = r.ArtistName + }); + } + + foreach (var r in await tvRequestsTask) + { + // Make model + var votes = GetVotes(r.Id, RequestType.Movie); + var upVotes = await votes.Where(x => x.VoteType == VoteType.Upvote).CountAsync(); + var downVotes = await votes.Where(x => x.VoteType == VoteType.Downvote).CountAsync(); + + var finalsb = new StringBuilder(); + foreach (var childRequests in r.ChildRequests) + { + foreach (var epInformation in childRequests.SeasonRequests.OrderBy(x => x.SeasonNumber)) + { + var orderedEpisodes = epInformation.Episodes.OrderBy(x => x.EpisodeNumber).ToList(); + var episodeString = NewsletterJob.BuildEpisodeList(orderedEpisodes.Select(x => x.EpisodeNumber)); + finalsb.Append($"Season: {epInformation.SeasonNumber} - Episodes: {episodeString}"); + finalsb.Append("
"); + } + } + vm.Add(new VoteViewModel + { + Upvotes = upVotes, + Downvotes = downVotes, + RequestId = r.Id, + RequestType = RequestType.Movie, + Title = r.Title, + Image = r.PosterPath, + Background = r.Background, + Description = finalsb.ToString() + }); + } + return vm; } diff --git a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs index f152f6b4b..9f5e58482 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs @@ -654,7 +654,7 @@ namespace Ombi.Schedule.Jobs.Ombi AddInfoTable(sb); var title = ""; - if (!String.IsNullOrEmpty(info.premiered) && info.premiered.Length > 4) + if (!string.IsNullOrEmpty(info.premiered) && info.premiered.Length > 4) { title = $"{t.Title} ({info.premiered.Remove(4)})"; } else @@ -715,7 +715,7 @@ namespace Ombi.Schedule.Jobs.Ombi } } - public string BuildEpisodeList(IEnumerable orderedEpisodes) + public static string BuildEpisodeList(IEnumerable orderedEpisodes) { var epSb = new StringBuilder(); var previousEpisodes = new List(); diff --git a/src/Ombi/Controllers/VoteController.cs b/src/Ombi/Controllers/VoteController.cs index 5039626be..f1466e3ed 100644 --- a/src/Ombi/Controllers/VoteController.cs +++ b/src/Ombi/Controllers/VoteController.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Ombi.Core.Engine; +using Ombi.Core.Models.UI; using Ombi.Store.Entities; namespace Ombi.Controllers @@ -20,6 +21,12 @@ namespace Ombi.Controllers private readonly IVoteEngine _engine; + [HttpGet] + public Task> GetView() + { + return _engine.GetMovieViewModel(); + } + /// /// Get's all the votes for the request id ///