feat(data): add TaskRepository.SetTagsAsync for full tag-set replacement

This commit is contained in:
mika kuns
2026-04-25 11:18:26 +02:00
parent 14cc9fb891
commit 25493528de
2 changed files with 112 additions and 0 deletions

View File

@@ -194,6 +194,27 @@ public sealed class TaskRepository
}
}
public async Task SetTagsAsync(string taskId, IReadOnlyList<string> tagNames, CancellationToken ct = default)
{
var task = await _context.Tasks.Include(t => t.Tags).FirstOrDefaultAsync(t => t.Id == taskId, ct);
if (task is null) return;
task.Tags.Clear();
foreach (var name in tagNames.Where(n => !string.IsNullOrWhiteSpace(n)).Distinct(StringComparer.OrdinalIgnoreCase))
{
var tag = await _context.Tags.FirstOrDefaultAsync(t => t.Name == name, ct);
if (tag is null)
{
tag = new TagEntity { Name = name };
_context.Tags.Add(tag);
}
task.Tags.Add(tag);
}
await _context.SaveChangesAsync(ct);
}
public async Task<List<TagEntity>> GetTagsAsync(string taskId, CancellationToken ct = default)
{
return await _context.Tasks
@@ -276,6 +297,41 @@ public sealed class TaskRepository
return child;
}
public async Task UpdateChildAsync(
string taskId,
string? title,
string? description,
string? commitType,
IReadOnlyList<string>? tagNames,
TaskStatus? status,
CancellationToken ct = default)
{
var task = await _context.Tasks.Include(t => t.Tags).FirstOrDefaultAsync(t => t.Id == taskId, ct)
?? throw new InvalidOperationException($"Task {taskId} not found.");
if (title is not null) task.Title = title;
if (description is not null) task.Description = description;
if (commitType is not null) task.CommitType = commitType;
if (status.HasValue) task.Status = status.Value;
if (tagNames is not null)
{
task.Tags.Clear();
foreach (var name in tagNames.Where(n => !string.IsNullOrWhiteSpace(n)).Distinct(StringComparer.OrdinalIgnoreCase))
{
var tag = await _context.Tags.FirstOrDefaultAsync(t => t.Name == name, ct);
if (tag is null)
{
tag = new TagEntity { Name = name };
_context.Tags.Add(tag);
}
task.Tags.Add(tag);
}
}
await _context.SaveChangesAsync(ct);
}
public async Task UpdatePlanningTaskAsync(
string taskId,
string? title,