diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-08-17 04:38:03 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2023-08-17 04:38:03 +1000 |
| commit | 6a6514df8b5f40cad4f5afb284bdd199f0e8f450 (patch) | |
| tree | a05d2a202f4a204faa7d92ae91f65867d4d61ad1 /Services | |
| parent | 596f79318b41b7da60da0f82794f56f306842973 (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); +} |
