Added a bunch of new API endpoints for requests

pull/3528/head
Jamie Rees 5 years ago
parent 8789ac81cf
commit 2bf67ffafe

@ -23,6 +23,7 @@ namespace Ombi.Core.Engine.Interfaces
Task<RequestsViewModel<MovieRequests>> GetUnavailableRequests(int count, int position, string sortProperty, Task<RequestsViewModel<MovieRequests>> GetUnavailableRequests(int count, int position, string sortProperty,
string sortOrder); string sortOrder);
Task<RequestsViewModel<MovieRequests>> GetRequestsByStatus(int count, int position, string sortProperty, string sortOrder, RequestStatus status);
Task<RequestEngineResult> UpdateAdvancedOptions(MovieAdvancedOptions options); Task<RequestEngineResult> UpdateAdvancedOptions(MovieAdvancedOptions options);
} }
} }

@ -25,5 +25,6 @@ namespace Ombi.Core.Engine.Interfaces
Task UpdateQualityProfile(int requestId, int profileId); Task UpdateQualityProfile(int requestId, int profileId);
Task UpdateRootPath(int requestId, int rootPath); Task UpdateRootPath(int requestId, int rootPath);
Task<RequestsViewModel<ChildRequests>> GetRequests(int count, int position, string sortProperty, string sortOrder); Task<RequestsViewModel<ChildRequests>> GetRequests(int count, int position, string sortProperty, string sortOrder);
Task<RequestsViewModel<ChildRequests>> GetRequests(int count, int position, string sortProperty, string sortOrder, RequestStatus status);
} }
} }

