From 0c59ec65cae5943d03060ff3ac6fa2da58e7d8ad Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 11 May 2013 00:10:58 -0400 Subject: added CriticReviews api endpoint --- MediaBrowser.Api/LibraryService.cs | 100 +++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 MediaBrowser.Api/LibraryService.cs (limited to 'MediaBrowser.Api/LibraryService.cs') diff --git a/MediaBrowser.Api/LibraryService.cs b/MediaBrowser.Api/LibraryService.cs new file mode 100644 index 000000000..a6e7598aa --- /dev/null +++ b/MediaBrowser.Api/LibraryService.cs @@ -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 +{ + /// + /// Class GetCriticReviews + /// + [Route("/Items/{Id}/CriticReviews", "GET")] + [Api(Description = "Gets critic reviews for an item")] + public class GetCriticReviews : IReturn + { + /// + /// Gets or sets the id. + /// + /// The id. + [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string Id { get; set; } + + /// + /// Skips over a given number of items within the results. Use for paging. + /// + /// The start index. + [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; } + + /// + /// The maximum number of items to return + /// + /// The limit. + [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; } + } + + /// + /// Class LibraryService + /// + public class LibraryService : BaseApiService + { + /// + /// The _item repo + /// + private readonly IItemRepository _itemRepo; + + /// + /// Initializes a new instance of the class. + /// + /// The item repo. + public LibraryService(IItemRepository itemRepo) + { + _itemRepo = itemRepo; + } + + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetCriticReviews request) + { + var result = GetCriticReviewsAsync(request).Result; + + return ToOptimizedResult(result); + } + + /// + /// Gets the critic reviews async. + /// + /// The request. + /// Task{ItemReviewsResult}. + private async Task 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; + } + } +} -- cgit v1.2.3