#2932 - Added an api for unavailable requests

pull/3895/head
tidusjar 6 years ago
parent cb12160a97
commit 572746351b

@ -20,6 +20,9 @@ namespace Ombi.Core.Engine.Interfaces
Task<RequestEngineResult> ApproveMovieById(int requestId);
Task<RequestEngineResult> DenyMovieById(int modelId, string denyReason);
Task<RequestsViewModel<MovieRequests>> GetRequests(int count, int position, string sortProperty, string sortOrder);
Task<RequestsViewModel<MovieRequests>> GetUnavailableRequests(int count, int position, string sortProperty,
string sortOrder);
Task<RequestEngineResult> UpdateAdvancedOptions(MovieAdvancedOptions options);
}
}

@ -209,13 +209,13 @@ namespace Ombi.Core.Engine
{
allRequests =
MovieRepository.GetWithUser(shouldHide
.UserId);
.UserId);
}
else
{
allRequests =
MovieRepository
.GetWithUser();
.GetWithUser();
}
var prop = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find(sortProperty, true);
@ -230,8 +230,8 @@ namespace Ombi.Core.Engine
//var secondProp = TypeDescriptor.GetProperties(propType).Find(properties[1], true);
}
allRequests = sortOrder.Equals("asc", StringComparison.InvariantCultureIgnoreCase)
? allRequests.OrderBy(x => prop.GetValue(x))
allRequests = sortOrder.Equals("asc", StringComparison.InvariantCultureIgnoreCase)
? allRequests.OrderBy(x => prop.GetValue(x))
: allRequests.OrderByDescending(x => prop.GetValue(x));
var total = await allRequests.CountAsync();
var requests = await allRequests.Skip(position).Take(count)
@ -246,9 +246,55 @@ namespace Ombi.Core.Engine
Collection = requests,
Total = total
};
}
public async Task<RequestsViewModel<MovieRequests>> GetUnavailableRequests(int count, int position, string sortProperty, string sortOrder)
{
var shouldHide = await HideFromOtherUsers();
IQueryable<MovieRequests> allRequests;
if (shouldHide.Hide)
{
allRequests =
MovieRepository.GetWithUser(shouldHide
.UserId).Where(x => !x.Available);
}
else
{
allRequests =
MovieRepository
.GetWithUser().Where(x => !x.Available);
}
var prop = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find(sortProperty, true);
if (sortProperty.Contains('.'))
{
// This is a navigation property currently not supported
prop = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find("RequestedDate", true);
//var properties = sortProperty.Split(new []{'.'}, StringSplitOptions.RemoveEmptyEntries);
//var firstProp = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find(properties[0], true);
//var propType = firstProp.PropertyType;
//var secondProp = TypeDescriptor.GetProperties(propType).Find(properties[1], true);
}
allRequests = sortOrder.Equals("asc", StringComparison.InvariantCultureIgnoreCase)
? allRequests.OrderBy(x => prop.GetValue(x))
: allRequests.OrderByDescending(x => prop.GetValue(x));
var total = await allRequests.CountAsync();
var requests = await allRequests.Skip(position).Take(count)
.ToListAsync();
requests.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
await CheckForSubscription(shouldHide, x);
});
return new RequestsViewModel<MovieRequests>
{
Collection = requests,
Total = total
};
}
public async Task<RequestEngineResult> UpdateAdvancedOptions(MovieAdvancedOptions options)
{
var request = await MovieRepository.Find(options.RequestId);

@ -266,7 +266,61 @@ namespace Ombi.Core.Engine
// Make sure we do not show duplicate child requests
allRequests = allRequests.DistinctBy(x => x.ParentRequest.Title).ToList();
allRequests = allRequests.Skip(position).Take(count).ToList();
return new RequestsViewModel<ChildRequests>
{
Collection = allRequests,
Total = total,
};
}
public async Task<RequestsViewModel<ChildRequests>> GetUnavailableRequests(int count, int position, string sortProperty, string sortOrder)
{
var shouldHide = await HideFromOtherUsers();
List<ChildRequests> allRequests;
if (shouldHide.Hide)
{
allRequests = await TvRepository.GetChild(shouldHide.UserId).Where(x => !x.Available).ToListAsync();
// Filter out children
FilterChildren(allRequests, shouldHide);
}
else
{
allRequests = await TvRepository.GetChild().Where(x => !x.Available).ToListAsync();
}
if (allRequests == null)
{
return new RequestsViewModel<ChildRequests>();
}
var total = allRequests.Count;
var prop = TypeDescriptor.GetProperties(typeof(ChildRequests)).Find(sortProperty, true);
if (sortProperty.Contains('.'))
{
// This is a navigation property currently not supported
prop = TypeDescriptor.GetProperties(typeof(ChildRequests)).Find("Title", true);
//var properties = sortProperty.Split(new []{'.'}, StringSplitOptions.RemoveEmptyEntries);
//var firstProp = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find(properties[0], true);
//var propType = firstProp.PropertyType;
//var secondProp = TypeDescriptor.GetProperties(propType).Find(properties[1], true);
}
allRequests = sortOrder.Equals("asc", StringComparison.InvariantCultureIgnoreCase)
? allRequests.OrderBy(x => prop.GetValue(x)).ToList()
: allRequests.OrderByDescending(x => prop.GetValue(x)).ToList();
allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
// Make sure we do not show duplicate child requests
allRequests = allRequests.DistinctBy(x => x.ParentRequest.Title).ToList();
allRequests = allRequests.Skip(position).Take(count).ToList();
return new RequestsViewModel<ChildRequests>
{
Collection = allRequests,

@ -39,6 +39,19 @@ namespace Ombi.Controllers.V2
return await _movieRequestEngine.GetRequests(count, position, sort, sortOrder);
}
/// <summary>
/// Gets the unavailable movie requests.
/// </summary>
/// <param name="count">The count of items you want to return. e.g. 30</param>
/// <param name="position">The position. e.g. position 60 for a 2nd page (since we have already got the first 30 items)</param>
/// <param name="sort">The item to sort on e.g. "requestDate"</param>
/// <param name="sortOrder">asc or desc</param>
[HttpGet("movie/unavailable/{count:int}/{position:int}/{sort}/{sortOrder}")]
public async Task<RequestsViewModel<MovieRequests>> GetNotAvailableRequests(int count, int position, string sort, string sortOrder)
{
return await _movieRequestEngine.GetUnavailableRequests(count, position, sort, sortOrder);
}
/// <summary>
/// Gets Tv requests.
/// </summary>
@ -52,6 +65,19 @@ namespace Ombi.Controllers.V2
return await _tvRequestEngine.GetRequests(count, position, sort, sortOrder);
}
/// <summary>
/// Gets unavailable Tv requests.
/// </summary>
/// <param name="count">The count of items you want to return. e.g. 30</param>
/// <param name="position">The position. e.g. position 60 for a 2nd page (since we have already got the first 30 items)</param>
/// <param name="sort">The item to sort on e.g. "requestDate"</param>
/// <param name="sortOrder">asc or desc</param>
[HttpGet("tv/{count:int}/{position:int}/{sort}/{sortOrder}")]
public async Task<RequestsViewModel<ChildRequests>> GetNotAvailableTvRequests(int count, int position, string sort, string sortOrder)
{
return await _tvRequestEngine.GetRequests(count, position, sort, sortOrder);
}
[HttpPost("movie/advancedoptions")]
public async Task<RequestEngineResult> UpdateAdvancedOptions([FromBody] MovieAdvancedOptions options)
{

Loading…
Cancel
Save