1 | package it.finki.tinki.service.impl;
|
---|
2 |
|
---|
3 | import it.finki.tinki.model.Users.Account;
|
---|
4 | import it.finki.tinki.model.Users.Company;
|
---|
5 | import it.finki.tinki.model.Users.Team;
|
---|
6 | import it.finki.tinki.model.Users.User;
|
---|
7 | import it.finki.tinki.model.enumerator.AccountType;
|
---|
8 | import it.finki.tinki.repository.CompanyRepository;
|
---|
9 | import it.finki.tinki.repository.TeamRepository;
|
---|
10 | import it.finki.tinki.repository.UserRepository;
|
---|
11 | import it.finki.tinki.service.AccountService;
|
---|
12 | import org.springframework.stereotype.Service;
|
---|
13 |
|
---|
14 | import java.util.HashMap;
|
---|
15 | import java.util.Map;
|
---|
16 |
|
---|
17 | @Service
|
---|
18 | public class AccountServiceImpl implements AccountService {
|
---|
19 |
|
---|
20 | UserRepository userRepository;
|
---|
21 | TeamRepository teamRepository;
|
---|
22 | CompanyRepository companyRepository;
|
---|
23 |
|
---|
24 | public AccountServiceImpl(UserRepository userRepository, TeamRepository teamRepository, CompanyRepository companyRepository) {
|
---|
25 | this.userRepository = userRepository;
|
---|
26 | this.teamRepository = teamRepository;
|
---|
27 | this.companyRepository = companyRepository;
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public Account findUser(String email, String password, AccountType type) {
|
---|
32 |
|
---|
33 | if(type.equals(AccountType.USER)){
|
---|
34 | User u1 = userRepository.findByEmailAndPassword(email, password);
|
---|
35 | if(u1!=null){
|
---|
36 | return u1;
|
---|
37 | }
|
---|
38 | }
|
---|
39 | else if(type.equals(AccountType.TEAM)){
|
---|
40 | Team t1 = teamRepository.findByEmailAndPassword(email, password);
|
---|
41 | if(t1!=null){
|
---|
42 | return t1;
|
---|
43 | }
|
---|
44 | }
|
---|
45 | else if(type.equals(AccountType.COMPANY)){
|
---|
46 | Company c1 = companyRepository.findByEmailAndPassword(email, password);
|
---|
47 | if(c1!=null){
|
---|
48 | return c1;
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | return null;
|
---|
53 | }
|
---|
54 | }
|
---|