public object Get(GetLatestMedia request) { var user = _userManager.GetUserById(request.UserId); if (!request.IsPlayed.HasValue) { if (user.Configuration.HidePlayedInLatest) { request.IsPlayed = false; } } var dtoOptions = GetDtoOptions(_authContext, request); var list = _userViewManager.GetLatestItems(new LatestItemsQuery { GroupItems = request.GroupItems, IncludeItemTypes = ApiEntryPoint.Split(request.IncludeItemTypes, ',', true), IsPlayed = request.IsPlayed, Limit = request.Limit, ParentId = request.ParentId, UserId = request.UserId, }, dtoOptions); var dtos = list.Select(i => { var item = i.Item2[0]; var childCount = 0; if (i.Item1 != null && (i.Item2.Count > 1 || i.Item1 is MusicAlbum)) { item = i.Item1; childCount = i.Item2.Count; } var dto = _dtoService.GetBaseItemDto(item, dtoOptions, user); dto.ChildCount = childCount; return(dto); }); return(ToOptimizedResult(dtos.ToArray())); }
public IActionResult GetAsync() { var apiEntryPoint = new ApiEntryPoint { Message = @"Entry point into the Blogging Hypermedia API powered by JsonApiFramework [Server]." + " " + "Implements the JSON API 1.0 specification.", Version = "1.0" }; ///////////////////////////////////////////////////// // Build JSON API document ///////////////////////////////////////////////////// var currentRequestUri = this.GetCurrentRequestUri(); var scheme = currentRequestUri.Scheme; var host = currentRequestUri.Host; var port = currentRequestUri.Port; var urlBuilderConfiguration = new UrlBuilderConfiguration(scheme, host, port); var blogsResourceCollectionLink = CreateBlogsResourceCollectionLink(urlBuilderConfiguration); var articlesResourceCollectionLink = CreateArticlesResourceCollectionUrl(urlBuilderConfiguration); var commentsResourceCollectionLink = CreateCommentsResourceCollectionUrl(urlBuilderConfiguration); var peopleResourceCollectionLink = CreatePeopleResourceCollectionUrl(urlBuilderConfiguration); using var documentContext = this.ApiServiceContext.CreateApiDocumentContext(); var document = documentContext .NewDocument(currentRequestUri) .SetJsonApiVersion(JsonApiVersion.Version10) .Links() .AddSelfLink() .LinksEnd() .Resource(apiEntryPoint) .Links() .AddLink("blogs", blogsResourceCollectionLink) .AddLink("articles", articlesResourceCollectionLink) .AddLink("comments", commentsResourceCollectionLink) .AddLink("people", peopleResourceCollectionLink) .LinksEnd() .ResourceEnd() .WriteDocument(); return(this.Ok(document)); }