From 00810b3f6d014a9e4b99ff60376a765923890325 Mon Sep 17 00:00:00 2001 From: Alex Prudencio Date: Sun, 24 Nov 2024 20:46:35 -0500 Subject: [PATCH] corregir metodo de getTeamLeadName --- .../repositories/EmployeeRepository.java | 3 +-- .../com/primefactorsolutions/service/EmployeeService.java | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/repositories/EmployeeRepository.java b/src/main/java/com/primefactorsolutions/repositories/EmployeeRepository.java index 90b6919..a72f647 100644 --- a/src/main/java/com/primefactorsolutions/repositories/EmployeeRepository.java +++ b/src/main/java/com/primefactorsolutions/repositories/EmployeeRepository.java @@ -9,8 +9,7 @@ import java.util.UUID; public interface EmployeeRepository extends JpaRepository { Optional findByUsername(String username); - Optional findByPersonalEmail(String personalEmail); - Optional findByTeamId(UUID teamId); + List findAllByTeamId(UUID teamId); List findByTeamName(String teamName); } \ No newline at end of file diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index bb42d32..1f374e8 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -1,4 +1,5 @@ package com.primefactorsolutions.service; +import com.google.common.base.Strings; import com.primefactorsolutions.model.Employee; import jakarta.persistence.EntityManager; import lombok.AllArgsConstructor; @@ -50,7 +51,10 @@ public class EmployeeService { public String getTeamLeadName(final UUID teamId) { // Encuentra al empleado con el rol de lead_manager en el equipo especificado - Optional leadManager = employeeRepository.findByTeamId(teamId); + List teamMembers = employeeRepository.findAllByTeamId(teamId); + Optional leadManager = teamMembers.stream() + .filter(e -> Strings.isNullOrEmpty(e.getLeadManager())) + .findFirst(); return leadManager.map(employee -> employee.getFirstName() + " " + employee.getLastName()) .orElse("No asignado");