added more sorting to ibn endpoints

pull/702/head
Luke Pulverenti 11 years ago
parent 50aa0b8675
commit 032f3d376b

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Serialization;
using ServiceStack.ServiceHost;
@ -20,7 +21,7 @@ namespace MediaBrowser.Api
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "DisplayPreferencesId", Description = "DisplayPreferences Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public Guid DisplayPreferencesId { get; set; }
public string DisplayPreferencesId { get; set; }
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public Guid UserId { get; set; }
@ -38,7 +39,7 @@ namespace MediaBrowser.Api
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public Guid Id { get; set; }
public string Id { get; set; }
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public Guid UserId { get; set; }
@ -78,7 +79,14 @@ namespace MediaBrowser.Api
/// <param name="request">The request.</param>
public object Get(GetDisplayPreferences request)
{
var result = _displayPreferencesManager.GetDisplayPreferences(request.Id, request.UserId, request.Client);
Guid displayPreferencesId;
if (!Guid.TryParse(request.Id, out displayPreferencesId))
{
displayPreferencesId = request.Id.GetMD5();
}
var result = _displayPreferencesManager.GetDisplayPreferences(displayPreferencesId, request.UserId, request.Client);
return ToOptimizedResult(result);
}

@ -142,6 +142,12 @@ namespace MediaBrowser.Api.UserLibrary
items = items.Where(i => string.Compare(request.NameStartsWithOrGreater, i.Name, StringComparison.CurrentCultureIgnoreCase) < 1);
}
var imageTypes = request.GetImageTypes().ToArray();
if (imageTypes.Length > 0)
{
items = items.Where(item => imageTypes.Any(imageType => ItemsService.HasImage(item.GetItem().Result, imageType)));
}
var filters = request.GetFilters().ToList();
if (filters.Count == 0)
@ -221,6 +227,17 @@ namespace MediaBrowser.Api.UserLibrary
items = items.OrderBy(i => i.Name);
}
}
else if (string.Equals(request.SortBy, "Random", StringComparison.OrdinalIgnoreCase))
{
if (request.SortOrder.HasValue && request.SortOrder.Value == Model.Entities.SortOrder.Descending)
{
items = items.OrderByDescending(i => Guid.NewGuid());
}
else
{
items = items.OrderBy(i => Guid.NewGuid());
}
}
return items;
}
@ -358,7 +375,6 @@ namespace MediaBrowser.Api.UserLibrary
public string Name;
public BaseItem Item;
private UserItemData _userData;
public List<BaseItem> Items

@ -79,6 +79,13 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "MediaTypes", Description = "Optional filter by MediaType. Allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string MediaTypes { get; set; }
/// <summary>
/// Gets or sets the image types.
/// </summary>
/// <value>The image types.</value>
[ApiMember(Name = "ImageTypes", Description = "Optional. If specified, results will be filtered based on those containing image types. This allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string ImageTypes { get; set; }
/// <summary>
/// Gets the filters.
/// </summary>
@ -120,5 +127,21 @@ namespace MediaBrowser.Api.UserLibrary
}).Where(i => i.HasValue).Select(i => i.Value);
}
/// <summary>
/// Gets the image types.
/// </summary>
/// <returns>IEnumerable{ImageType}.</returns>
public IEnumerable<ImageType> GetImageTypes()
{
var val = ImageTypes;
if (string.IsNullOrEmpty(val))
{
return new ImageType[] { };
}
return val.Split(',').Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true));
}
}
}

@ -87,7 +87,7 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "Albums", Description = "Optional. If specified, results will be filtered based on album. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Albums { get; set; }
/// <summary>
/// Limit results to items containing specific years
/// </summary>
@ -95,13 +95,6 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "Years", Description = "Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Years { get; set; }
/// <summary>
/// Gets or sets the image types.
/// </summary>
/// <value>The image types.</value>
[ApiMember(Name = "ImageTypes", Description = "Optional. If specified, results will be filtered based on those containing image types. This allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string ImageTypes { get; set; }
/// <summary>
/// Gets or sets the item ids.
/// </summary>
@ -174,7 +167,7 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "MinIndexNumber", Description = "Optional filter index number.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? MinIndexNumber { get; set; }
/// <summary>
/// Gets the order by.
/// </summary>
@ -620,7 +613,7 @@ namespace MediaBrowser.Api.UserLibrary
items = items.Where(i => !string.IsNullOrEmpty(i.MediaType) && types.Contains(i.MediaType, StringComparer.OrdinalIgnoreCase));
}
var imageTypes = GetImageTypes(request).ToArray();
var imageTypes = request.GetImageTypes().ToArray();
if (imageTypes.Length > 0)
{
items = items.Where(item => imageTypes.Any(imageType => HasImage(item, imageType)));
@ -717,7 +710,7 @@ namespace MediaBrowser.Api.UserLibrary
/// <param name="item">The item.</param>
/// <param name="imageType">Type of the image.</param>
/// <returns><c>true</c> if the specified item has image; otherwise, <c>false</c>.</returns>
private static bool HasImage(BaseItem item, ImageType imageType)
internal static bool HasImage(BaseItem item, ImageType imageType)
{
if (imageType == ImageType.Backdrop)
{
@ -772,23 +765,6 @@ namespace MediaBrowser.Api.UserLibrary
return items;
}
/// <summary>
/// Gets the image types.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>IEnumerable{ImageType}.</returns>
private static IEnumerable<ImageType> GetImageTypes(GetItems request)
{
var val = request.ImageTypes;
if (string.IsNullOrEmpty(val))
{
return new ImageType[] { };
}
return val.Split(',').Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true));
}
}
/// <summary>

Loading…
Cancel
Save