@ -240,6 +240,69 @@ namespace Ombi.Core.Engine
Total = total Total = total
}; };
} }
public async Task<RequestsViewModel<MovieRequests>> GetRequestsByStatus(int count, int position, string sortProperty, string sortOrder, RequestStatus status)
{
var shouldHide = await HideFromOtherUsers();
IQueryable<MovieRequests> allRequests;
if (shouldHide.Hide)
{
allRequests =
MovieRepository.GetWithUser(shouldHide
.UserId);
}
else
{
allRequests =
MovieRepository
.GetWithUser();
}
switch (status)
{
case RequestStatus.PendingApproval:
allRequests = allRequests.Where(x => !x.Approved && !x.Available && (!x.Denied.HasValue || !x.Denied.Value));
break;
case RequestStatus.ProcessingRequest:
allRequests = allRequests.Where(x => x.Approved && !x.Available && (!x.Denied.HasValue || !x.Denied.Value));
break;
case RequestStatus.Available:
allRequests = allRequests.Where(x => x.Available && (!x.Denied.HasValue || !x.Denied.Value));
break;
case RequestStatus.Denied:
allRequests = allRequests.Where(x => x.Denied.HasValue && x.Denied.Value);
break;
default:
break;
}
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);
}
// TODO fix this so we execute this on the server
var requests = sortOrder.Equals("asc", StringComparison.InvariantCultureIgnoreCase)
? allRequests.ToList().OrderBy(x => x.RequestedDate).ToList()
: allRequests.ToList().OrderByDescending(x => prop.GetValue(x)).ToList();
var total = requests.Count();
requests = requests.Skip(position).Take(count).ToList();
await CheckForSubscription(shouldHide, requests);
return new RequestsViewModel<MovieRequests>
{
Collection = requests,
Total = total
};
}
public async Task<RequestsViewModel<MovieRequests>> GetUnavailableRequests(int count, int position, string sortProperty, string sortOrder) public async Task<RequestsViewModel<MovieRequests>> GetUnavailableRequests(int count, int position, string sortProperty, string sortOrder)
{ {
var shouldHide = await HideFromOtherUsers(); var shouldHide = await HideFromOtherUsers();

@ -248,6 +248,79 @@ namespace Ombi.Core.Engine
var total = allRequests.Count; 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();
await CheckForSubscription(shouldHide, allRequests);
// 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>> GetRequests(int count, int position, string sortProperty, string sortOrder, RequestStatus status)
{
var shouldHide = await HideFromOtherUsers();
List<ChildRequests> allRequests;
if (shouldHide.Hide)
{
allRequests = await TvRepository.GetChild(shouldHide.UserId).ToListAsync();
// Filter out children
FilterChildren(allRequests, shouldHide);
}
else
{
allRequests = await TvRepository.GetChild().ToListAsync();
}
switch (status)
{
case RequestStatus.PendingApproval:
allRequests = allRequests.Where(x => !x.Approved && !x.Available && (!x.Denied.HasValue || !x.Denied.Value)).ToList();
break;
case RequestStatus.ProcessingRequest:
allRequests = allRequests.Where(x => x.Approved && !x.Available && (!x.Denied.HasValue || !x.Denied.Value)).ToList();
break;
case RequestStatus.Available:
allRequests = allRequests.Where(x => x.Available && (!x.Denied.HasValue || !x.Denied.Value)).ToList();
break;
case RequestStatus.Denied:
allRequests = allRequests.Where(x => x.Denied.HasValue && x.Denied.Value).ToList();
break;
default:
break;
}
if (allRequests == null)
{
return new RequestsViewModel<ChildRequests>();
}
var total = allRequests.Count;
var prop = TypeDescriptor.GetProperties(typeof(ChildRequests)).Find(sortProperty, true); var prop = TypeDescriptor.GetProperties(typeof(ChildRequests)).Find(sortProperty, true);
if (sortProperty.Contains('.')) if (sortProperty.Contains('.'))

@ -0,0 +1,10 @@
namespace Ombi.Core.Models.Requests
{
public enum RequestStatus
{
PendingApproval,
ProcessingRequest,
Available,
Denied
}
}

@ -36,6 +36,30 @@ namespace Ombi.Controllers.V2
return await _movieRequestEngine.GetRequests(count, position, sort, sortOrder); return await _movieRequestEngine.GetRequests(count, position, sort, sortOrder);
} }
[HttpGet("movie/availble/{count:int}/{position:int}/{sort}/{sortOrder}")]
public async Task<RequestsViewModel<MovieRequests>> GetAvailableRequests(int count, int position, string sort, string sortOrder)
{
return await _movieRequestEngine.GetRequestsByStatus(count, position, sort, sortOrder, RequestStatus.Available);
}
[HttpGet("movie/processing/{count:int}/{position:int}/{sort}/{sortOrder}")]
public async Task<RequestsViewModel<MovieRequests>> GetProcessingRequests(int count, int position, string sort, string sortOrder)
{
return await _movieRequestEngine.GetRequestsByStatus(count, position, sort, sortOrder, RequestStatus.ProcessingRequest);
}
[HttpGet("movie/pending/{count:int}/{position:int}/{sort}/{sortOrder}")]
public async Task<RequestsViewModel<MovieRequests>> GetPendingRequests(int count, int position, string sort, string sortOrder)
{
return await _movieRequestEngine.GetRequestsByStatus(count, position, sort, sortOrder, RequestStatus.PendingApproval);
}
[HttpGet("movie/denied/{count:int}/{position:int}/{sort}/{sortOrder}")]
public async Task<RequestsViewModel<MovieRequests>> GetDeniedRequests(int count, int position, string sort, string sortOrder)
{
return await _movieRequestEngine.GetRequestsByStatus(count, position, sort, sortOrder, RequestStatus.Denied);
}
/// <summary> /// <summary>
/// Gets the unavailable movie requests. /// Gets the unavailable movie requests.
/// </summary> /// </summary>
@ -62,6 +86,30 @@ namespace Ombi.Controllers.V2
return await _tvRequestEngine.GetRequests(count, position, sort, sortOrder); return await _tvRequestEngine.GetRequests(count, position, sort, sortOrder);
} }
[HttpGet("tv/pending/{count:int}/{position:int}/{sort}/{sortOrder}")]
public async Task<RequestsViewModel<ChildRequests>> GetPendingTvRequests(int count, int position, string sort, string sortOrder)
{
return await _tvRequestEngine.GetRequests(count, position, sort, sortOrder, RequestStatus.PendingApproval);
}
[HttpGet("tv/processing/{count:int}/{position:int}/{sort}/{sortOrder}")]
public async Task<RequestsViewModel<ChildRequests>> GetProcessingTvRequests(int count, int position, string sort, string sortOrder)
{
return await _tvRequestEngine.GetRequests(count, position, sort, sortOrder, RequestStatus.ProcessingRequest);
}
[HttpGet("tv/available/{count:int}/{position:int}/{sort}/{sortOrder}")]
public async Task<RequestsViewModel<ChildRequests>> GetAvailableTvRequests(int count, int position, string sort, string sortOrder)
{
return await _tvRequestEngine.GetRequests(count, position, sort, sortOrder, RequestStatus.Available);
}
[HttpGet("tv/denied/{count:int}/{position:int}/{sort}/{sortOrder}")]
public async Task<RequestsViewModel<ChildRequests>> GetDeniedTvRequests(int count, int position, string sort, string sortOrder)
{
return await _tvRequestEngine.GetRequests(count, position, sort, sortOrder, RequestStatus.Denied);
}
/// <summary> /// <summary>
/// Gets unavailable Tv requests. /// Gets unavailable Tv requests.
/// </summary> /// </summary>

Loading…
Cancel
Save