using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Services;
namespace Umbraco.Cms.Core;
///
/// Implements .
///
public class TagQuery : ITagQuery
{
private readonly IPublishedContentQuery _contentQuery;
private readonly IUmbracoMapper _mapper;
private readonly ITagService _tagService;
///
/// Initializes a new instance of the class.
///
public TagQuery(ITagService tagService, IPublishedContentQuery contentQuery, IUmbracoMapper mapper)
{
_tagService = tagService ?? throw new ArgumentNullException(nameof(tagService));
_contentQuery = contentQuery ?? throw new ArgumentNullException(nameof(contentQuery));
_mapper = mapper;
}
///
public IEnumerable GetContentByTag(string tag, string? group = null, string? culture = null)
{
IEnumerable ids = _tagService.GetTaggedContentByTag(tag, group, culture)
.Select(x => x.EntityId);
return _contentQuery.Content(ids);
}
///
public IEnumerable GetContentByTagGroup(string group, string? culture = null)
{
IEnumerable ids = _tagService.GetTaggedContentByTagGroup(group, culture)
.Select(x => x.EntityId);
return _contentQuery.Content(ids);
}
///
public IEnumerable GetMediaByTag(string tag, string? group = null, string? culture = null)
{
IEnumerable ids = _tagService.GetTaggedMediaByTag(tag, group, culture)
.Select(x => x.EntityId);
return _contentQuery.Media(ids);
}
///
public IEnumerable GetMediaByTagGroup(string group, string? culture = null)
{
IEnumerable ids = _tagService.GetTaggedMediaByTagGroup(group, culture)
.Select(x => x.EntityId);
return _contentQuery.Media(ids);
}
///
public IEnumerable GetAllTags(string? group = null, string? culture = null) =>
_mapper.MapEnumerable(_tagService.GetAllTags(group, culture));
///
public IEnumerable GetAllContentTags(string? group = null, string? culture = null) =>
_mapper.MapEnumerable(_tagService.GetAllContentTags(group, culture));
///
public IEnumerable GetAllMediaTags(string? group = null, string? culture = null) =>
_mapper.MapEnumerable(_tagService.GetAllMediaTags(group, culture));
///
public IEnumerable GetAllMemberTags(string? group = null, string? culture = null) =>
_mapper.MapEnumerable(_tagService.GetAllMemberTags(group, culture));
///
public IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string? group = null, string? culture = null) =>
_mapper.MapEnumerable(_tagService.GetTagsForProperty(contentId, propertyTypeAlias, group, culture));
///
public IEnumerable GetTagsForEntity(int contentId, string? group = null, string? culture = null) =>
_mapper.MapEnumerable(_tagService.GetTagsForEntity(contentId, group, culture));
}