Changeset 14b648e for src/main/java/it
- Timestamp:
- 01/08/21 20:46:33 (4 years ago)
- Branches:
- master
- Children:
- bd38a55
- Parents:
- 31fc5c8
- Location:
- src/main/java/it/finki/tinki
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/it/finki/tinki/repository/CompanyRepository.java
r31fc5c8 r14b648e 10 10 public interface CompanyRepository extends JpaRepository<Company, Long> { 11 11 Company findByEmailAndPassword(String email, String password); 12 Optional<Object> findByEmail(String email); 12 Optional<Company> findByEmail(String email); 13 Optional<Company> findByIdAndEmail(Long id, String email); 13 14 } -
src/main/java/it/finki/tinki/repository/TeamRepository.java
r31fc5c8 r14b648e 1 1 package it.finki.tinki.repository; 2 2 3 import it.finki.tinki.model.Users.Company; 3 4 import it.finki.tinki.model.Users.Team; 4 5 import org.springframework.data.jpa.repository.JpaRepository; … … 11 12 Team findByEmailAndPassword(String email, String password); 12 13 Optional<Team> findByEmail(String email); 14 Optional<Team> findByIdAndEmail(Long id, String email); 13 15 } -
src/main/java/it/finki/tinki/repository/UserRepository.java
r31fc5c8 r14b648e 11 11 User findByEmailAndPassword(String email, String password); 12 12 Optional<User> findByEmail(String email); 13 Optional<User> findByIdAndEmail(Long id, String email); 13 14 } -
src/main/java/it/finki/tinki/service/AccountService.java
r31fc5c8 r14b648e 3 3 import it.finki.tinki.model.Skill; 4 4 import it.finki.tinki.model.Users.Account; 5 import it.finki.tinki.model.Users.Company; 6 import it.finki.tinki.model.Users.Team; 7 import it.finki.tinki.model.Users.User; 5 8 import it.finki.tinki.model.enumerator.AccountType; 6 9 7 10 import java.util.List; 11 import java.util.Optional; 8 12 9 13 public interface AccountService { … … 13 17 Account registerCompany(String email, String password, String name, String country, String city, String street); 14 18 Account findByIdAndType(Long accId, AccountType type); 19 User editUser(Long id, String email, String name, String surname, List<Skill> retainedSkills, List<Skill> skillsToLearn); 20 Company editCompany(Long id, String email, String name, String country, String city, String street); 21 Optional<?> findByIdAndEmail(Long id, String email, AccountType type); 22 Team editTeam(Long id, String email, String name, int members); 15 23 } -
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 } -
src/main/java/it/finki/tinki/web/controller/RegisterController.java
r31fc5c8 r14b648e 69 69 70 70 @RequestMapping(path = "/company", method = RequestMethod.POST) 71 private Map<String, String> registe Company(@RequestBody CompanyRegisterDTO body){71 private Map<String, String> registerCompany(@RequestBody CompanyRegisterDTO body){ 72 72 73 73 Account k = this.accountService.registerCompany(body.getEmail(),
Note:
See TracChangeset
for help on using the changeset viewer.