feat(children): generalize CreateChildAsync for any parent + CreatedBy stamp

This commit is contained in:
mika kuns
2026-06-04 15:32:18 +02:00
parent ee0d1257dd
commit 6fdf04d6a0
2 changed files with 3 additions and 4 deletions

View File

@@ -196,6 +196,7 @@ public sealed class TaskRepository
string title,
string? description,
string? commitType,
string? createdBy = null,
CancellationToken ct = default)
{
// AsNoTracking: SetPlanningStartedAsync mutates via ExecuteUpdate which
@@ -204,9 +205,6 @@ public sealed class TaskRepository
.FirstOrDefaultAsync(t => t.Id == parentId, ct);
if (parent is null)
throw new InvalidOperationException($"Parent task {parentId} not found.");
if (parent.PlanningPhase == PlanningPhase.None)
throw new InvalidOperationException(
$"Parent task {parentId} is not in a planning phase; cannot attach children.");
var maxSort = await _context.Tasks
.Where(t => t.ListId == parent.ListId)
@@ -224,6 +222,7 @@ public sealed class TaskRepository
CommitType = string.IsNullOrEmpty(commitType) ? parent.CommitType : commitType,
ParentTaskId = parentId,
SortOrder = (maxSort ?? -1) + 1,
CreatedBy = createdBy,
};
_context.Tasks.Add(child);
await _context.SaveChangesAsync(ct);

View File

@@ -45,7 +45,7 @@ public sealed class PlanningMcpService
CancellationToken cancellationToken)
{
var ctx = _contextAccessor.Current;
var child = await _tasks.CreateChildAsync(ctx.ParentTaskId, title, description, commitType, cancellationToken);
var child = await _tasks.CreateChildAsync(ctx.ParentTaskId, title, description, commitType, createdBy: null, cancellationToken);
await BroadcastTaskUpdatedAsync(child.Id, cancellationToken);
await BroadcastTaskUpdatedAsync(ctx.ParentTaskId, cancellationToken);
return new CreatedChildDto(child.Id, child.Status.ToString());