mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 15:56:05 -07:00
Fixed a load of bugs need to figure out what is wrong with tv requests #865
This commit is contained in:
parent
2bc916998c
commit
386f856ea7
7 changed files with 66 additions and 32 deletions
|
@ -81,6 +81,7 @@ namespace Ombi.Core.Engine
|
|||
RequestedDate = DateTime.UtcNow,
|
||||
Approved = false,
|
||||
RequestedUserId = user.Id,
|
||||
SeasonRequests = new List<SeasonRequests>()
|
||||
};
|
||||
|
||||
if (tv.LatestSeason)
|
||||
|
@ -112,13 +113,16 @@ namespace Ombi.Core.Engine
|
|||
var episodesRequests = new List<EpisodeRequests>();
|
||||
foreach (var ep in episodes)
|
||||
{
|
||||
episodesRequests.Add(new EpisodeRequests
|
||||
if (ep.season == first.season)
|
||||
{
|
||||
EpisodeNumber = ep.number,
|
||||
AirDate = DateTime.Parse(ep.airdate),
|
||||
Title = ep.name,
|
||||
Url = ep.url
|
||||
});
|
||||
episodesRequests.Add(new EpisodeRequests
|
||||
{
|
||||
EpisodeNumber = ep.number,
|
||||
AirDate = DateTime.Parse(ep.airdate),
|
||||
Title = ep.name,
|
||||
Url = ep.url
|
||||
});
|
||||
}
|
||||
}
|
||||
childRequest.SeasonRequests.Add(new SeasonRequests
|
||||
{
|
||||
|
|
|
@ -77,15 +77,16 @@ namespace Ombi.Core.Engine
|
|||
});
|
||||
mapped.SeasonRequests.Add(newSeason);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Find the episode
|
||||
var ep = season.Episodes.FirstOrDefault(x => x.EpisodeNumber == e.number);
|
||||
ep.Url = e.url;
|
||||
ep.Title = e.name;
|
||||
ep.AirDate = DateTime.Parse(e.airstamp);
|
||||
ep.EpisodeNumber = e.number;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// // Find the episode
|
||||
// var ep = episodes.FirstOrDefault(x => x.number == e.number);
|
||||
|
||||
// ep.Url = e.url;
|
||||
// ep.Title = e.name;
|
||||
// ep.AirDate = DateTime.Parse(e.airstamp);
|
||||
// ep.EpisodeNumber = e.number;
|
||||
//}
|
||||
}
|
||||
|
||||
var existingRequests = await GetTvRequests();
|
||||
|
@ -180,6 +181,10 @@ namespace Ombi.Core.Engine
|
|||
{
|
||||
// Find the episode from what we are searching
|
||||
var episodeSearching = season.Episodes.FirstOrDefault(x => x.EpisodeNumber == ep.EpisodeNumber);
|
||||
if(episodeSearching == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
episodeSearching.Requested = true;
|
||||
episodeSearching.Available = ep.Available;
|
||||
episodeSearching.Approved = ep.Season.ChildRequest.Approved;
|
||||
|
|
|
@ -7,24 +7,26 @@ using Ombi.Core.Models.Requests.Tv;
|
|||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Requests.Models;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Store.Repository;
|
||||
using Ombi.Store.Repository.Requests;
|
||||
|
||||
namespace Ombi.Core.Rule.Rules.Search
|
||||
{
|
||||
public class ExistingRequestRule : BaseSearchRule, IRequestRules<SearchViewModel>
|
||||
{
|
||||
public ExistingRequestRule(IRequestService<MovieRequestModel> movie, IRequestService<TvRequestModel> tv)
|
||||
public ExistingRequestRule(IMovieRequestRepository movie, ITvRequestRepository tv)
|
||||
{
|
||||
Movie = movie;
|
||||
Tv = tv;
|
||||
}
|
||||
|
||||
private IRequestService<MovieRequestModel> Movie { get; }
|
||||
private IRequestService<TvRequestModel> Tv { get; }
|
||||
private IMovieRequestRepository Movie { get; }
|
||||
private ITvRequestRepository Tv { get; }
|
||||
|
||||
public async Task<RuleResult> Execute(SearchViewModel obj)
|
||||
{
|
||||
var movieRequests = await Movie.GetAllAsync();
|
||||
var existing = movieRequests.FirstOrDefault(x => x.ProviderId == obj.Id);
|
||||
var movieRequests = Movie.Get();
|
||||
var existing = await movieRequests.FirstOrDefaultAsync(x => x.TheMovieDbId == obj.Id);
|
||||
if (existing != null) // Do we already have a request for this?
|
||||
{
|
||||
|
||||
|
@ -35,14 +37,14 @@ namespace Ombi.Core.Rule.Rules.Search
|
|||
return Success();
|
||||
}
|
||||
|
||||
var tvRequests = await Tv.GetAllAsync();
|
||||
var tv = tvRequests.FirstOrDefault(x => x.ProviderId == obj.Id);
|
||||
var tvRequests = Tv.Get();
|
||||
var tv = await tvRequests.FirstOrDefaultAsync(x => x.TvDbId == obj.Id);
|
||||
if (tv != null) // Do we already have a request for this?
|
||||
{
|
||||
|
||||
obj.Requested = true;
|
||||
obj.Approved = tv.Approved;
|
||||
obj.Available = tv.Available;
|
||||
obj.Approved = tv.ChildRequests.Any(x => x.Approved);
|
||||
obj.Available = tv.ChildRequests.Any(x => x.Available);
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
|
|
@ -18,27 +18,30 @@ namespace Ombi.Store.Repository.Requests
|
|||
public async Task<TvRequests> GetRequest(int tvDbId)
|
||||
{
|
||||
return await Db.TvRequests.Where(x => x.TvDbId == tvDbId)
|
||||
.Include(x => x.ChildRequests)
|
||||
.ThenInclude(x => x.Issues)
|
||||
.Include(x => x.ChildRequests)
|
||||
.ThenInclude(x => x.RequestedUser)
|
||||
.Include(x => x.ChildRequests)
|
||||
.ThenInclude(x => x.SeasonRequests)
|
||||
.ThenInclude(x => x.Episodes)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public IQueryable<TvRequests> Get()
|
||||
{
|
||||
return Db.TvRequests
|
||||
.Include(x => x.ChildRequests)
|
||||
.ThenInclude(x => x.Issues)
|
||||
.Include(x => x.ChildRequests)
|
||||
.ThenInclude(x => x.RequestedUser)
|
||||
.Include(x => x.ChildRequests)
|
||||
.ThenInclude(x => x.SeasonRequests)
|
||||
.ThenInclude(x => x.Episodes)
|
||||
.AsQueryable();
|
||||
}
|
||||
public IQueryable<ChildRequests> GetChild()
|
||||
{
|
||||
return Db.ChildRequests
|
||||
.Include(x => x.Issues)
|
||||
.Include(x => x.RequestedUser)
|
||||
.Include(x => x.SeasonRequests)
|
||||
.ThenInclude(x => x.Episodes)
|
||||
.AsQueryable();
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,16 @@ namespace Ombi.Auth
|
|||
// If the request path doesn't match, skip
|
||||
if (!context.Request.Path.Equals(_options.Path, StringComparison.Ordinal))
|
||||
{
|
||||
return _next(context);
|
||||
try
|
||||
{
|
||||
|
||||
return _next(context);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// Request must be POST with Content-Type: application/json
|
||||
|
|
|
@ -40,7 +40,8 @@ export class RequestService extends ServiceAuthHelpers {
|
|||
}
|
||||
|
||||
getTvRequests(count: number, position: number): Observable<ITvRequests[]> {
|
||||
return this.http.get(`${this.url}tv/${count}/${position}`).map(this.extractData);
|
||||
return this.http.get(`${this.url}tv/${count}/${position}`).map(this.extractData)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
searchTvRequests(search: string): Observable<ITvRequests[]> {
|
||||
|
|
|
@ -7,6 +7,7 @@ using Ombi.Core.Models.Search;
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Ombi.Controllers
|
||||
{
|
||||
|
@ -95,7 +96,16 @@ namespace Ombi.Controllers
|
|||
[HttpGet("tv/{count:int}/{position:int}")]
|
||||
public async Task<IEnumerable<TvRequests>> GetTvRequests(int count, int position)
|
||||
{
|
||||
return await TvRequestEngine.GetRequests(count, position);
|
||||
try
|
||||
{
|
||||
|
||||
return await TvRequestEngine.GetRequests(count, position);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.WriteLine(e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue