ajustes que nao lembro mais
This commit is contained in:
parent
4582663fc8
commit
e0a3697e5b
22 changed files with 107 additions and 80 deletions
|
|
@ -13,6 +13,7 @@ public class Task {
|
||||||
private String description;
|
private String description;
|
||||||
private TaskStatus status;
|
private TaskStatus status;
|
||||||
private Project project;
|
private Project project;
|
||||||
|
private User user;
|
||||||
private LocalDateTime finishedAt;
|
private LocalDateTime finishedAt;
|
||||||
private List<TaskHistoryItem> history = new ArrayList<>();
|
private List<TaskHistoryItem> history = new ArrayList<>();
|
||||||
|
|
||||||
|
|
@ -75,6 +76,14 @@ public class Task {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
public List<TaskHistoryItem> getHistory() {
|
public List<TaskHistoryItem> getHistory() {
|
||||||
return history;
|
return history;
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +103,7 @@ public class Task {
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(User user) {
|
public void start() {
|
||||||
TaskHistoryItem current = getCurrentRunningItem();
|
TaskHistoryItem current = getCurrentRunningItem();
|
||||||
|
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
|
|
@ -104,7 +113,6 @@ public class Task {
|
||||||
this.status = TaskStatus.IN_PROGRESS;
|
this.status = TaskStatus.IN_PROGRESS;
|
||||||
TaskHistoryItem item = new TaskHistoryItem();
|
TaskHistoryItem item = new TaskHistoryItem();
|
||||||
item.setStartAt(LocalDateTime.now());
|
item.setStartAt(LocalDateTime.now());
|
||||||
item.setUser(user);
|
|
||||||
this.history.add(item);
|
this.history.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
package net.beetechgroup.beetask.entities.task;
|
package net.beetechgroup.beetask.entities.task;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import net.beetechgroup.beetask.entities.User;
|
|
||||||
|
|
||||||
public class TaskHistoryItem {
|
public class TaskHistoryItem {
|
||||||
private Long id;
|
private Long id;
|
||||||
private LocalDateTime startAt;
|
private LocalDateTime startAt;
|
||||||
private LocalDateTime endAt;
|
private LocalDateTime endAt;
|
||||||
private User user;
|
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
|
|
@ -36,12 +34,4 @@ public class TaskHistoryItem {
|
||||||
public boolean isRunning() {
|
public boolean isRunning() {
|
||||||
return endAt == null;
|
return endAt == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUser(User user) {
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ import net.beetechgroup.beetask.usecase.task.get.GetTaskUseCase;
|
||||||
public class TaskUseCaseConfig {
|
public class TaskUseCaseConfig {
|
||||||
|
|
||||||
@Produces
|
@Produces
|
||||||
public CreateTaskUseCase createTaskUseCase(TaskRepository taskRepository, ProjectRepository projectRepository) {
|
public CreateTaskUseCase createTaskUseCase(TaskRepository taskRepository, ProjectRepository projectRepository, UserRepository userRepository) {
|
||||||
return new CreateTaskUseCase(taskRepository, projectRepository);
|
return new CreateTaskUseCase(taskRepository, projectRepository, userRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Produces
|
@Produces
|
||||||
|
|
@ -42,8 +42,8 @@ public class TaskUseCaseConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Produces
|
@Produces
|
||||||
public UpdateTaskUseCase updateTaskUseCase(TaskRepository taskRepository, ProjectRepository projectRepository) {
|
public UpdateTaskUseCase updateTaskUseCase(TaskRepository taskRepository, ProjectRepository projectRepository, UserRepository userRepository) {
|
||||||
return new UpdateTaskUseCase(taskRepository, projectRepository);
|
return new UpdateTaskUseCase(taskRepository, projectRepository, userRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Produces
|
@Produces
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@ public class TaskEntity {
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "project_id")
|
@JoinColumn(name = "project_id")
|
||||||
private ProjectEntity project;
|
private ProjectEntity project;
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "user_id")
|
||||||
|
private UserEntity user;
|
||||||
@OneToMany(mappedBy = "task", cascade = CascadeType.ALL, orphanRemoval = true)
|
@OneToMany(mappedBy = "task", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
private List<TaskHistoryItemEntity> history;
|
private List<TaskHistoryItemEntity> history;
|
||||||
|
|
||||||
|
|
@ -88,4 +91,11 @@ public class TaskEntity {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserEntity getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(UserEntity user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,6 @@ public class TaskHistoryItemEntity {
|
||||||
private LocalDateTime startAt;
|
private LocalDateTime startAt;
|
||||||
private LocalDateTime endAt;
|
private LocalDateTime endAt;
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "user_id")
|
|
||||||
private UserEntity user;
|
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "task_id")
|
@JoinColumn(name = "task_id")
|
||||||
private TaskEntity task;
|
private TaskEntity task;
|
||||||
|
|
@ -52,14 +48,6 @@ public class TaskHistoryItemEntity {
|
||||||
this.endAt = endAt;
|
this.endAt = endAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserEntity getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUser(UserEntity user) {
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TaskEntity getTask() {
|
public TaskEntity getTask() {
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users")
|
@Table(name = "users_entity")
|
||||||
public class UserEntity {
|
public class UserEntity {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ public class TaskEntityMapper {
|
||||||
entity.setStatus(task.getStatus());
|
entity.setStatus(task.getStatus());
|
||||||
entity.setFinishedAt(task.getFinishedAt());
|
entity.setFinishedAt(task.getFinishedAt());
|
||||||
entity.setProject(ProjectEntityMapper.toEntity(task.getProject()));
|
entity.setProject(ProjectEntityMapper.toEntity(task.getProject()));
|
||||||
|
entity.setUser(UserEntityMapper.toEntity(task.getUser()));
|
||||||
entity.setHistory(new ArrayList<>(task.getHistory().stream().map(h -> {
|
entity.setHistory(new ArrayList<>(task.getHistory().stream().map(h -> {
|
||||||
TaskHistoryItemEntity he = TaskHistoryItemMapper.toEntity(h);
|
TaskHistoryItemEntity he = TaskHistoryItemMapper.toEntity(h);
|
||||||
he.setTask(entity);
|
he.setTask(entity);
|
||||||
|
|
@ -34,6 +35,7 @@ public class TaskEntityMapper {
|
||||||
task.setStatus(entity.getStatus());
|
task.setStatus(entity.getStatus());
|
||||||
task.setFinishedAt(entity.getFinishedAt());
|
task.setFinishedAt(entity.getFinishedAt());
|
||||||
task.setProject(ProjectEntityMapper.toDomain(entity.getProject()));
|
task.setProject(ProjectEntityMapper.toDomain(entity.getProject()));
|
||||||
|
task.setUser(UserEntityMapper.toDomain(entity.getUser()));
|
||||||
task.setHistory(new ArrayList<>(entity.getHistory().stream().map(TaskHistoryItemMapper::toDomain).toList()));
|
task.setHistory(new ArrayList<>(entity.getHistory().stream().map(TaskHistoryItemMapper::toDomain).toList()));
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,6 @@ public class TaskHistoryItemMapper {
|
||||||
entity.setId(item.getId());
|
entity.setId(item.getId());
|
||||||
entity.setStartAt(item.getStartAt());
|
entity.setStartAt(item.getStartAt());
|
||||||
entity.setEndAt(item.getEndAt());
|
entity.setEndAt(item.getEndAt());
|
||||||
if (item.getUser() != null) {
|
|
||||||
entity.setUser(UserEntityMapper.toEntity(item.getUser()));
|
|
||||||
}
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,9 +19,6 @@ public class TaskHistoryItemMapper {
|
||||||
item.setId(entity.getId());
|
item.setId(entity.getId());
|
||||||
item.setStartAt(entity.getStartAt());
|
item.setStartAt(entity.getStartAt());
|
||||||
item.setEndAt(entity.getEndAt());
|
item.setEndAt(entity.getEndAt());
|
||||||
if (entity.getUser() != null) {
|
|
||||||
item.setUser(UserEntityMapper.toDomain(entity.getUser()));
|
|
||||||
}
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -41,13 +41,16 @@ public class TaskRepositoryImpl implements TaskRepository, PanacheRepository<Tas
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Task> findTasksWorkedByUserInPeriod(String email, LocalDateTime start, LocalDateTime end) {
|
public List<Task> findTasksWorkedByUserInPeriod(String email, LocalDateTime start, LocalDateTime end) {
|
||||||
return find("select distinct t from TaskEntity t join t.history h where h.user.email = ?1 and h.startAt >= ?2 and h.startAt <= ?3",
|
return find("select distinct t from TaskEntity t join t.history h where t.user.email = ?1 " +
|
||||||
|
"and h.startAt <= ?3 and (h.endAt is null or h.endAt >= ?2)",
|
||||||
email, start, end).list().stream().map(TaskEntityMapper::toDomain).toList();
|
email, start, end).list().stream().map(TaskEntityMapper::toDomain).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Task> findTasksFinishedByUserInPeriod(String email, LocalDateTime start, LocalDateTime end) {
|
public List<Task> findTasksFinishedByUserInPeriod(String email, LocalDateTime start, LocalDateTime end) {
|
||||||
return find("select distinct t from TaskEntity t join t.history h where h.user.email = ?1 and t.finishedAt >= ?2 and t.finishedAt <= ?3",
|
return find("select distinct t from TaskEntity t where t.user.email = ?1 " +
|
||||||
|
"and t.status = net.beetechgroup.beetask.entities.task.TaskStatus.COMPLETED " +
|
||||||
|
"and t.finishedAt >= ?2 and t.finishedAt <= ?3",
|
||||||
email, start, end).list().stream().map(TaskEntityMapper::toDomain).toList();
|
email, start, end).list().stream().map(TaskEntityMapper::toDomain).toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -41,6 +41,10 @@ public class DashboardController {
|
||||||
? LocalDateTime.parse(endDateStr, DateTimeFormatter.ISO_DATE_TIME)
|
? LocalDateTime.parse(endDateStr, DateTimeFormatter.ISO_DATE_TIME)
|
||||||
: LocalDateTime.now();
|
: LocalDateTime.now();
|
||||||
|
|
||||||
|
if (endDateStr != null && end.toLocalTime().equals(java.time.LocalTime.MIDNIGHT)) {
|
||||||
|
end = end.with(java.time.LocalTime.MAX);
|
||||||
|
}
|
||||||
|
|
||||||
DashboardInput input = new DashboardInput(email, start, end);
|
DashboardInput input = new DashboardInput(email, start, end);
|
||||||
return dashboardUseCase.execute(input);
|
return dashboardUseCase.execute(input);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,8 @@ public class TaskController {
|
||||||
@Operation(summary = "Create a new task", description = "Creates a new task in the system")
|
@Operation(summary = "Create a new task", description = "Creates a new task in the system")
|
||||||
@APIResponse(responseCode = "201", description = "Task created successfully")
|
@APIResponse(responseCode = "201", description = "Task created successfully")
|
||||||
public CreateTaskResponse createTask(CreateTaskRequest request) {
|
public CreateTaskResponse createTask(CreateTaskRequest request) {
|
||||||
CreateTaskInput input = TaskControllerMapper.toCreateTaskInput(request);
|
String email = securityIdentity.getPrincipal().getName();
|
||||||
|
CreateTaskInput input = TaskControllerMapper.toCreateTaskInput(request, email);
|
||||||
CreateTaskOutput output = createTaskUseCase.execute(input);
|
CreateTaskOutput output = createTaskUseCase.execute(input);
|
||||||
return TaskControllerMapper.toCreateTaskResponse(output);
|
return TaskControllerMapper.toCreateTaskResponse(output);
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +75,8 @@ public class TaskController {
|
||||||
@Operation(summary = "Update a task", description = "Updates an existing task in the system")
|
@Operation(summary = "Update a task", description = "Updates an existing task in the system")
|
||||||
@APIResponse(responseCode = "200", description = "Task updated successfully")
|
@APIResponse(responseCode = "200", description = "Task updated successfully")
|
||||||
public CreateTaskResponse updateTask(@PathParam("id") Long id, CreateTaskRequest request) {
|
public CreateTaskResponse updateTask(@PathParam("id") Long id, CreateTaskRequest request) {
|
||||||
CreateTaskOutput output = updateTaskUseCase.execute(TaskControllerMapper.toUpdateTaskInput(id, request));
|
String email = securityIdentity.getPrincipal().getName();
|
||||||
|
CreateTaskOutput output = updateTaskUseCase.execute(TaskControllerMapper.toUpdateTaskInput(id, request, email));
|
||||||
return TaskControllerMapper.toCreateTaskResponse(output);
|
return TaskControllerMapper.toCreateTaskResponse(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,13 @@ import net.beetechgroup.beetask.usecase.task.update.UpdateTaskInput;
|
||||||
|
|
||||||
public class TaskControllerMapper {
|
public class TaskControllerMapper {
|
||||||
|
|
||||||
public static CreateTaskInput toCreateTaskInput(CreateTaskRequest request) {
|
public static CreateTaskInput toCreateTaskInput(CreateTaskRequest request, String userEmail) {
|
||||||
return new CreateTaskInput(
|
return new CreateTaskInput(
|
||||||
request.title(),
|
request.title(),
|
||||||
request.description(),
|
request.description(),
|
||||||
request.status(),
|
request.status(),
|
||||||
request.projectId()
|
request.projectId(),
|
||||||
|
userEmail
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,13 +39,14 @@ public class TaskControllerMapper {
|
||||||
return new StopTaskInput(id);
|
return new StopTaskInput(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UpdateTaskInput toUpdateTaskInput(Long id, CreateTaskRequest request) {
|
public static UpdateTaskInput toUpdateTaskInput(Long id, CreateTaskRequest request, String userEmail) {
|
||||||
return new UpdateTaskInput(
|
return new UpdateTaskInput(
|
||||||
id,
|
id,
|
||||||
request.title(),
|
request.title(),
|
||||||
request.description(),
|
request.description(),
|
||||||
request.status(),
|
request.status(),
|
||||||
request.projectId(),
|
request.projectId(),
|
||||||
|
userEmail,
|
||||||
request.history() != null ? request.history().stream()
|
request.history() != null ? request.history().stream()
|
||||||
.map(h -> new TaskHistoryItemInput(h.id(), h.startAt(), h.endAt()))
|
.map(h -> new TaskHistoryItemInput(h.id(), h.startAt(), h.endAt()))
|
||||||
.toList() : null
|
.toList() : null
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ public class LoginUseCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoginOutput execute(LoginInput input) {
|
public LoginOutput execute(LoginInput input) {
|
||||||
System.out.println(input.email() + " " + input.password());
|
|
||||||
Optional<User> userOptional = userRepository.findByEmail(input.email());
|
Optional<User> userOptional = userRepository.findByEmail(input.email());
|
||||||
|
|
||||||
if (userOptional.isEmpty()) {
|
if (userOptional.isEmpty()) {
|
||||||
|
|
@ -50,14 +49,17 @@ public class LoginUseCase {
|
||||||
.sign();
|
.sign();
|
||||||
|
|
||||||
List<LoginOutput.OrganizationOutput> orgs = userOrganizations.stream()
|
List<LoginOutput.OrganizationOutput> orgs = userOrganizations.stream()
|
||||||
.collect(Collectors.groupingBy(uo -> uo.getOrganization().getName()))
|
.collect(Collectors.groupingBy(uo -> uo.getOrganization().getId()))
|
||||||
.entrySet().stream()
|
.entrySet().stream()
|
||||||
.map(entry -> new LoginOutput.OrganizationOutput(
|
.map(entry -> {
|
||||||
entry.getValue().stream().map(uo -> uo.getOrganization().getId()).findFirst().orElse(null),
|
UserOrganization first = entry.getValue().get(0);
|
||||||
|
return new LoginOutput.OrganizationOutput(
|
||||||
entry.getKey(),
|
entry.getKey(),
|
||||||
entry.getValue().stream().map(uo -> uo.getRole().name()).collect(Collectors.toList())
|
first.getOrganization().getName(),
|
||||||
))
|
entry.getValue().stream().map(uo -> uo.getRole().name()).toList()
|
||||||
.collect(Collectors.toList());
|
);
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
|
||||||
String refreshToken = Jwt.issuer(this.issuer)
|
String refreshToken = Jwt.issuer(this.issuer)
|
||||||
.upn(user.getEmail())
|
.upn(user.getEmail())
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,17 @@ public class RefreshTokenUseCase {
|
||||||
.sign();
|
.sign();
|
||||||
|
|
||||||
List<LoginOutput.OrganizationOutput> orgs = userOrganizations.stream()
|
List<LoginOutput.OrganizationOutput> orgs = userOrganizations.stream()
|
||||||
.collect(Collectors.groupingBy(uo -> uo.getOrganization().getName()))
|
.collect(Collectors.groupingBy(uo -> uo.getOrganization().getId()))
|
||||||
.entrySet().stream()
|
.entrySet().stream()
|
||||||
.map(entry -> new LoginOutput.OrganizationOutput(
|
.map(entry -> {
|
||||||
|
UserOrganization first = entry.getValue().get(0);
|
||||||
|
return new LoginOutput.OrganizationOutput(
|
||||||
entry.getKey(),
|
entry.getKey(),
|
||||||
entry.getValue().stream().map(uo -> uo.getRole().name()).collect(Collectors.toList())
|
first.getOrganization().getName(),
|
||||||
))
|
entry.getValue().stream().map(uo -> uo.getRole().name()).toList()
|
||||||
.collect(Collectors.toList());
|
);
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
|
||||||
return new LoginOutput(
|
return new LoginOutput(
|
||||||
user.getName(),
|
user.getName(),
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ public class DashboardUseCase {
|
||||||
|
|
||||||
for (Task task : workedTasks) {
|
for (Task task : workedTasks) {
|
||||||
long taskMinutesInPeriod = task.getHistory().stream()
|
long taskMinutesInPeriod = task.getHistory().stream()
|
||||||
.filter(h -> h.getUser() != null && h.getUser().getEmail().equals(input.userEmail()))
|
|
||||||
.filter(h -> isWithinPeriod(h, input.startDate(), input.endDate()))
|
.filter(h -> isWithinPeriod(h, input.startDate(), input.endDate()))
|
||||||
.mapToLong(h -> calculateMinutesInRange(h, input.startDate(), input.endDate()))
|
.mapToLong(h -> calculateMinutesInRange(h, input.startDate(), input.endDate()))
|
||||||
.sum();
|
.sum();
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,6 @@ public record CreateTaskInput(
|
||||||
String title,
|
String title,
|
||||||
String description,
|
String description,
|
||||||
TaskStatus status,
|
TaskStatus status,
|
||||||
Long projectId) {
|
Long projectId,
|
||||||
|
String userEmail) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,17 @@ import net.beetechgroup.beetask.entities.Project;
|
||||||
import net.beetechgroup.beetask.entities.task.Task;
|
import net.beetechgroup.beetask.entities.task.Task;
|
||||||
import net.beetechgroup.beetask.usecase.repository.ProjectRepository;
|
import net.beetechgroup.beetask.usecase.repository.ProjectRepository;
|
||||||
import net.beetechgroup.beetask.usecase.repository.TaskRepository;
|
import net.beetechgroup.beetask.usecase.repository.TaskRepository;
|
||||||
|
import net.beetechgroup.beetask.usecase.repository.UserRepository;
|
||||||
|
|
||||||
public class CreateTaskUseCase {
|
public class CreateTaskUseCase {
|
||||||
private final TaskRepository taskRepository;
|
private final TaskRepository taskRepository;
|
||||||
private final ProjectRepository projectRepository;
|
private final ProjectRepository projectRepository;
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
public CreateTaskUseCase(TaskRepository taskRepository, ProjectRepository projectRepository) {
|
public CreateTaskUseCase(TaskRepository taskRepository, ProjectRepository projectRepository, UserRepository userRepository) {
|
||||||
this.taskRepository = taskRepository;
|
this.taskRepository = taskRepository;
|
||||||
this.projectRepository = projectRepository;
|
this.projectRepository = projectRepository;
|
||||||
|
this.userRepository = userRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CreateTaskOutput execute(CreateTaskInput input) {
|
public CreateTaskOutput execute(CreateTaskInput input) {
|
||||||
|
|
@ -26,6 +29,9 @@ public class CreateTaskUseCase {
|
||||||
task.setProject(project);
|
task.setProject(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task.setUser(userRepository.findByEmail(input.userEmail())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("Usuário não encontrado: " + input.userEmail())));
|
||||||
|
|
||||||
return CreateTaskMapper.toCreateTaskOutput(taskRepository.saveTask(task));
|
return CreateTaskMapper.toCreateTaskOutput(taskRepository.saveTask(task));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,12 @@ public class StartTaskUseCase {
|
||||||
|
|
||||||
public CreateTaskOutput execute(StartTaskInput input) {
|
public CreateTaskOutput execute(StartTaskInput input) {
|
||||||
Task task = taskRepository.findTaskById(input.id());
|
Task task = taskRepository.findTaskById(input.id());
|
||||||
User user = userRepository.findByEmail(input.userEmail())
|
|
||||||
.orElseThrow(() -> new UserNotFoundException(input.userEmail()));
|
if (task.getUser() != null && !task.getUser().getEmail().equals(input.userEmail())) {
|
||||||
task.start(user);
|
throw new SecurityException("Você não tem permissão para iniciar esta tarefa.");
|
||||||
|
}
|
||||||
|
|
||||||
|
task.start();
|
||||||
return CreateTaskMapper.toCreateTaskOutput(taskRepository.saveTask(task));
|
return CreateTaskMapper.toCreateTaskOutput(taskRepository.saveTask(task));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,6 @@ public record UpdateTaskInput(
|
||||||
String description,
|
String description,
|
||||||
TaskStatus status,
|
TaskStatus status,
|
||||||
Long projectId,
|
Long projectId,
|
||||||
|
String userEmail,
|
||||||
List<TaskHistoryItemInput> history) {
|
List<TaskHistoryItemInput> history) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,22 +6,29 @@ import net.beetechgroup.beetask.entities.task.Task;
|
||||||
import net.beetechgroup.beetask.entities.task.TaskHistoryItem;
|
import net.beetechgroup.beetask.entities.task.TaskHistoryItem;
|
||||||
import net.beetechgroup.beetask.usecase.repository.ProjectRepository;
|
import net.beetechgroup.beetask.usecase.repository.ProjectRepository;
|
||||||
import net.beetechgroup.beetask.usecase.repository.TaskRepository;
|
import net.beetechgroup.beetask.usecase.repository.TaskRepository;
|
||||||
|
import net.beetechgroup.beetask.usecase.repository.UserRepository;
|
||||||
import net.beetechgroup.beetask.usecase.task.create.CreateTaskMapper;
|
import net.beetechgroup.beetask.usecase.task.create.CreateTaskMapper;
|
||||||
import net.beetechgroup.beetask.usecase.task.create.CreateTaskOutput;
|
import net.beetechgroup.beetask.usecase.task.create.CreateTaskOutput;
|
||||||
|
|
||||||
public class UpdateTaskUseCase {
|
public class UpdateTaskUseCase {
|
||||||
private final TaskRepository taskRepository;
|
private final TaskRepository taskRepository;
|
||||||
private final ProjectRepository projectRepository;
|
private final ProjectRepository projectRepository;
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
public UpdateTaskUseCase(TaskRepository taskRepository, ProjectRepository projectRepository) {
|
public UpdateTaskUseCase(TaskRepository taskRepository, ProjectRepository projectRepository, UserRepository userRepository) {
|
||||||
this.taskRepository = taskRepository;
|
this.taskRepository = taskRepository;
|
||||||
this.projectRepository = projectRepository;
|
this.projectRepository = projectRepository;
|
||||||
|
this.userRepository = userRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CreateTaskOutput execute(UpdateTaskInput input) {
|
public CreateTaskOutput execute(UpdateTaskInput input) {
|
||||||
//TODO deve validar se o usuario logado é o dono da task
|
|
||||||
Task task = taskRepository.findTaskById(input.id());
|
Task task = taskRepository.findTaskById(input.id());
|
||||||
|
|
||||||
|
if (task.getUser() == null) {
|
||||||
|
task.setUser(userRepository.findByEmail(input.userEmail())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("Usuário não encontrado: " + input.userEmail())));
|
||||||
|
}
|
||||||
|
|
||||||
task.setTitle(input.title());
|
task.setTitle(input.title());
|
||||||
task.setDescription(input.description());
|
task.setDescription(input.description());
|
||||||
task.setStatus(input.status());
|
task.setStatus(input.status());
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import {
|
||||||
Send,
|
Send,
|
||||||
XCircle,
|
XCircle,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
import { format } from "date-fns";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import type { ChangeEvent, FormEvent } from "react";
|
import type { ChangeEvent, FormEvent } from "react";
|
||||||
import { Link, useNavigate, useParams } from "react-router-dom";
|
import { Link, useNavigate, useParams } from "react-router-dom";
|
||||||
|
|
@ -302,7 +303,7 @@ export function CreateTaskPage() {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setForm(prev => ({
|
setForm(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
history: [...prev.history, { startAt: new Date().toISOString(), endAt: null }]
|
history: [...prev.history, { startAt: format(new Date(), "yyyy-MM-dd'T'HH:mm:ss"), endAt: null }]
|
||||||
}))
|
}))
|
||||||
}}
|
}}
|
||||||
className="text-xs font-bold text-brand hover:underline"
|
className="text-xs font-bold text-brand hover:underline"
|
||||||
|
|
@ -321,7 +322,7 @@ export function CreateTaskPage() {
|
||||||
value={item.startAt ? item.startAt.slice(0, 16) : ""}
|
value={item.startAt ? item.startAt.slice(0, 16) : ""}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const newHistory = [...form.history];
|
const newHistory = [...form.history];
|
||||||
newHistory[index] = { ...item, startAt: new Date(e.target.value).toISOString() };
|
newHistory[index] = { ...item, startAt: e.target.value };
|
||||||
setForm(prev => ({ ...prev, history: newHistory }));
|
setForm(prev => ({ ...prev, history: newHistory }));
|
||||||
}}
|
}}
|
||||||
className="w-full rounded-lg border border-border-soft bg-surface px-3 py-2 text-xs outline-none focus:border-brand"
|
className="w-full rounded-lg border border-border-soft bg-surface px-3 py-2 text-xs outline-none focus:border-brand"
|
||||||
|
|
@ -334,7 +335,7 @@ export function CreateTaskPage() {
|
||||||
value={item.endAt ? item.endAt.slice(0, 16) : ""}
|
value={item.endAt ? item.endAt.slice(0, 16) : ""}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const newHistory = [...form.history];
|
const newHistory = [...form.history];
|
||||||
newHistory[index] = { ...item, endAt: e.target.value ? new Date(e.target.value).toISOString() : null };
|
newHistory[index] = { ...item, endAt: e.target.value || null };
|
||||||
setForm(prev => ({ ...prev, history: newHistory }));
|
setForm(prev => ({ ...prev, history: newHistory }));
|
||||||
}}
|
}}
|
||||||
className="w-full rounded-lg border border-border-soft bg-surface px-3 py-2 text-xs outline-none focus:border-brand"
|
className="w-full rounded-lg border border-border-soft bg-surface px-3 py-2 text-xs outline-none focus:border-brand"
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ export const DashboardPage: React.FC = () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
const result = await dashboardService.getDashboard(
|
const result = await dashboardService.getDashboard(
|
||||||
startDate.toISOString(),
|
format(startDate, "yyyy-MM-dd'T'HH:mm:ss"),
|
||||||
endDate.toISOString(),
|
format(endDate, "yyyy-MM-dd'T'HH:mm:ss"),
|
||||||
);
|
);
|
||||||
setData(result);
|
setData(result);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -80,7 +80,7 @@ export const DashboardPage: React.FC = () => {
|
||||||
<input
|
<input
|
||||||
type="date"
|
type="date"
|
||||||
value={format(startDate, "yyyy-MM-dd")}
|
value={format(startDate, "yyyy-MM-dd")}
|
||||||
onChange={(e) => setStartDate(new Date(e.target.value))}
|
onChange={(e) => setStartDate(new Date(e.target.value + 'T00:00:00'))}
|
||||||
className="bg-transparent border-none text-sm font-bold text-text-main focus:ring-0 outline-none"
|
className="bg-transparent border-none text-sm font-bold text-text-main focus:ring-0 outline-none"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -88,7 +88,7 @@ export const DashboardPage: React.FC = () => {
|
||||||
<input
|
<input
|
||||||
type="date"
|
type="date"
|
||||||
value={format(endDate, "yyyy-MM-dd")}
|
value={format(endDate, "yyyy-MM-dd")}
|
||||||
onChange={(e) => setEndDate(new Date(e.target.value))}
|
onChange={(e) => setEndDate(new Date(e.target.value + 'T23:59:59'))}
|
||||||
className="bg-transparent border-none text-sm font-bold text-text-main focus:ring-0 outline-none"
|
className="bg-transparent border-none text-sm font-bold text-text-main focus:ring-0 outline-none"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue