Added a smaller and simplier way of getting TV Request info

pull/2351/head
Jamie Rees 7 years ago
parent 7e7376bbe5
commit a7ccb74ad9

@ -10,6 +10,7 @@ namespace Ombi.Core.Engine.Interfaces
{ {
Task RemoveTvRequest(int requestId); Task RemoveTvRequest(int requestId);
Task<TvRequests> GetTvRequest(int requestId);
Task<RequestEngineResult> RequestTvShow(TvRequestViewModel tv); Task<RequestEngineResult> RequestTvShow(TvRequestViewModel tv);
Task<RequestEngineResult> DenyChildRequest(int requestId); Task<RequestEngineResult> DenyChildRequest(int requestId);
Task<IEnumerable<TvRequests>> SearchTvRequest(string search); Task<IEnumerable<TvRequests>> SearchTvRequest(string search);
@ -20,5 +21,6 @@ namespace Ombi.Core.Engine.Interfaces
Task<ChildRequests> UpdateChildRequest(ChildRequests request); Task<ChildRequests> UpdateChildRequest(ChildRequests request);
Task RemoveTvChild(int requestId); Task RemoveTvChild(int requestId);
Task<RequestEngineResult> ApproveChildRequest(int id); Task<RequestEngineResult> ApproveChildRequest(int id);
Task<IEnumerable<TvRequests>> GetRequestsLite();
} }
} }

@ -218,11 +218,61 @@ namespace Ombi.Core.Engine
return allRequests; return allRequests;
} }
public async Task<IEnumerable<TvRequests>> GetRequestsLite()
{
var shouldHide = await HideFromOtherUsers();
List<TvRequests> allRequests;
if (shouldHide.Hide)
{
allRequests = await TvRepository.GetLite(shouldHide.UserId).ToListAsync();
FilterChildren(allRequests, shouldHide);
}
else
{
allRequests = await TvRepository.GetLite().ToListAsync();
}
allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
return allRequests;
}
public async Task<TvRequests> GetTvRequest(int requestId)
{
var shouldHide = await HideFromOtherUsers();
TvRequests request;
if (shouldHide.Hide)
{
request = await TvRepository.Get(shouldHide.UserId).Where(x => x.Id == requestId).FirstOrDefaultAsync();
FilterChildren(request, shouldHide);
}
else
{
request = await TvRepository.Get().Where(x => x.Id == requestId).FirstOrDefaultAsync();
}
await CheckForSubscription(shouldHide, request);
return request;
}
private static void FilterChildren(IEnumerable<TvRequests> allRequests, HideResult shouldHide) private static void FilterChildren(IEnumerable<TvRequests> allRequests, HideResult shouldHide)
{ {
// Filter out children // Filter out children
foreach (var t in allRequests) foreach (var t in allRequests)
{ {
for (var j = 0; j < t.ChildRequests.Count; j++)
{
FilterChildren(t, shouldHide);
}
}
}
private static void FilterChildren(TvRequests t, HideResult shouldHide)
{
// Filter out children
for (var j = 0; j < t.ChildRequests.Count; j++) for (var j = 0; j < t.ChildRequests.Count; j++)
{ {
var child = t.ChildRequests[j]; var child = t.ChildRequests[j];
@ -232,7 +282,7 @@ namespace Ombi.Core.Engine
j--; j--;
} }
} }
}
} }
public async Task<IEnumerable<ChildRequests>> GetAllChldren(int tvId) public async Task<IEnumerable<ChildRequests>> GetAllChldren(int tvId)

@ -26,7 +26,7 @@ namespace Ombi.Schedule.Tests
_tv = new Mock<ITvRequestRepository>(); _tv = new Mock<ITvRequestRepository>();
_movie = new Mock<IMovieRequestRepository>(); _movie = new Mock<IMovieRequestRepository>();
_notify = new Mock<INotificationService>(); _notify = new Mock<INotificationService>();
Checker = new PlexAvailabilityChecker(_repo.Object, _tv.Object, _movie.Object, _notify.Object, new Mock<IBackgroundJobClient>().Object); Checker = new PlexAvailabilityChecker(_repo.Object, _tv.Object, _movie.Object, _notify.Object, new Mock<IBackgroundJobClient>().Object, null);
} }

@ -14,7 +14,9 @@ namespace Ombi.Store.Repository.Requests
Task Delete(TvRequests request); Task Delete(TvRequests request);
Task DeleteChild(ChildRequests request); Task DeleteChild(ChildRequests request);
IQueryable<TvRequests> Get(); IQueryable<TvRequests> Get();
IQueryable<TvRequests> GetLite();
IQueryable<TvRequests> Get(string userId); IQueryable<TvRequests> Get(string userId);
IQueryable<TvRequests> GetLite(string userId);
Task<TvRequests> GetRequestAsync(int tvDbId); Task<TvRequests> GetRequestAsync(int tvDbId);
TvRequests GetRequest(int tvDbId); TvRequests GetRequest(int tvDbId);
Task Update(TvRequests request); Task Update(TvRequests request);

@ -60,6 +60,24 @@ namespace Ombi.Store.Repository.Requests
.Where(x => x.ChildRequests.Any(a => a.RequestedUserId == userId)) .Where(x => x.ChildRequests.Any(a => a.RequestedUserId == userId))
.AsQueryable(); .AsQueryable();
} }
public IQueryable<TvRequests> GetLite(string userId)
{
return Db.TvRequests
.Include(x => x.ChildRequests)
.ThenInclude(x => x.RequestedUser)
.Where(x => x.ChildRequests.Any(a => a.RequestedUserId == userId))
.AsQueryable();
}
public IQueryable<TvRequests> GetLite()
{
return Db.TvRequests
.Include(x => x.ChildRequests)
.ThenInclude(x => x.RequestedUser)
.AsQueryable();
}
public IQueryable<ChildRequests> GetChild() public IQueryable<ChildRequests> GetChild()
{ {
return Db.ChildRequests return Db.ChildRequests

@ -204,6 +204,27 @@ namespace Ombi.Controllers
return await TvRequestEngine.GetRequests(); return await TvRequestEngine.GetRequests();
} }
/// <summary>
/// Gets the tv requests without the whole object graph (Does not include seasons/episodes).
/// </summary>
/// <returns></returns>
[HttpGet("tvlite")]
public async Task<IEnumerable<TvRequests>> GetTvRequestsLite()
{
return await TvRequestEngine.GetRequestsLite();
}
/// <summary>
/// Returns the full request object for the specified requestId
/// </summary>
/// <param name="requestId"></param>
/// <returns></returns>
[HttpGet("tv/{requestId:int}")]
public async Task<TvRequests> GetTvRequest(int requestId)
{
return await TvRequestEngine.GetTvRequest(requestId);
}
/// <summary> /// <summary>
/// Requests a tv show/episode/season. /// Requests a tv show/episode/season.
/// </summary> /// </summary>

@ -10,7 +10,6 @@
}, },
"ApplicationSettings": { "ApplicationSettings": {
"Verison": "{{VERSIONNUMBER}}", "Verison": "{{VERSIONNUMBER}}",
"OmbiService": "https://ombiservice.azurewebsites.net/",
"Branch": "{{BRANCH}}", "Branch": "{{BRANCH}}",
"FriendlyVersion": "v3.0.0" "FriendlyVersion": "v3.0.0"
}, },

Loading…
Cancel
Save