!wip done api

pull/2556/head
Jamie 6 years ago
parent cfd0625df4
commit 3f7eb80470

@ -1,6 +1,8 @@
using System.Linq; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Ombi.Core.Models; using Ombi.Core.Models;
using Ombi.Core.Models.UI;
using Ombi.Store.Entities; using Ombi.Store.Entities;
namespace Ombi.Core.Engine namespace Ombi.Core.Engine
@ -12,5 +14,6 @@ namespace Ombi.Core.Engine
IQueryable<Votes> GetVotes(int requestId, RequestType requestType); IQueryable<Votes> GetVotes(int requestId, RequestType requestType);
Task RemoveCurrentVote(Votes currentVote); Task RemoveCurrentVote(Votes currentVote);
Task<VoteEngineResult> UpVote(int requestId, RequestType requestType); Task<VoteEngineResult> UpVote(int requestId, RequestType requestType);
Task<List<VoteViewModel>> GetMovieViewModel();
} }
} }

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Principal; using System.Security.Principal;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Ombi.Core.Authentication; using Ombi.Core.Authentication;
@ -10,6 +11,7 @@ using Ombi.Core.Models;
using Ombi.Core.Models.UI; using Ombi.Core.Models.UI;
using Ombi.Core.Rule.Interfaces; using Ombi.Core.Rule.Interfaces;
using Ombi.Core.Settings; using Ombi.Core.Settings;
using Ombi.Schedule.Jobs.Ombi;
using Ombi.Settings.Settings.Models; using Ombi.Settings.Settings.Models;
using Ombi.Store.Entities; using Ombi.Store.Entities;
using Ombi.Store.Repository; using Ombi.Store.Repository;
@ -38,6 +40,8 @@ namespace Ombi.Core.Engine
{ {
var vm = new List<VoteViewModel>(); var vm = new List<VoteViewModel>();
var movieRequests = await _movieRequestEngine.GetRequests(); var movieRequests = await _movieRequestEngine.GetRequests();
var tvRequestsTask = _tvRequestEngine.GetRequestsLite();
var musicRequestsTask = _musicRequestEngine.GetRequests();
foreach (var r in movieRequests) foreach (var r in movieRequests)
{ {
// Make model // 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("<br />");
}
}
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; return vm;
} }

@ -654,7 +654,7 @@ namespace Ombi.Schedule.Jobs.Ombi
AddInfoTable(sb); AddInfoTable(sb);
var title = ""; 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)})"; title = $"{t.Title} ({info.premiered.Remove(4)})";
} else } else
@ -715,7 +715,7 @@ namespace Ombi.Schedule.Jobs.Ombi
} }
} }
public string BuildEpisodeList(IEnumerable<int> orderedEpisodes) public static string BuildEpisodeList(IEnumerable<int> orderedEpisodes)
{ {
var epSb = new StringBuilder(); var epSb = new StringBuilder();
var previousEpisodes = new List<int>(); var previousEpisodes = new List<int>();

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Ombi.Core.Engine; using Ombi.Core.Engine;
using Ombi.Core.Models.UI;
using Ombi.Store.Entities; using Ombi.Store.Entities;
namespace Ombi.Controllers namespace Ombi.Controllers
@ -20,6 +21,12 @@ namespace Ombi.Controllers
private readonly IVoteEngine _engine; private readonly IVoteEngine _engine;
[HttpGet]
public Task<List<VoteViewModel>> GetView()
{
return _engine.GetMovieViewModel();
}
/// <summary> /// <summary>
/// Get's all the votes for the request id /// Get's all the votes for the request id
/// </summary> /// </summary>

Loading…
Cancel
Save