fix: salvar histórico ao criar task
Propagava o campo history do CreateTaskRequest até o use case e persistência. O mapeamento em TaskControllerMapper ignorava o history; CreateTaskInput não tinha o campo; e CreateTaskUseCase não aplicava os itens à entidade antes de salvar. Closes #22 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0ff655bf8b
commit
345a41cf13
4 changed files with 21 additions and 3 deletions
|
|
@ -9,5 +9,5 @@ public record CreateTaskRequest(
|
|||
String description,
|
||||
TaskStatus status,
|
||||
Long projectId,
|
||||
List<TaskHistoryItemResponse> history) {
|
||||
List<TaskHistoryItemResponse> history) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,10 @@ public class TaskControllerMapper {
|
|||
request.description(),
|
||||
request.status(),
|
||||
request.projectId(),
|
||||
userEmail
|
||||
userEmail,
|
||||
Objects.nonNull(request.history()) ? request.history().stream()
|
||||
.map(h -> new TaskHistoryItemInput(h.id(), h.startAt(), h.endAt()))
|
||||
.toList() : null
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
package net.beetechgroup.beetask.usecase.task.create;
|
||||
|
||||
import java.util.List;
|
||||
import net.beetechgroup.beetask.entities.task.TaskStatus;
|
||||
import net.beetechgroup.beetask.usecase.task.update.TaskHistoryItemInput;
|
||||
|
||||
public record CreateTaskInput(
|
||||
String title,
|
||||
String description,
|
||||
TaskStatus status,
|
||||
Long projectId,
|
||||
String userEmail) {
|
||||
String userEmail,
|
||||
List<TaskHistoryItemInput> history) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package net.beetechgroup.beetask.usecase.task.create;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import net.beetechgroup.beetask.entities.Project;
|
||||
import net.beetechgroup.beetask.entities.task.Task;
|
||||
import net.beetechgroup.beetask.entities.task.TaskHistoryItem;
|
||||
import net.beetechgroup.beetask.usecase.repository.ProjectRepository;
|
||||
import net.beetechgroup.beetask.usecase.repository.TaskRepository;
|
||||
import net.beetechgroup.beetask.usecase.repository.UserRepository;
|
||||
|
|
@ -42,6 +44,16 @@ public class CreateTaskUseCase {
|
|||
return new IllegalArgumentException("Usuário não encontrado: " + input.userEmail());
|
||||
}));
|
||||
|
||||
if (Objects.nonNull(input.history())) {
|
||||
List<TaskHistoryItem> historyItems = input.history().stream().map(h -> {
|
||||
TaskHistoryItem item = new TaskHistoryItem();
|
||||
item.setStartAt(h.startAt());
|
||||
item.setEndAt(h.endAt());
|
||||
return item;
|
||||
}).toList();
|
||||
task.getHistory().addAll(historyItems);
|
||||
}
|
||||
|
||||
CreateTaskOutput output = CreateTaskMapper.toCreateTaskOutput(taskRepository.saveTask(task));
|
||||
LOGGER.infof("Task %d created for user %s", output.id(), input.userEmail());
|
||||
return output;
|
||||
|
|
|
|||
Loading…
Reference in a new issue