public async Task <HttpResponseMessage> GetAncestors(int id, [ModelBinder(typeof(PagedQueryModelBinder))] PagedRequest query) { if (!await AuthorizationService.AuthorizeAsync(ClaimsPrincipal, new ContentResourceAccess(id), AuthorizationPolicies.ContentRead)) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } var items = Services.ContentService.GetAncestors(id).ToArray(); var total = items.Length; var pages = (total + query.PageSize - 1) / query.PageSize; var paged = items.Skip(ContentControllerHelper.GetSkipSize(query.Page - 1, query.PageSize)).Take(query.PageSize); var mapped = Mapper.Map <IEnumerable <ContentRepresentation> >(paged).ToList(); // this seems stupid since we usually end up in here by request via guid from the other overload... var key = Services.EntityService.GetKeyForId(id, UmbracoObjectTypes.Document); if (key.Result == Guid.Empty) { Request.CreateResponse(HttpStatusCode.NotFound); } var result = new ContentPagedListRepresentation(mapped, total, pages, query.Page, query.PageSize, LinkTemplates.Content.PagedAncestors, new { id = key.Result }); FilterAllowedOutgoingContent(result); return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public Task <HttpResponseMessage> Search( [ModelBinder(typeof(PagedQueryModelBinder))] PagedQuery query) { if (query.Query.IsNullOrWhiteSpace()) { throw new HttpResponseException(HttpStatusCode.NotFound); } //search var result = SearchProvider.Search( SearchProvider.CreateSearchCriteria().RawQuery(query.Query), query.PageSize); //paging var paged = result.Skip(ContentControllerHelper.GetSkipSize(query.Page - 1, query.PageSize)).ToArray(); var pages = (result.TotalItemCount + query.PageSize - 1) / query.PageSize; var foundContent = Enumerable.Empty <IMedia>(); //Map to Imedia if (paged.Any()) { foundContent = Services.MediaService.GetByIds(paged.Select(x => x.Id)).WhereNotNull(); } //Map to representation var items = Mapper.Map <IEnumerable <MediaRepresentation> >(foundContent).ToList(); //return as paged list of media items var representation = new MediaPagedListRepresentation(items, result.TotalItemCount, pages, query.Page - 1, query.PageSize, LinkTemplates.Media.Search, new { query = query.Query, pageSize = query.PageSize }); return(Task.FromResult(Request.CreateResponse(HttpStatusCode.OK, representation))); }
public async Task <HttpResponseMessage> Search( [ModelBinder(typeof(PagedQueryModelBinder))] PagedQuery query) { if (!await AuthorizationService.AuthorizeAsync(ClaimsPrincipal, ContentResourceAccess.Empty(), AuthorizationPolicies.ContentRead)) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } //TODO: Authorize this! how? Same as core, i guess we just filter the results if (query.Query.IsNullOrWhiteSpace()) { throw new HttpResponseException(HttpStatusCode.NotFound); } //Query prepping - ensure that we only search for content items... var contentQuery = "__IndexType:content AND " + query.Query; //search var result = SearchProvider.Search( SearchProvider.CreateSearchCriteria().RawQuery(contentQuery), ContentControllerHelper.GetMaxResults(query.Page, query.PageSize)); //paging var paged = result.Skip(ContentControllerHelper.GetSkipSize(query.Page - 1, query.PageSize)).ToArray(); var pages = (result.TotalItemCount + query.PageSize - 1) / query.PageSize; var foundContent = Enumerable.Empty <IContent>(); //Map to Imedia if (paged.Any()) { foundContent = Services.ContentService.GetByIds(paged.Select(x => x.Id)).WhereNotNull(); } //Map to representation var items = Mapper.Map <IEnumerable <ContentRepresentation> >(foundContent).ToList(); //return as paged list of media items var representation = new ContentPagedListRepresentation(items, result.TotalItemCount, pages, query.Page, query.PageSize, LinkTemplates.Content.Search, new { query = query.Query, pageSize = query.PageSize }); //TODO: Enable this //FilterAllowedOutgoingContent(result); return(Request.CreateResponse(HttpStatusCode.OK, representation)); }
public async Task <HttpResponseMessage> GetAncestors(int id, [ModelBinder(typeof(PagedQueryModelBinder))] PagedRequest query) { if (!await AuthorizationService.AuthorizeAsync(ClaimsPrincipal, new ContentResourceAccess(id), AuthorizationPolicies.MediaRead)) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } var items = Services.MediaService.GetAncestors(id).ToArray(); var total = items.Length; var pages = (total + query.PageSize - 1) / query.PageSize; var paged = items.Skip(ContentControllerHelper.GetSkipSize(query.Page - 1, query.PageSize)).Take(query.PageSize); var mapped = Mapper.Map <IEnumerable <MediaRepresentation> >(paged).ToList(); var result = new MediaPagedListRepresentation(mapped, total, pages, query.Page - 1, query.PageSize, LinkTemplates.Media.PagedAncestors, new { id = id }); return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public HttpResponseMessage Search( [System.Web.Http.ModelBinding.ModelBinder(typeof(PagedQueryModelBinder))] PagedQuery query) { if (query.Query.IsNullOrWhiteSpace()) { throw new HttpResponseException(HttpStatusCode.NotFound); } //TODO: This would be more efficient if we went straight to the ExamineManager and used it's built in Skip method // but then we have to write our own model mappers and don't have time for that right now. var result = Umbraco.ContentQuery.TypedSearch(SearchProvider.CreateSearchCriteria().RawQuery(query.Query), _searchProvider).ToArray(); var paged = result.Skip(ContentControllerHelper.GetSkipSize(query.Page - 1, query.PageSize)).Take(query.PageSize); var items = AutoMapper.Mapper.Map <IEnumerable <PublishedContentRepresentation> >(paged).ToList(); var representation = new PublishedContentPagedListRepresentation(items, result.Length, 1, query.Page - 1, query.PageSize, LinkTemplates.PublishedContent.Search, new { query = query.Query, pageSize = query.PageSize }); return(Request.CreateResponse(HttpStatusCode.OK, representation)); }
private HttpResponseMessage GetAncestorsInternal(Func <IPublishedContent> getContent, PagedQuery query, int depth) { var content = getContent(); if (content == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } PcrFactory.Create(content, Request.RequestUri); var resolved = (string.IsNullOrEmpty(query.Query)) ? content.Ancestors().ToArray() : content.Ancestors(query.Query).ToArray(); var total = resolved.Length; var pages = (total + query.PageSize - 1) / query.PageSize; var items = AutoMapper.Mapper.Map <IEnumerable <PublishedContentRepresentation> >(resolved .Skip(ContentControllerHelper.GetSkipSize(query.Page - 1, query.PageSize)) .Take(query.PageSize), options => options.Items["prop::depth"] = depth).ToList(); var result = new PublishedContentPagedListRepresentation(items, total, pages, query.Page, query.PageSize, LinkTemplates.PublishedContent.PagedAncestors, new { id = content.GetKey() }); return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public HttpResponseMessage GetChildren(int id, [System.Web.Http.ModelBinding.ModelBinder(typeof(PagedQueryModelBinder))] PagedQuery query) { var content = Umbraco.TypedContent(id); if (content == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } PcrFactory.Create(content, Request.RequestUri); var resolved = (string.IsNullOrEmpty(query.Query)) ? content.Children().ToArray() : content.Children(query.Query.Split(',')).ToArray(); var total = resolved.Length; var pages = (total + query.PageSize - 1) / query.PageSize; var items = AutoMapper.Mapper.Map <IEnumerable <PublishedContentRepresentation> >(resolved.Skip(ContentControllerHelper.GetSkipSize(query.Page - 1, query.PageSize)).Take(query.PageSize)).ToList(); var result = new PublishedContentPagedListRepresentation(items, total, pages, query.Page - 1, query.PageSize, LinkTemplates.PublishedContent.PagedChildren, new { id = id }); return(Request.CreateResponse(HttpStatusCode.OK, result)); }