feat(children): generalize CreateChildAsync for any parent + CreatedBy stamp
This commit is contained in:
@@ -196,6 +196,7 @@ public sealed class TaskRepository
|
|||||||
string title,
|
string title,
|
||||||
string? description,
|
string? description,
|
||||||
string? commitType,
|
string? commitType,
|
||||||
|
string? createdBy = null,
|
||||||
CancellationToken ct = default)
|
CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
// AsNoTracking: SetPlanningStartedAsync mutates via ExecuteUpdate which
|
// AsNoTracking: SetPlanningStartedAsync mutates via ExecuteUpdate which
|
||||||
@@ -204,9 +205,6 @@ public sealed class TaskRepository
|
|||||||
.FirstOrDefaultAsync(t => t.Id == parentId, ct);
|
.FirstOrDefaultAsync(t => t.Id == parentId, ct);
|
||||||
if (parent is null)
|
if (parent is null)
|
||||||
throw new InvalidOperationException($"Parent task {parentId} not found.");
|
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
|
var maxSort = await _context.Tasks
|
||||||
.Where(t => t.ListId == parent.ListId)
|
.Where(t => t.ListId == parent.ListId)
|
||||||
@@ -224,6 +222,7 @@ public sealed class TaskRepository
|
|||||||
CommitType = string.IsNullOrEmpty(commitType) ? parent.CommitType : commitType,
|
CommitType = string.IsNullOrEmpty(commitType) ? parent.CommitType : commitType,
|
||||||
ParentTaskId = parentId,
|
ParentTaskId = parentId,
|
||||||
SortOrder = (maxSort ?? -1) + 1,
|
SortOrder = (maxSort ?? -1) + 1,
|
||||||
|
CreatedBy = createdBy,
|
||||||
};
|
};
|
||||||
_context.Tasks.Add(child);
|
_context.Tasks.Add(child);
|
||||||
await _context.SaveChangesAsync(ct);
|
await _context.SaveChangesAsync(ct);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public sealed class PlanningMcpService
|
|||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var ctx = _contextAccessor.Current;
|
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(child.Id, cancellationToken);
|
||||||
await BroadcastTaskUpdatedAsync(ctx.ParentTaskId, cancellationToken);
|
await BroadcastTaskUpdatedAsync(ctx.ParentTaskId, cancellationToken);
|
||||||
return new CreatedChildDto(child.Id, child.Status.ToString());
|
return new CreatedChildDto(child.Id, child.Status.ToString());
|
||||||
|
|||||||
Reference in New Issue
Block a user