| 1 | package edu.ucsb.cs156.dining.services; | |
| 2 | ||
| 3 | import com.google.common.collect.Lists; | |
| 4 | import edu.ucsb.cs156.dining.entities.Admin; | |
| 5 | import edu.ucsb.cs156.dining.entities.Moderator; | |
| 6 | import edu.ucsb.cs156.dining.entities.User; | |
| 7 | import edu.ucsb.cs156.dining.models.UserDataDTO; | |
| 8 | import edu.ucsb.cs156.dining.repositories.AdminRepository; | |
| 9 | import edu.ucsb.cs156.dining.repositories.ModeratorRepository; | |
| 10 | import edu.ucsb.cs156.dining.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 ModeratorRepository moderatorRepository; | |
| 24 | ||
| 25 | @Autowired | |
| 26 | public UserDataDTOService( | |
| 27 | UserRepository userRepository, | |
| 28 | AdminRepository adminRepository, | |
| 29 | ModeratorRepository moderatorRepository) { | |
| 30 | this.userRepository = userRepository; | |
| 31 | this.adminRepository = adminRepository; | |
| 32 | this.moderatorRepository = moderatorRepository; | |
| 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<Moderator> moderators = Lists.newArrayList(moderatorRepository.findAll()); | |
| 39 | ||
| 40 | List<UserDataDTO> userDTOs = new ArrayList<>(); | |
| 41 | ||
| 42 | for (User user : users) { | |
| 43 |
2
1. lambda$getUserDataDTOs$0 : replaced boolean return with false for edu/ucsb/cs156/dining/services/UserDataDTOService::lambda$getUserDataDTOs$0 → KILLED 2. lambda$getUserDataDTOs$0 : replaced boolean return with true for edu/ucsb/cs156/dining/services/UserDataDTOService::lambda$getUserDataDTOs$0 → KILLED |
boolean isAdmin = admins.stream().anyMatch(a -> a.getEmail().equals(user.getEmail())); |
| 44 |
2
1. lambda$getUserDataDTOs$1 : replaced boolean return with true for edu/ucsb/cs156/dining/services/UserDataDTOService::lambda$getUserDataDTOs$1 → KILLED 2. lambda$getUserDataDTOs$1 : replaced boolean return with false for edu/ucsb/cs156/dining/services/UserDataDTOService::lambda$getUserDataDTOs$1 → KILLED |
boolean isModerator = moderators.stream().anyMatch(m -> m.getEmail().equals(user.getEmail())); |
| 45 | ||
| 46 | userDTOs.add(UserDataDTO.from(user, isAdmin, isModerator)); | |
| 47 | } | |
| 48 | ||
| 49 |
1
1. getUserDataDTOs : replaced return value with null for edu/ucsb/cs156/dining/services/UserDataDTOService::getUserDataDTOs → KILLED |
return new PageImpl<>(userDTOs, pageable, users.getTotalElements()); |
| 50 | } | |
| 51 | } | |
Mutations | ||
| 43 |
1.1 2.2 |
|
| 44 |
1.1 2.2 |
|
| 49 |
1.1 |