added CriticReviews api endpoint

pull/702/head
Luke Pulverenti 12 years ago
parent 3a814a8b92
commit 0c59ec65ca

@ -0,0 +1,100 @@
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Querying;
using ServiceStack.ServiceHost;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace MediaBrowser.Api
{
/// <summary>
/// Class GetCriticReviews
/// </summary>
[Route("/Items/{Id}/CriticReviews", "GET")]
[Api(Description = "Gets critic reviews for an item")]
public class GetCriticReviews : IReturn<ItemReviewsResult>
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { 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; }
}
/// <summary>
/// Class LibraryService
/// </summary>
public class LibraryService : BaseApiService
{
/// <summary>
/// The _item repo
/// </summary>
private readonly IItemRepository _itemRepo;
/// <summary>
/// Initializes a new instance of the <see cref="LibraryService"/> class.
/// </summary>
/// <param name="itemRepo">The item repo.</param>
public LibraryService(IItemRepository itemRepo)
{
_itemRepo = itemRepo;
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetCriticReviews request)
{
var result = GetCriticReviewsAsync(request).Result;
return ToOptimizedResult(result);
}
/// <summary>
/// Gets the critic reviews async.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Task{ItemReviewsResult}.</returns>
private async Task<ItemReviewsResult> GetCriticReviewsAsync(GetCriticReviews request)
{
var reviews = await _itemRepo.GetCriticReviews(new Guid(request.Id)).ConfigureAwait(false);
var reviewsArray = reviews.ToArray();
var result = new ItemReviewsResult
{
TotalRecordCount = reviewsArray.Length
};
if (request.StartIndex.HasValue)
{
reviewsArray = reviewsArray.Skip(request.StartIndex.Value).ToArray();
}
if (request.Limit.HasValue)
{
reviewsArray = reviewsArray.Take(request.Limit.Value).ToArray();
}
result.ItemReviews = reviewsArray;
return result;
}
}
}

@ -68,6 +68,7 @@
<Compile Include="Images\ImageRequest.cs" />
<Compile Include="Images\ImageService.cs" />
<Compile Include="Images\ImageWriter.cs" />
<Compile Include="LibraryService.cs" />
<Compile Include="Library\LibraryHelpers.cs" />
<Compile Include="Library\LibraryService.cs" />
<Compile Include="Library\LibraryStructureService.cs" />

@ -54,6 +54,7 @@
<Compile Include="Net\WebSocketMessageType.cs" />
<Compile Include="Net\WebSocketState.cs" />
<Compile Include="Querying\ArtistsQuery.cs" />
<Compile Include="Querying\ItemReviewsResult.cs" />
<Compile Include="Querying\ItemsByNameQuery.cs" />
<Compile Include="Entities\BaseItemInfo.cs" />
<Compile Include="Session\BrowseRequest.cs" />

@ -0,0 +1,30 @@
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Model.Querying
{
/// <summary>
/// Class ItemReviewsResult
/// </summary>
public class ItemReviewsResult
{
/// <summary>
/// Gets or sets the item reviews.
/// </summary>
/// <value>The item reviews.</value>
public ItemReview[] ItemReviews { get; set; }
/// <summary>
/// The total number of records available
/// </summary>
/// <value>The total record count.</value>
public int TotalRecordCount { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ItemsResult" /> class.
/// </summary>
public ItemReviewsResult()
{
ItemReviews = new ItemReview[] { };
}
}
}
Loading…
Cancel
Save