Merge branch 'develop' into feature/tvmaze-replacement

This commit is contained in:
tidusjar 2021-03-12 23:40:25 +00:00
commit 8368877c74
135 changed files with 10704 additions and 320 deletions

View file

@ -0,0 +1,81 @@
using Microsoft.EntityFrameworkCore;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Ombi.Core.Engine.V2
{
public interface IIssuesEngine
{
Task<IEnumerable<IssuesSummaryModel>> GetIssues(int position, int take, IssueStatus status, CancellationToken token);
Task<IssuesSummaryModel> GetIssuesByProviderId(string providerId, CancellationToken token);
}
public class IssuesEngine : IIssuesEngine
{
private readonly IRepository<IssueCategory> _categories;
private readonly IRepository<Issues> _issues;
private readonly IRepository<IssueComments> _comments;
public IssuesEngine(IRepository<IssueCategory> categories,
IRepository<Issues> issues,
IRepository<IssueComments> comments)
{
_categories = categories;
_issues = issues;
_comments = comments;
}
public async Task<IEnumerable<IssuesSummaryModel>> GetIssues(int position, int take, IssueStatus status, CancellationToken token)
{
var issues = await _issues.GetAll().Where(x => x.Status == status && x.ProviderId != null).Skip(position).Take(take).OrderBy(x => x.Title).ToListAsync(token);
var grouped = issues.GroupBy(x => x.Title, (key, g) => new { Title = key, Issues = g });
var model = new List<IssuesSummaryModel>();
foreach(var group in grouped)
{
model.Add(new IssuesSummaryModel
{
Count = group.Issues.Count(),
Title = group.Title,
ProviderId = group.Issues.FirstOrDefault()?.ProviderId
});
}
return model;
}
public async Task<IssuesSummaryModel> GetIssuesByProviderId(string providerId, CancellationToken token)
{
var issues = await _issues.GetAll().Include(x => x.Comments).ThenInclude(x => x.User).Include(x => x.UserReported).Include(x => x.IssueCategory).Where(x => x.ProviderId == providerId).ToListAsync(token);
var grouped = issues.GroupBy(x => x.Title, (key, g) => new { Title = key, Issues = g }).FirstOrDefault();
if (grouped == null)
{
return null;
}
return new IssuesSummaryModel
{
Count = grouped.Issues.Count(),
Title = grouped.Title,
ProviderId = grouped.Issues.FirstOrDefault()?.ProviderId,
Issues = grouped.Issues
};
}
}
public class IssuesSummaryModel
{
public string Title { get; set; }
public int Count { get; set; }
public string ProviderId { get; set; }
public IEnumerable<Issues> Issues { get; set; }
}
}

View file

@ -63,7 +63,8 @@ namespace Ombi.Core.Engine.V2
var result = new MultiSearchResult
{
MediaType = multiSearch.media_type,
Poster = multiSearch.poster_path
Poster = multiSearch.poster_path,
Overview = multiSearch.overview
};
if (multiSearch.media_type.Equals("movie", StringComparison.InvariantCultureIgnoreCase) && filter.Movies)

View file

@ -6,5 +6,6 @@
public string MediaType { get; set; }
public string Title { get; set; }
public string Poster { get; set; }
public string Overview { get; set; }
}
}

View file

@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Core.Models.Search;
using Ombi.Helpers;
using Ombi.Store.Context;
using Ombi.Store.Entities;
using Ombi.Store.Entities.Requests;
@ -53,8 +54,13 @@ namespace Ombi.Core.Rule.Rules
if (obj.Type == RequestType.TvShow)
{
var vm = (SearchTvShowViewModel) obj;
// Check if it's in Radarr
var result = await _ctx.SonarrCache.FirstOrDefaultAsync(x => x.TvDbId.ToString() == vm.TheTvDbId);
// Check if it's in Sonarr
if (!vm.TheTvDbId.HasValue())
{
return new RuleResult { Success = true };
}
var tvdbidint = int.Parse(vm.TheTvDbId);
var result = await _ctx.SonarrCache.FirstOrDefaultAsync(x => x.TvDbId == tvdbidint);
if (result != null)
{
vm.Approved = true;
@ -69,7 +75,7 @@ namespace Ombi.Core.Rule.Rules
// Check if we have it
var monitoredInSonarr = await sonarrEpisodes.FirstOrDefaultAsync(x =>
x.EpisodeNumber == ep.EpisodeNumber && x.SeasonNumber == season.SeasonNumber
&& x.TvDbId.ToString() == vm.TheTvDbId);
&& x.TvDbId == tvdbidint);
if (monitoredInSonarr != null)
{
ep.Approved = true;