From 5d462af49365e84e0dfd7ed5bd862efb6b325cd1 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Thu, 17 Aug 2023 04:38:03 +1000 Subject: Added UI to set implicit tags --- Services/TagService.cs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'Services') diff --git a/Services/TagService.cs b/Services/TagService.cs index e0d1072..da2bb2d 100644 --- a/Services/TagService.cs +++ b/Services/TagService.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; namespace HyperBooru.Services; @@ -12,6 +13,8 @@ public interface ITagService { public void RemoveImplicitTag(TagDefinition tagDef, TagDefinition implicitTagDef); public void CreateTagDefinition(string name, string? @namespace); public void DeleteTagDefinition(TagDefinition tagDef); + public (TagDefinition tagDefinition, bool isImplicit)[] GetAllTags(Guid obj); + public (TagDefinition tagDefinition, bool isImplicit)[] GetAllTags(HBObject obj); } public class TagService : ITagService { @@ -97,4 +100,23 @@ public class TagService : ITagService { transaction.Commit(); } -} \ No newline at end of file + + public (TagDefinition tagDefinition, bool isImplicit)[] GetAllTags(Guid obj) { + IEnumerable GetTagRecursive(IEnumerable tagDefs) => + tagDefs + .Concat(tagDefs.SelectMany(td => GetTagRecursive(td.ImplicitTags))) + .DistinctBy(td => td.Guid); + + using var db = dbFactory.CreateDbContext(); + var @object = db.Objects.First(o => o.Guid == obj); + + var guids = @object.Tags.Select(t => t.TagDefinition.Guid); + + return GetTagRecursive(@object.Tags.Select(t => t.TagDefinition)) + .Select(td => new ValueTuple(td, !guids.Contains(td.Guid))) + .ToArray(); + } + + public (TagDefinition tagDefinition, bool isImplicit)[] GetAllTags(HBObject obj) => + GetAllTags(obj.Guid); +} -- cgit v1.3