Merge pull request #2967 from crobibero/api-channel

Move ChannelService to Jellyfin.Api
pull/3524/head
Patrick Barron 4 years ago committed by GitHub
commit d80eb91ba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,256 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Api.Constants;
using Jellyfin.Api.Extensions;
using Jellyfin.Api.Helpers;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Jellyfin.Api.Controllers
{
/// <summary>
/// Channels Controller.
/// </summary>
[Authorize(Policy = Policies.DefaultAuthorization)]
public class ChannelsController : BaseJellyfinApiController
{
private readonly IChannelManager _channelManager;
private readonly IUserManager _userManager;
/// <summary>
/// Initializes a new instance of the <see cref="ChannelsController"/> class.
/// </summary>
/// <param name="channelManager">Instance of the <see cref="IChannelManager"/> interface.</param>
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
public ChannelsController(IChannelManager channelManager, IUserManager userManager)
{
_channelManager = channelManager;
_userManager = userManager;
}
/// <summary>
/// Gets available channels.
/// </summary>
/// <param name="userId">User Id to filter by. Use <see cref="Guid.Empty"/> to not filter by user.</param>
/// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
/// <param name="limit">Optional. The maximum number of records to return.</param>
/// <param name="supportsLatestItems">Optional. Filter by channels that support getting latest items.</param>
/// <param name="supportsMediaDeletion">Optional. Filter by channels that support media deletion.</param>
/// <param name="isFavorite">Optional. Filter by channels that are favorite.</param>
/// <response code="200">Channels returned.</response>
/// <returns>An <see cref="OkResult"/> containing the channels.</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult<QueryResult<BaseItemDto>> GetChannels(
[FromQuery] Guid userId,
[FromQuery] int? startIndex,
[FromQuery] int? limit,
[FromQuery] bool? supportsLatestItems,
[FromQuery] bool? supportsMediaDeletion,
[FromQuery] bool? isFavorite)
{
return _channelManager.GetChannels(new ChannelQuery
{
Limit = limit,
StartIndex = startIndex,
UserId = userId,
SupportsLatestItems = supportsLatestItems,
SupportsMediaDeletion = supportsMediaDeletion,
IsFavorite = isFavorite
});
}
/// <summary>
/// Get all channel features.
/// </summary>
/// <response code="200">All channel features returned.</response>
/// <returns>An <see cref="OkResult"/> containing the channel features.</returns>
[HttpGet("Features")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult<IEnumerable<ChannelFeatures>> GetAllChannelFeatures()
{
return _channelManager.GetAllChannelFeatures();
}
/// <summary>
/// Get channel features.
/// </summary>
/// <param name="channelId">Channel id.</param>
/// <response code="200">Channel features returned.</response>
/// <returns>An <see cref="OkResult"/> containing the channel features.</returns>
[HttpGet("{channelId}/Features")]
public ActionResult<ChannelFeatures> GetChannelFeatures([FromRoute] string channelId)
{
return _channelManager.GetChannelFeatures(channelId);
}
/// <summary>
/// Get channel items.
/// </summary>
/// <param name="channelId">Channel Id.</param>
/// <param name="folderId">Optional. Folder Id.</param>
/// <param name="userId">Optional. User Id.</param>
/// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
/// <param name="limit">Optional. The maximum number of records to return.</param>
/// <param name="sortOrder">Optional. Sort Order - Ascending,Descending.</param>
/// <param name="filters">Optional. Specify additional filters to apply. This allows multiple, comma delimited. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes.</param>
/// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited. Options: Album, AlbumArtist, Artist, Budget, CommunityRating, CriticRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Revenue, Runtime.</param>
/// <param name="fields">Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimited. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines.</param>
/// <response code="200">Channel items returned.</response>
/// <returns>
/// A <see cref="Task"/> representing the request to get the channel items.
/// The task result contains an <see cref="OkResult"/> containing the channel items.
/// </returns>
[HttpGet("{channelId}/Items")]
public async Task<ActionResult<QueryResult<BaseItemDto>>> GetChannelItems(
[FromRoute] Guid channelId,
[FromQuery] Guid? folderId,
[FromQuery] Guid? userId,
[FromQuery] int? startIndex,
[FromQuery] int? limit,
[FromQuery] string? sortOrder,
[FromQuery] string? filters,
[FromQuery] string? sortBy,
[FromQuery] string? fields)
{
var user = userId == null
? null
: _userManager.GetUserById(userId.Value);
var query = new InternalItemsQuery(user)
{
Limit = limit,
StartIndex = startIndex,
ChannelIds = new[] { channelId },
ParentId = folderId ?? Guid.Empty,
OrderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder),
DtoOptions = new DtoOptions()
.AddItemFields(fields)
};
foreach (var filter in RequestHelpers.GetFilters(filters))
{
switch (filter)
{
case ItemFilter.IsFolder:
query.IsFolder = true;
break;
case ItemFilter.IsNotFolder:
query.IsFolder = false;
break;
case ItemFilter.IsUnplayed:
query.IsPlayed = false;
break;
case ItemFilter.IsPlayed:
query.IsPlayed = true;
break;
case ItemFilter.IsFavorite:
query.IsFavorite = true;
break;
case ItemFilter.IsResumable:
query.IsResumable = true;
break;
case ItemFilter.Likes:
query.IsLiked = true;
break;
case ItemFilter.Dislikes:
query.IsLiked = false;
break;
case ItemFilter.IsFavoriteOrLikes:
query.IsFavoriteOrLiked = true;
break;
}
}
return await _channelManager.GetChannelItems(query, CancellationToken.None).ConfigureAwait(false);
}
/// <summary>
/// Gets latest channel items.
/// </summary>
/// <param name="userId">Optional. User Id.</param>
/// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
/// <param name="limit">Optional. The maximum number of records to return.</param>
/// <param name="filters">Optional. Specify additional filters to apply. This allows multiple, comma delimited. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes.</param>
/// <param name="fields">Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimited. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines.</param>
/// <param name="channelIds">Optional. Specify one or more channel id's, comma delimited.</param>
/// <response code="200">Latest channel items returned.</response>
/// <returns>
/// A <see cref="Task"/> representing the request to get the latest channel items.
/// The task result contains an <see cref="OkResult"/> containing the latest channel items.
/// </returns>
[HttpGet("Items/Latest")]
public async Task<ActionResult<QueryResult<BaseItemDto>>> GetLatestChannelItems(
[FromQuery] Guid? userId,
[FromQuery] int? startIndex,
[FromQuery] int? limit,
[FromQuery] string filters,
[FromQuery] string fields,
[FromQuery] string channelIds)
{
var user = userId == null || userId == Guid.Empty
? null
: _userManager.GetUserById(userId.Value);
var query = new InternalItemsQuery(user)
{
Limit = limit,
StartIndex = startIndex,
ChannelIds = (channelIds ?? string.Empty)
.Split(',')
.Where(i => !string.IsNullOrWhiteSpace(i))
.Select(i => new Guid(i))
.ToArray(),
DtoOptions = new DtoOptions()
.AddItemFields(fields)
};
foreach (var filter in RequestHelpers.GetFilters(filters))
{
switch (filter)
{
case ItemFilter.IsFolder:
query.IsFolder = true;
break;
case ItemFilter.IsNotFolder:
query.IsFolder = false;
break;
case ItemFilter.IsUnplayed:
query.IsPlayed = false;
break;
case ItemFilter.IsPlayed:
query.IsPlayed = true;
break;
case ItemFilter.IsFavorite:
query.IsFavorite = true;
break;
case ItemFilter.IsResumable:
query.IsResumable = true;
break;
case ItemFilter.Likes:
query.IsLiked = true;
break;
case ItemFilter.Dislikes:
query.IsLiked = false;
break;
case ItemFilter.IsFavoriteOrLikes:
query.IsFavoriteOrLiked = true;
break;
}
}
return await _channelManager.GetLatestChannelItems(query, CancellationToken.None).ConfigureAwait(false);
}
}
}

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Jellyfin.Data.Enums; using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
@ -14,6 +15,58 @@ namespace Jellyfin.Api.Helpers
/// </summary> /// </summary>
public static class RequestHelpers public static class RequestHelpers
{ {
/// <summary>
/// Get Order By.
/// </summary>
/// <param name="sortBy">Sort By. Comma delimited string.</param>
/// <param name="requestedSortOrder">Sort Order. Comma delimited string.</param>
/// <returns>Order By.</returns>
public static ValueTuple<string, SortOrder>[] GetOrderBy(string? sortBy, string? requestedSortOrder)
{
var val = sortBy;
if (string.IsNullOrEmpty(val))
{
return Array.Empty<ValueTuple<string, SortOrder>>();
}
var vals = val.Split(',');
if (string.IsNullOrWhiteSpace(requestedSortOrder))
{
requestedSortOrder = "Ascending";
}
var sortOrders = requestedSortOrder.Split(',');
var result = new ValueTuple<string, SortOrder>[vals.Length];
for (var i = 0; i < vals.Length; i++)
{
var sortOrderIndex = sortOrders.Length > i ? i : 0;
var sortOrderValue = sortOrders.Length > sortOrderIndex ? sortOrders[sortOrderIndex] : null;
var sortOrder = string.Equals(sortOrderValue, "Descending", StringComparison.OrdinalIgnoreCase)
? SortOrder.Descending
: SortOrder.Ascending;
result[i] = new ValueTuple<string, SortOrder>(vals[i], sortOrder);
}
return result;
}
/// <summary>
/// Get parsed filters.
/// </summary>
/// <param name="filters">The filters.</param>
/// <returns>Item filters.</returns>
public static IEnumerable<ItemFilter> GetFilters(string? filters)
{
return string.IsNullOrEmpty(filters)
? Array.Empty<ItemFilter>()
: filters.Split(',').Select(v => Enum.Parse<ItemFilter>(v, true));
}
/// <summary> /// <summary>
/// Splits a string at a separating character into an array of substrings. /// Splits a string at a separating character into an array of substrings.
/// </summary> /// </summary>
@ -94,57 +147,6 @@ namespace Jellyfin.Api.Helpers
.ToArray(); .ToArray();
} }
/// <summary>
/// Get orderby.
/// </summary>
/// <param name="sortBy">Sort by.</param>
/// <param name="requestedSortOrder">Sort order.</param>
/// <returns>Resulting order by.</returns>
internal static ValueTuple<string, SortOrder>[] GetOrderBy(string? sortBy, string? requestedSortOrder)
{
if (string.IsNullOrEmpty(sortBy))
{
return Array.Empty<ValueTuple<string, SortOrder>>();
}
var vals = sortBy.Split(',');
if (string.IsNullOrWhiteSpace(requestedSortOrder))
{
requestedSortOrder = "Ascending";
}
var sortOrders = requestedSortOrder.Split(',');
var result = new ValueTuple<string, SortOrder>[vals.Length];
for (var i = 0; i < vals.Length; i++)
{
var sortOrderIndex = sortOrders.Length > i ? i : 0;
var sortOrderValue = sortOrders.Length > sortOrderIndex ? sortOrders[sortOrderIndex] : null;
var sortOrder = string.Equals(sortOrderValue, "Descending", StringComparison.OrdinalIgnoreCase)
? SortOrder.Descending
: SortOrder.Ascending;
result[i] = new ValueTuple<string, SortOrder>(vals[i], sortOrder);
}
return result;
}
/// <summary>
/// Gets the filters.
/// </summary>
/// <param name="filters">The filter string.</param>
/// <returns>IEnumerable{ItemFilter}.</returns>
internal static ItemFilter[] GetFilters(string filters)
{
return string.IsNullOrEmpty(filters)
? Array.Empty<ItemFilter>()
: Split(filters, ',', true)
.Select(v => Enum.Parse<ItemFilter>(v, true)).ToArray();
}
/// <summary> /// <summary>
/// Gets the item fields. /// Gets the item fields.
/// </summary> /// </summary>

