- Timestamp:
- 01/06/21 18:18:24 (4 years ago)
- Branches:
- master
- Children:
- 504c3ef
- Parents:
- a222a43
- Location:
- src/main/java/it/finki/tinki
- Files:
-
- 3 added
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/it/finki/tinki/controller/LoginController.java
ra222a43 r7edede9 11 11 @CrossOrigin(origins = "http://localhost:3000") 12 12 @RequestMapping("/api") 13 public class TestController {13 public class LoginController { 14 14 15 15 AccountService accountService; 16 16 17 public TestController(AccountService accountService) {17 public LoginController(AccountService accountService) { 18 18 this.accountService = accountService; 19 19 } -
src/main/java/it/finki/tinki/repository/UserRepository.java
ra222a43 r7edede9 5 5 import org.springframework.stereotype.Repository; 6 6 7 import java.util.Optional; 8 7 9 @Repository 8 10 public interface UserRepository extends JpaRepository<User, Long> { 9 11 User findByEmailAndPassword(String email, String password); 12 Optional<User> findByEmail(String email); 10 13 } -
src/main/java/it/finki/tinki/service/impl/AccountServiceImpl.java
ra222a43 r7edede9 1 1 package it.finki.tinki.service.impl; 2 2 3 import it.finki.tinki.model.Address; 4 import it.finki.tinki.model.Skill; 3 5 import it.finki.tinki.model.Users.Account; 4 6 import it.finki.tinki.model.Users.Company; … … 6 8 import it.finki.tinki.model.Users.User; 7 9 import it.finki.tinki.model.enumerator.AccountType; 10 import it.finki.tinki.model.exception.InvalidArgumentsException; 11 import it.finki.tinki.model.exception.UserExistsException; 12 import it.finki.tinki.repository.AddressRepository; 8 13 import it.finki.tinki.repository.CompanyRepository; 9 14 import it.finki.tinki.repository.TeamRepository; … … 13 18 14 19 import java.util.HashMap; 20 import java.util.List; 15 21 import java.util.Map; 16 22 … … 18 24 public class AccountServiceImpl implements AccountService { 19 25 26 AddressRepository addressRepository; 20 27 UserRepository userRepository; 21 28 TeamRepository teamRepository; 22 29 CompanyRepository companyRepository; 23 30 24 public AccountServiceImpl(UserRepository userRepository, TeamRepository teamRepository, CompanyRepository companyRepository) { 31 public AccountServiceImpl(AddressRepository addressRepository, UserRepository userRepository, TeamRepository teamRepository, CompanyRepository companyRepository) { 32 this.addressRepository = addressRepository; 25 33 this.userRepository = userRepository; 26 34 this.teamRepository = teamRepository; … … 33 41 if(type.equals(AccountType.USER)){ 34 42 User u1 = userRepository.findByEmailAndPassword(email, password); 35 if(u1!=null){ 36 return u1; 37 } 43 return u1; 38 44 } 39 45 else if(type.equals(AccountType.TEAM)){ 40 46 Team t1 = teamRepository.findByEmailAndPassword(email, password); 41 if(t1!=null){ 42 return t1; 43 } 47 return t1; 44 48 } 45 49 else if(type.equals(AccountType.COMPANY)){ 46 50 Company c1 = companyRepository.findByEmailAndPassword(email, password); 47 if(c1!=null){ 48 return c1; 49 } 51 return c1; 50 52 } 51 53 52 54 return null; 53 55 } 56 57 public Account registerUser(String email, String password, String name, String surname, List<Skill> retainedSkills, List<Skill> skillsToLearn){ 58 if(email==null || email.isEmpty() || password==null || password.isEmpty() || name==null || name.isEmpty() || surname==null || surname.isEmpty()){ 59 throw new InvalidArgumentsException(); 60 } 61 62 if(this.userRepository.findByEmail(email).isPresent()){ 63 throw new UserExistsException(); 64 } 65 66 User u = new User(email, password, name, AccountType.USER, surname, retainedSkills, skillsToLearn); 67 return this.userRepository.save(u); 68 } 54 69 }
Note:
See TracChangeset
for help on using the changeset viewer.