diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-08-17 04:38:03 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2025-08-18 17:03:21 +1000 |
| commit | 5d462af49365e84e0dfd7ed5bd862efb6b325cd1 (patch) | |
| tree | bdb2fbd894916ad0cdb5ce64fa68fdab9d2d8130 /Services | |
| parent | cfa09334407e962f57ba4aca7905265d22424c33 (diff) | |
Added UI to set implicit tags
Diffstat (limited to 'Services')
| -rw-r--r-- | Services/TagService.cs | 26 |
1 files changed, 24 insertions, 2 deletions
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<TagDefinition> GetTagRecursive(IEnumerable<TagDefinition> 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<TagDefinition, bool>(td, !guids.Contains(td.Guid))) + .ToArray(); + } + + public (TagDefinition tagDefinition, bool isImplicit)[] GetAllTags(HBObject obj) => + GetAllTags(obj.Guid); +} |
