| 1 | package edu.ucsb.cs156.frontiers.services; | |
| 2 | ||
| 3 | import com.google.common.collect.Lists; | |
| 4 | import edu.ucsb.cs156.frontiers.entities.Admin; | |
| 5 | import edu.ucsb.cs156.frontiers.entities.Instructor; | |
| 6 | import edu.ucsb.cs156.frontiers.entities.User; | |
| 7 | import edu.ucsb.cs156.frontiers.models.UserDataDTO; | |
| 8 | import edu.ucsb.cs156.frontiers.repositories.AdminRepository; | |
| 9 | import edu.ucsb.cs156.frontiers.repositories.InstructorRepository; | |
| 10 | import edu.ucsb.cs156.frontiers.repositories.UserRepository; | |
| 11 | import java.util.ArrayList; | |
| 12 | import java.util.List; | |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | import org.springframework.data.domain.Page; | |
| 15 | import org.springframework.data.domain.PageImpl; | |
| 16 | import org.springframework.data.domain.Pageable; | |
| 17 | import org.springframework.stereotype.Service; | |
| 18 | ||
| 19 | @Service | |
| 20 | public class UserDataDTOService { | |
| 21 | private final UserRepository userRepository; | |
| 22 | private final AdminRepository adminRepository; | |
| 23 | private final InstructorRepository instructorRepository; | |
| 24 | ||
| 25 | @Autowired | |
| 26 | public UserDataDTOService( | |
| 27 | UserRepository userRepository, | |
| 28 | AdminRepository adminRepository, | |
| 29 | InstructorRepository instructorRepository) { | |
| 30 | this.userRepository = userRepository; | |
| 31 | this.adminRepository = adminRepository; | |
| 32 | this.instructorRepository = instructorRepository; | |
| 33 | } | |
| 34 | ||
| 35 | public Page<UserDataDTO> getUserDataDTOs(Pageable pageable) { | |
| 36 | Page<User> users = userRepository.findAll(pageable); | |
| 37 | List<Admin> admins = Lists.newArrayList(adminRepository.findAll()); | |
| 38 | List<Instructor> instructors = Lists.newArrayList(instructorRepository.findAll()); | |
| 39 | ||
| 40 | List<UserDataDTO> userDTOs = new ArrayList<>(); | |
| 41 | for (User user : users) { | |
| 42 |
2
1. lambda$getUserDataDTOs$0 : replaced boolean return with true for edu/ucsb/cs156/frontiers/services/UserDataDTOService::lambda$getUserDataDTOs$0 → KILLED 2. lambda$getUserDataDTOs$0 : replaced boolean return with false for edu/ucsb/cs156/frontiers/services/UserDataDTOService::lambda$getUserDataDTOs$0 → KILLED |
boolean isAdmin = admins.stream().anyMatch(a -> a.getEmail().equals(user.getEmail())); |
| 43 | boolean isInstructor = | |
| 44 |
2
1. lambda$getUserDataDTOs$1 : replaced boolean return with true for edu/ucsb/cs156/frontiers/services/UserDataDTOService::lambda$getUserDataDTOs$1 → KILLED 2. lambda$getUserDataDTOs$1 : replaced boolean return with false for edu/ucsb/cs156/frontiers/services/UserDataDTOService::lambda$getUserDataDTOs$1 → KILLED |
instructors.stream().anyMatch(i -> i.getEmail().equals(user.getEmail())); |
| 45 | userDTOs.add(UserDataDTO.from(user, isAdmin, isInstructor)); | |
| 46 | } | |
| 47 |
1
1. getUserDataDTOs : replaced return value with null for edu/ucsb/cs156/frontiers/services/UserDataDTOService::getUserDataDTOs → KILLED |
return new PageImpl<UserDataDTO>(userDTOs, pageable, users.getTotalElements()); |
| 48 | } | |
| 49 | } | |
Mutations | ||
| 42 |
1.1 2.2 |
|
| 44 |
1.1 2.2 |
|
| 47 |
1.1 |