Changeset 14b648e for src/main/java/it/finki/tinki/service/impl
- Timestamp:
- 01/08/21 20:46:33 (4 years ago)
- Branches:
- master
- Children:
- bd38a55
- Parents:
- 31fc5c8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/it/finki/tinki/service/impl/AccountServiceImpl.java
r31fc5c8 r14b648e 19 19 20 20 import java.util.List; 21 import java.util.Optional; 21 22 22 23 @Service … … 81 82 User ru = this.userRepository.save(u); 82 83 83 List<Job> jobs = this.jobRepository.findAll(); 84 List<Project> projects = this.projectRepository.findAll(); 85 List<Internship> internships = this.internshipRepository.findAll(); 86 87 if(jobs.size()!=0){ 88 for (Job job : jobs) { 89 this.matchmakerService.setUpUserJobMatches(job, u); 90 } 91 } 92 93 if(projects.size()!=0){ 94 for (Project project : projects) { 95 this.matchmakerService.setUpUserProjectMatches(project, u); 96 } 97 } 98 99 if(internships.size()!=0){ 100 for(Internship internship : internships){ 101 this.matchmakerService.setUpUserInternshipMatches(internship, u); 102 } 103 } 84 setUpUser(ru); 104 85 105 86 return ru; … … 147 128 return null; 148 129 } 130 131 public Optional<?> findByIdAndEmail(Long id, String email, AccountType accountType){ 132 133 switch (accountType){ 134 case USER: 135 return this.userRepository.findByIdAndEmail(id, email); 136 case TEAM: 137 return this.teamRepository.findByIdAndEmail(id, email); 138 case COMPANY: 139 return this.companyRepository.findByIdAndEmail(id, email); 140 } 141 142 return Optional.empty(); 143 } 144 145 public User editUser(Long id, String email, String name, String surname, List<Skill> retainedSkills, List<Skill> skillsToLearn){ 146 if(email==null || email.isEmpty() || name==null || name.isEmpty() || surname==null || surname.isEmpty()){ 147 throw new InvalidArgumentsException(); 148 } 149 150 User u = this.userRepository.findById(id).get(); 151 Optional<User> t = this.userRepository.findByEmail(email); 152 153 if(t.isPresent() && !t.get().equals(u)){ 154 throw new UserExistsException(); 155 } 156 157 u.setEmail(email); 158 u.setName(name); 159 u.setSurname(surname); 160 u.setRetainedSkills(retainedSkills); 161 u.setSkillsToLearn(skillsToLearn); 162 163 User m = this.userRepository.save(u); 164 165 setUpUser(m); 166 167 return m; 168 } 169 170 public Company editCompany(Long id, String email, String name, String country, String city, String street){ 171 if(email==null || email.isEmpty() || name==null || name.isEmpty() 172 || country==null || country.isEmpty() || city==null || city.isEmpty() || street==null || street.isEmpty()){ 173 throw new InvalidArgumentsException(); 174 } 175 176 Company c = this.companyRepository.findById(id).get(); 177 Optional<Company> t = this.companyRepository.findByEmail(email); 178 179 if(t.isPresent() && !t.get().equals(c)){ 180 throw new UserExistsException(); 181 } 182 183 c.setEmail(email); 184 c.setName(name); 185 186 Address ad = c.getAddress(); 187 ad.setCountry(country); 188 ad.setCity(city); 189 ad.setStreet(street); 190 191 this.addressRepository.save(ad); 192 return this.companyRepository.save(c); 193 } 194 195 public Team editTeam(Long id, String email, String name, int members){ 196 if(email==null || email.isEmpty() || name==null || name.isEmpty()){ 197 throw new InvalidArgumentsException(); 198 } 199 200 Team t = this.teamRepository.findById(id).get(); 201 Optional<Team> tt = this.teamRepository.findByEmail(email); 202 203 if(tt.isPresent() && !tt.get().equals(t)){ 204 throw new UserExistsException(); 205 } 206 207 t.setEmail(email); 208 t.setName(name); 209 t.setMembers(members); 210 211 return this.teamRepository.save(t); 212 } 213 214 215 private void setUpUser(User u){ 216 List<Job> jobs = this.jobRepository.findAll(); 217 List<Project> projects = this.projectRepository.findAll(); 218 List<Internship> internships = this.internshipRepository.findAll(); 219 220 if(jobs.size()!=0){ 221 for (Job job : jobs) { 222 this.matchmakerService.setUpUserJobMatches(job, u); 223 } 224 } 225 226 if(projects.size()!=0){ 227 for (Project project : projects) { 228 this.matchmakerService.setUpUserProjectMatches(project, u); 229 } 230 } 231 232 if(internships.size()!=0){ 233 for(Internship internship : internships){ 234 this.matchmakerService.setUpUserInternshipMatches(internship, u); 235 } 236 } 237 } 149 238 }
Note:
See TracChangeset
for help on using the changeset viewer.