mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
!wip done api
This commit is contained in:
parent
cfd0625df4
commit
3f7eb80470
4 changed files with 67 additions and 3 deletions
|
@ -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<Votes> GetVotes(int requestId, RequestType requestType);
|
||||
Task RemoveCurrentVote(Votes currentVote);
|
||||
Task<VoteEngineResult> UpVote(int requestId, RequestType requestType);
|
||||
Task<List<VoteViewModel>> GetMovieViewModel();
|
||||
}
|
||||
}
|
|
@ -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<VoteViewModel>();
|
||||
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("<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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<int> orderedEpisodes)
|
||||
public static string BuildEpisodeList(IEnumerable<int> orderedEpisodes)
|
||||
{
|
||||
var epSb = new StringBuilder();
|
||||
var previousEpisodes = new List<int>();
|
||||
|
|
|
@ -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<List<VoteViewModel>> GetView()
|
||||
{
|
||||
return _engine.GetMovieViewModel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get's all the votes for the request id
|
||||
/// </summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue