---
task_id: task_5
story_id: story_0
sprint_id: sprint_4
status: not_started
type: backend
assignee: backend
created_date: 2025-11-05
completion_date: null
---

# Task 5: Update DTOs and API Endpoints

## What to do

Update StoryDto, TaskDto, and API request/response models to include the new fields. Update API endpoints to accept and return the new fields.

## Files to modify

- `colaflow-api/src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Application/DTOs/StoryDto.cs`
- `colaflow-api/src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Application/DTOs/TaskDto.cs`
- `colaflow-api/src/ColaFlow.API/Controllers/StoriesController.cs`
- `colaflow-api/src/ColaFlow.API/Controllers/TasksController.cs`
- `colaflow-api/src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Application/Commands/CreateStory/CreateStoryCommand.cs`
- `colaflow-api/src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Application/Commands/UpdateStory/UpdateStoryCommand.cs`
- `colaflow-api/src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Application/Commands/CreateTask/CreateTaskCommand.cs`
- `colaflow-api/src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Application/Commands/UpdateTask/UpdateTaskCommand.cs`

## Implementation

### StoryDto.cs

Add properties:
```csharp
public List<string> AcceptanceCriteria { get; init; } = new();
public List<string> Tags { get; init; } = new();
public int? StoryPoints { get; init; }
```

### TaskDto.cs

Add property:
```csharp
public int Order { get; init; }
```

### CreateStoryCommand.cs

Add properties:
```csharp
public List<string> AcceptanceCriteria { get; init; } = new();
public List<string> Tags { get; init; } = new();
public int? StoryPoints { get; init; }
```

Update handler to call new domain methods:
```csharp
if (command.AcceptanceCriteria.Any())
    story.UpdateAcceptanceCriteria(command.AcceptanceCriteria);

if (command.Tags.Any())
    story.UpdateTags(command.Tags);

if (command.StoryPoints.HasValue)
    story.UpdateStoryPoints(command.StoryPoints);
```

### UpdateStoryCommand.cs

Add properties and handler logic (same as CreateStoryCommand).

### CreateTaskCommand.cs

Add property:
```csharp
public int? Order { get; init; }
```

Update handler to set Order:
```csharp
var task = WorkTask.Create(tenantId, command.Title, command.Description, storyId, priority, createdBy);
if (command.Order.HasValue)
    task.UpdateOrder(command.Order.Value);
```

### UpdateTaskCommand.cs

Add property and handler logic (same as CreateTaskCommand).

### StoriesController.cs

Update request models:
```csharp
public record CreateStoryRequest
{
    // Existing fields...
    public List<string> AcceptanceCriteria { get; init; } = new();
    public List<string> Tags { get; init; } = new();
    public int? StoryPoints { get; init; }
}

public record UpdateStoryRequest
{
    // Existing fields...
    public List<string>? AcceptanceCriteria { get; init; }
    public List<string>? Tags { get; init; }
    public int? StoryPoints { get; init; }
}
```

### TasksController.cs

Add bulk reorder endpoint:
```csharp
[HttpPut("stories/{storyId:guid}/tasks/reorder")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> ReorderTasks(
    Guid storyId,
    [FromBody] ReorderTasksRequest request,
    CancellationToken cancellationToken = default)
{
    var command = new ReorderTasksCommand
    {
        StoryId = storyId,
        TaskOrders = request.Tasks
    };

    await _mediator.Send(command, cancellationToken);
    return NoContent();
}

public record ReorderTasksRequest
{
    public List<TaskOrderDto> Tasks { get; init; } = new();
}

public record TaskOrderDto
{
    public Guid TaskId { get; init; }
    public int Order { get; init; }
}
```

Create ReorderTasksCommand and handler in Application layer.

## Acceptance

- [ ] StoryDto includes new fields
- [ ] TaskDto includes Order field
- [ ] CreateStoryCommand accepts new fields
- [ ] UpdateStoryCommand accepts new fields
- [ ] CreateTaskCommand accepts Order field
- [ ] UpdateTaskCommand accepts Order field
- [ ] Command handlers call domain methods
- [ ] ReorderTasks endpoint implemented
- [ ] API compiles successfully
- [ ] Swagger documentation updated