@ -1,341 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Api.UserLibrary;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api
{
[Route("/Channels", "GET", Summary = "Gets available channels")]
public class GetChannels : IReturn<QueryResult<BaseItemDto>>
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public Guid UserId { get; set; }
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get; set; }
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get; set; }
[ApiMember(Name = "SupportsLatestItems", Description = "Optional. Filter by channels that support getting latest items.", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
public bool? SupportsLatestItems { get; set; }
public bool? SupportsMediaDeletion { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is favorite.
/// </summary>
/// <value><c>null</c> if [is favorite] contains no value, <c>true</c> if [is favorite]; otherwise, <c>false</c>.</value>
public bool? IsFavorite { get; set; }
}
[Route("/Channels/{Id}/Features", "GET", Summary = "Gets features for a channel")]
public class GetChannelFeatures : IReturn<ChannelFeatures>
{
[ApiMember(Name = "Id", Description = "Channel Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get; set; }
}
[Route("/Channels/Features", "GET", Summary = "Gets features for a channel")]
public class GetAllChannelFeatures : IReturn<ChannelFeatures[]>
{
}
[Route("/Channels/{Id}/Items", "GET", Summary = "Gets channel items")]
public class GetChannelItems : IReturn<QueryResult<BaseItemDto>>, IHasItemFields
{
[ApiMember(Name = "Id", Description = "Channel Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get; set; }
[ApiMember(Name = "FolderId", Description = "Folder Id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string FolderId { get; set; }
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public Guid UserId { get; set; }
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get; set; }
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get; set; }
[ApiMember(Name = "SortOrder", Description = "Sort Order - Ascending,Descending", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string SortOrder { get; set; }
[ApiMember(Name = "Filters", Description = "Optional. Specify additional filters to apply. This allows multiple, comma delimeted. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Filters { get; set; }
[ApiMember(Name = "SortBy", Description = "Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, Budget, CommunityRating, CriticRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Revenue, Runtime", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string SortBy { get; set; }
[ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Fields { get; set; }
/// <summary>
/// Gets the filters.
/// </summary>
/// <returns>IEnumerable{ItemFilter}.</returns>
public IEnumerable<ItemFilter> GetFilters()
{
var val = Filters;
return string.IsNullOrEmpty(val)
? Array.Empty<ItemFilter>()
: val.Split(',').Select(v => Enum.Parse<ItemFilter>(v, true));
}
/// <summary>
/// Gets the order by.
/// </summary>
/// <returns>IEnumerable{ItemSortBy}.</returns>
public ValueTuple<string, SortOrder>[] GetOrderBy()
{
return BaseItemsRequest.GetOrderBy(SortBy, SortOrder);
}
}
[Route("/Channels/Items/Latest", "GET", Summary = "Gets channel items")]
public class GetLatestChannelItems : IReturn<QueryResult<BaseItemDto>>, IHasItemFields
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public Guid UserId { get; set; }
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get; set; }
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get; set; }
[ApiMember(Name = "Filters", Description = "Optional. Specify additional filters to apply. This allows multiple, comma delimeted. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Filters { get; set; }
[ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Fields { get; set; }
[ApiMember(Name = "ChannelIds", Description = "Optional. Specify one or more channel id's, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string ChannelIds { get; set; }
/// <summary>
/// Gets the filters.
/// </summary>
/// <returns>IEnumerable{ItemFilter}.</returns>
public IEnumerable<ItemFilter> GetFilters()
{
return string.IsNullOrEmpty(Filters)
? Array.Empty<ItemFilter>()
: Filters.Split(',').Select(v => Enum.Parse<ItemFilter>(v, true));
}
}
[Authenticated]
public class ChannelService : BaseApiService
{
private readonly IChannelManager _channelManager;
private IUserManager _userManager;
public ChannelService(
ILogger<ChannelService> logger,
IServerConfigurationManager serverConfigurationManager,
IHttpResultFactory httpResultFactory,
IChannelManager channelManager,
IUserManager userManager)
: base(logger, serverConfigurationManager, httpResultFactory)
{
_channelManager = channelManager;
_userManager = userManager;
}
public object Get(GetAllChannelFeatures request)
{
var result = _channelManager.GetAllChannelFeatures();
return ToOptimizedResult(result);
}
public object Get(GetChannelFeatures request)
{
var result = _channelManager.GetChannelFeatures(request.Id);
return ToOptimizedResult(result);
}
public object Get(GetChannels request)
{
var result = _channelManager.GetChannels(new ChannelQuery
{
Limit = request.Limit,
StartIndex = request.StartIndex,
UserId = request.UserId,
SupportsLatestItems = request.SupportsLatestItems,
SupportsMediaDeletion = request.SupportsMediaDeletion,
IsFavorite = request.IsFavorite
});
return ToOptimizedResult(result);
}
public async Task<object> Get(GetChannelItems request)
{
var user = request.UserId.Equals(Guid.Empty)
? null
: _userManager.GetUserById(request.UserId);
var query = new InternalItemsQuery(user)
{
Limit = request.Limit,
StartIndex = request.StartIndex,
ChannelIds = new[] { new Guid(request.Id) },
ParentId = string.IsNullOrWhiteSpace(request.FolderId) ? Guid.Empty : new Guid(request.FolderId),
OrderBy = request.GetOrderBy(),
DtoOptions = new Controller.Dto.DtoOptions
{
Fields = request.GetItemFields()
}
};
foreach (var filter in request.GetFilters())
{
switch (filter)
{
case ItemFilter.Dislikes:
query.IsLiked = false;
break;
case ItemFilter.IsFavorite:
query.IsFavorite = true;
break;
case ItemFilter.IsFavoriteOrLikes:
query.IsFavoriteOrLiked = true;
break;
case ItemFilter.IsFolder:
query.IsFolder = true;
break;
case ItemFilter.IsNotFolder:
query.IsFolder = false;
break;
case ItemFilter.IsPlayed:
query.IsPlayed = true;
break;
case ItemFilter.IsResumable:
query.IsResumable = true;
break;
case ItemFilter.IsUnplayed:
query.IsPlayed = false;
break;
case ItemFilter.Likes:
query.IsLiked = true;
break;
}
}
var result = await _channelManager.GetChannelItems(query, CancellationToken.None).ConfigureAwait(false);
return ToOptimizedResult(result);
}
public async Task<object> Get(GetLatestChannelItems request)
{
var user = request.UserId.Equals(Guid.Empty)
? null
: _userManager.GetUserById(request.UserId);
var query = new InternalItemsQuery(user)
{
Limit = request.Limit,
StartIndex = request.StartIndex,
ChannelIds = (request.ChannelIds ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).Select(i => new Guid(i)).ToArray(),
DtoOptions = new Controller.Dto.DtoOptions
{
Fields = request.GetItemFields()
}
};
foreach (var filter in request.GetFilters())
{
switch (filter)
{
case ItemFilter.Dislikes:
query.IsLiked = false;
break;
case ItemFilter.IsFavorite:
query.IsFavorite = true;
break;
case ItemFilter.IsFavoriteOrLikes:
query.IsFavoriteOrLiked = true;
break;
case ItemFilter.IsFolder:
query.IsFolder = true;
break;
case ItemFilter.IsNotFolder:
query.IsFolder = false;
break;
case ItemFilter.IsPlayed:
query.IsPlayed = true;
break;
case ItemFilter.IsResumable:
query.IsResumable = true;
break;
case ItemFilter.IsUnplayed:
query.IsPlayed = false;
break;
case ItemFilter.Likes:
query.IsLiked = true;
break;
}
}
var result = await _channelManager.GetLatestChannelItems(query, CancellationToken.None).ConfigureAwait(false);
return ToOptimizedResult(result);
}
}
}
Loading…
Cancel
Save