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;
/// <summary>
/// Implements <see cref="ITagQuery" />.
/// </summary>
public class TagQuery : ITagQuery
{
private readonly IPublishedContentQuery _contentQuery;
private readonly IUmbracoMapper _mapper;
private readonly ITagService _tagService;
/// Initializes a new instance of the <see cref="TagQuery" /> 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;
}
/// <inheritdoc />
public IEnumerable<IPublishedContent> GetContentByTag(string tag, string? group = null, string? culture = null)
IEnumerable<int> ids = _tagService.GetTaggedContentByTag(tag, group, culture)
.Select(x => x.EntityId);
return _contentQuery.Content(ids);
public IEnumerable<IPublishedContent> GetContentByTagGroup(string group, string? culture = null)
IEnumerable<int> ids = _tagService.GetTaggedContentByTagGroup(group, culture)
public IEnumerable<IPublishedContent> GetMediaByTag(string tag, string? group = null, string? culture = null)
IEnumerable<int> ids = _tagService.GetTaggedMediaByTag(tag, group, culture)
return _contentQuery.Media(ids);
public IEnumerable<IPublishedContent> GetMediaByTagGroup(string group, string? culture = null)
IEnumerable<int> ids = _tagService.GetTaggedMediaByTagGroup(group, culture)
public IEnumerable<TagModel?> GetAllTags(string? group = null, string? culture = null) =>
_mapper.MapEnumerable<ITag, TagModel>(_tagService.GetAllTags(group, culture));
public IEnumerable<TagModel?> GetAllContentTags(string? group = null, string? culture = null) =>
_mapper.MapEnumerable<ITag, TagModel>(_tagService.GetAllContentTags(group, culture));
public IEnumerable<TagModel?> GetAllMediaTags(string? group = null, string? culture = null) =>
_mapper.MapEnumerable<ITag, TagModel>(_tagService.GetAllMediaTags(group, culture));
public IEnumerable<TagModel?> GetAllMemberTags(string? group = null, string? culture = null) =>
_mapper.MapEnumerable<ITag, TagModel>(_tagService.GetAllMemberTags(group, culture));
public IEnumerable<TagModel?> GetTagsForProperty(int contentId, string propertyTypeAlias, string? group = null, string? culture = null) =>
_mapper.MapEnumerable<ITag, TagModel>(_tagService.GetTagsForProperty(contentId, propertyTypeAlias, group, culture));
public IEnumerable<TagModel?> GetTagsForEntity(int contentId, string? group = null, string? culture = null) =>
_mapper.MapEnumerable<ITag, TagModel>(_tagService.GetTagsForEntity(contentId, group, culture));