Volver a la correcion de getTeamLead
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 2m48s

This commit is contained in:
Melina Gutierrez 2024-11-26 10:34:42 -04:00
parent deb7acc4a4
commit 3fa90b925b
2 changed files with 7 additions and 2 deletions

View File

@ -11,6 +11,6 @@ public interface EmployeeRepository extends JpaRepository<Employee, UUID> {
Optional<Employee> findByUsername(String username); Optional<Employee> findByUsername(String username);
Optional<Employee> findByPersonalEmail(String personalEmail); Optional<Employee> findByPersonalEmail(String personalEmail);
List<Employee> findAllByTeamId(UUID teamId); List<Employee> findAllByTeamId(UUID teamId);
Optional<Employee> findByTeamIdAndLeadManagerTrue(UUID teamId); //Optional<Employee> findByTeamIdAndLeadManagerTrue(UUID teamId);
List<Employee> findByTeamName(String teamName); List<Employee> findByTeamName(String teamName);
} }

View File

@ -1,4 +1,5 @@
package com.primefactorsolutions.service; package com.primefactorsolutions.service;
import com.google.common.base.Strings;
import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.model.Employee;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -49,7 +50,11 @@ public class EmployeeService {
} }
public String getTeamLeadName(final UUID teamId) { public String getTeamLeadName(final UUID teamId) {
Optional<Employee> leadManager = employeeRepository.findByTeamIdAndLeadManagerTrue(teamId); // Encuentra al empleado con el rol de lead_manager en el equipo especificado
List<Employee> teamMembers = employeeRepository.findAllByTeamId(teamId);
Optional<Employee> leadManager = teamMembers.stream()
.filter(e -> Strings.isNullOrEmpty(e.getLeadManager()))
.findFirst();
return leadManager.map(employee -> employee.getFirstName() + " " + employee.getLastName()) return leadManager.map(employee -> employee.getFirstName() + " " + employee.getLastName())
.orElse("No asignado"); .orElse("No asignado");
} }