mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-14 01:02:57 -07:00
#2932 - Added an api for unavailable requests
This commit is contained in:
parent
cb12160a97
commit
572746351b
4 changed files with 135 additions and 6 deletions
|
@ -20,6 +20,9 @@ namespace Ombi.Core.Engine.Interfaces
|
||||||
Task<RequestEngineResult> ApproveMovieById(int requestId);
|
Task<RequestEngineResult> ApproveMovieById(int requestId);
|
||||||
Task<RequestEngineResult> DenyMovieById(int modelId, string denyReason);
|
Task<RequestEngineResult> DenyMovieById(int modelId, string denyReason);
|
||||||
Task<RequestsViewModel<MovieRequests>> GetRequests(int count, int position, string sortProperty, string sortOrder);
|
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);
|
Task<RequestEngineResult> UpdateAdvancedOptions(MovieAdvancedOptions options);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -246,8 +246,54 @@ namespace Ombi.Core.Engine
|
||||||
Collection = requests,
|
Collection = requests,
|
||||||
Total = total
|
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)
|
public async Task<RequestEngineResult> UpdateAdvancedOptions(MovieAdvancedOptions options)
|
||||||
{
|
{
|
||||||
|
|
|
@ -267,6 +267,60 @@ namespace Ombi.Core.Engine
|
||||||
// Make sure we do not show duplicate child requests
|
// Make sure we do not show duplicate child requests
|
||||||
allRequests = allRequests.DistinctBy(x => x.ParentRequest.Title).ToList();
|
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>
|
return new RequestsViewModel<ChildRequests>
|
||||||
{
|
{
|
||||||
Collection = allRequests,
|
Collection = allRequests,
|
||||||
|
|
|
@ -39,6 +39,19 @@ namespace Ombi.Controllers.V2
|
||||||
return await _movieRequestEngine.GetRequests(count, position, sort, sortOrder);
|
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>
|
/// <summary>
|
||||||
/// Gets Tv requests.
|
/// Gets Tv requests.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -52,6 +65,19 @@ namespace Ombi.Controllers.V2
|
||||||
return await _tvRequestEngine.GetRequests(count, position, sort, sortOrder);
|
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")]
|
[HttpPost("movie/advancedoptions")]
|
||||||
public async Task<RequestEngineResult> UpdateAdvancedOptions([FromBody] MovieAdvancedOptions options)
|
public async Task<RequestEngineResult> UpdateAdvancedOptions([FromBody] MovieAdvancedOptions options)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue