[723994f] | 1 | package it.finki.tinki.web.controller;
|
---|
| 2 |
|
---|
| 3 | import it.finki.tinki.model.Users.Account;
|
---|
[509cb95] | 4 | import it.finki.tinki.model.Users.Company;
|
---|
[723994f] | 5 | import it.finki.tinki.model.Users.Team;
|
---|
| 6 | import it.finki.tinki.model.Users.User;
|
---|
[509cb95] | 7 | import it.finki.tinki.model.dto.*;
|
---|
[723994f] | 8 | import it.finki.tinki.model.enumerator.AccountType;
|
---|
| 9 | import it.finki.tinki.service.AccountService;
|
---|
| 10 | import it.finki.tinki.service.MatchmakerService;
|
---|
[509cb95] | 11 | import it.finki.tinki.service.WorkService;
|
---|
| 12 | import org.apache.coyote.Response;
|
---|
[723994f] | 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;
|
---|
[509cb95] | 25 | WorkService workService;
|
---|
[723994f] | 26 |
|
---|
[509cb95] | 27 | public LoginController(AccountService accountService, MatchmakerService matchmakerService, WorkService workService) {
|
---|
[723994f] | 28 | this.accountService = accountService;
|
---|
| 29 | this.matchmakerService = matchmakerService;
|
---|
[509cb95] | 30 | this.workService = workService;
|
---|
[723994f] | 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());
|
---|
[509cb95] | 39 |
|
---|
[723994f] | 40 | if(a1!=null){
|
---|
| 41 | if(a1.getClass().equals(User.class)){
|
---|
| 42 |
|
---|
| 43 | UserResponseDTO uDto = new UserResponseDTO();
|
---|
| 44 |
|
---|
[509cb95] | 45 | uDto.setError(null);
|
---|
| 46 |
|
---|
[723994f] | 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;
|
---|
[509cb95] | 61 |
|
---|
[723994f] | 62 | }else if(a1.getClass().equals(Team.class)){
|
---|
| 63 |
|
---|
[509cb95] | 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 |
|
---|
[723994f] | 79 | }else{
|
---|
| 80 |
|
---|
[509cb95] | 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 |
|
---|
[723994f] | 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[509cb95] | 99 | return new LoginResponseDTO();
|
---|
[723994f] | 100 | }
|
---|
| 101 |
|
---|
| 102 | }
|
---|