1 | package it.finki.tinki.web.controller;
|
---|
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.dto.*;
|
---|
8 | import it.finki.tinki.model.enumerator.AccountType;
|
---|
9 | import it.finki.tinki.service.AccountService;
|
---|
10 | import it.finki.tinki.service.MatchmakerService;
|
---|
11 | import it.finki.tinki.service.WorkService;
|
---|
12 | import org.apache.coyote.Response;
|
---|
13 | import org.springframework.web.bind.annotation.*;
|
---|
14 | import org.springframework.web.server.ResponseStatusException;
|
---|
15 |
|
---|
16 | import java.util.Map;
|
---|
17 |
|
---|
18 | @RestController
|
---|
19 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
20 | @RequestMapping("/api")
|
---|
21 | public class LoginController {
|
---|
22 |
|
---|
23 | AccountService accountService;
|
---|
24 | MatchmakerService matchmakerService;
|
---|
25 | WorkService workService;
|
---|
26 |
|
---|
27 | public LoginController(AccountService accountService, MatchmakerService matchmakerService, WorkService workService) {
|
---|
28 | this.accountService = accountService;
|
---|
29 | this.matchmakerService = matchmakerService;
|
---|
30 | this.workService = workService;
|
---|
31 | }
|
---|
32 |
|
---|
33 | @PostMapping(path = "/login")
|
---|
34 | public LoginResponseDTO testPage(@RequestBody AccountLoginDTO body) throws ResponseStatusException {
|
---|
35 |
|
---|
36 | System.out.println(body);
|
---|
37 |
|
---|
38 | Account a1 = accountService.findUser(body.getEmail(), body.getPassword(), body.getType());
|
---|
39 |
|
---|
40 | if(a1!=null){
|
---|
41 | if(a1.getClass().equals(User.class)){
|
---|
42 |
|
---|
43 | UserResponseDTO uDto = new UserResponseDTO();
|
---|
44 |
|
---|
45 | uDto.setError(null);
|
---|
46 |
|
---|
47 | uDto.setId(a1.getId());
|
---|
48 | uDto.setEmail(a1.getEmail());
|
---|
49 | uDto.setName(a1.getName());
|
---|
50 | uDto.setType(AccountType.USER);
|
---|
51 | uDto.setSurname(((User) a1).getSurname());
|
---|
52 |
|
---|
53 | uDto.setRetained(((User) a1).getRetainedSkills());
|
---|
54 | uDto.setToLearn(((User) a1).getSkillsToLearn());
|
---|
55 |
|
---|
56 | uDto.setInternships(this.matchmakerService.getMatchingInternshipsForUser((User) a1));
|
---|
57 | uDto.setJobs(this.matchmakerService.getMatchingJobsForUser((User) a1));
|
---|
58 | uDto.setProjects(this.matchmakerService.getMatchingProjectsForUser((User) a1));
|
---|
59 |
|
---|
60 | return uDto;
|
---|
61 |
|
---|
62 | }else if(a1.getClass().equals(Team.class)){
|
---|
63 |
|
---|
64 | TeamResponseDTO tDto = new TeamResponseDTO();
|
---|
65 |
|
---|
66 | tDto.setError(null);
|
---|
67 |
|
---|
68 | tDto.setId(a1.getId());
|
---|
69 | tDto.setEmail(a1.getEmail());
|
---|
70 | tDto.setName(a1.getName());
|
---|
71 | tDto.setType(AccountType.USER);
|
---|
72 | tDto.setMembers(((Team) a1).getMembers());
|
---|
73 |
|
---|
74 | tDto.setJobs(this.workService.getAllJobsByAccount(a1.getId()));
|
---|
75 | tDto.setProjects(this.workService.getAllProjectsByAccount(a1.getId()));
|
---|
76 |
|
---|
77 | return tDto;
|
---|
78 |
|
---|
79 | }else{
|
---|
80 |
|
---|
81 | CompanyResponseDTO cDto = new CompanyResponseDTO();
|
---|
82 |
|
---|
83 | cDto.setError(null);
|
---|
84 |
|
---|
85 | cDto.setId(a1.getId());
|
---|
86 | cDto.setEmail(a1.getEmail());
|
---|
87 | cDto.setName(a1.getName());
|
---|
88 | cDto.setType(AccountType.USER);
|
---|
89 | cDto.setAddress(((Company) a1).getAddress());
|
---|
90 |
|
---|
91 | cDto.setJobs(this.workService.getAllJobsByAccount(a1.getId()));
|
---|
92 | cDto.setInternships(this.workService.getAllInternshipsByAccount(a1.getId()));
|
---|
93 |
|
---|
94 | return cDto;
|
---|
95 |
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | return new LoginResponseDTO();
|
---|
100 | }
|
---|
101 |
|
---|
102 | }
|
---|