[723994f] | 1 | package it.finki.tinki.web.controller;
|
---|
| 2 |
|
---|
[4cec0a3] | 3 | import it.finki.tinki.model.Jobs.Internship;
|
---|
| 4 | import it.finki.tinki.model.Jobs.Job;
|
---|
[b24fe9b] | 5 | import it.finki.tinki.model.Jobs.Project;
|
---|
[723994f] | 6 | import it.finki.tinki.model.Users.Account;
|
---|
[509cb95] | 7 | import it.finki.tinki.model.Users.Company;
|
---|
[723994f] | 8 | import it.finki.tinki.model.Users.Team;
|
---|
| 9 | import it.finki.tinki.model.Users.User;
|
---|
[509cb95] | 10 | import it.finki.tinki.model.dto.*;
|
---|
[723994f] | 11 | import it.finki.tinki.model.enumerator.AccountType;
|
---|
| 12 | import it.finki.tinki.service.AccountService;
|
---|
| 13 | import it.finki.tinki.service.MatchmakerService;
|
---|
[509cb95] | 14 | import it.finki.tinki.service.WorkService;
|
---|
| 15 | import org.apache.coyote.Response;
|
---|
[723994f] | 16 | import org.springframework.web.bind.annotation.*;
|
---|
| 17 | import org.springframework.web.server.ResponseStatusException;
|
---|
| 18 |
|
---|
[4cec0a3] | 19 | import java.util.List;
|
---|
[723994f] | 20 | import java.util.Map;
|
---|
| 21 |
|
---|
| 22 | @RestController
|
---|
| 23 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
| 24 | @RequestMapping("/api")
|
---|
| 25 | public class LoginController {
|
---|
| 26 |
|
---|
| 27 | AccountService accountService;
|
---|
| 28 | MatchmakerService matchmakerService;
|
---|
[509cb95] | 29 | WorkService workService;
|
---|
[723994f] | 30 |
|
---|
[509cb95] | 31 | public LoginController(AccountService accountService, MatchmakerService matchmakerService, WorkService workService) {
|
---|
[723994f] | 32 | this.accountService = accountService;
|
---|
| 33 | this.matchmakerService = matchmakerService;
|
---|
[509cb95] | 34 | this.workService = workService;
|
---|
[723994f] | 35 | }
|
---|
| 36 |
|
---|
| 37 | @PostMapping(path = "/login")
|
---|
| 38 | public LoginResponseDTO testPage(@RequestBody AccountLoginDTO body) throws ResponseStatusException {
|
---|
| 39 |
|
---|
| 40 | System.out.println(body);
|
---|
| 41 |
|
---|
| 42 | Account a1 = accountService.findUser(body.getEmail(), body.getPassword(), body.getType());
|
---|
[509cb95] | 43 |
|
---|
[723994f] | 44 | if(a1!=null){
|
---|
| 45 | if(a1.getClass().equals(User.class)){
|
---|
| 46 |
|
---|
| 47 | UserResponseDTO uDto = new UserResponseDTO();
|
---|
| 48 |
|
---|
[509cb95] | 49 | uDto.setError(null);
|
---|
| 50 |
|
---|
[723994f] | 51 | uDto.setId(a1.getId());
|
---|
| 52 | uDto.setEmail(a1.getEmail());
|
---|
| 53 | uDto.setName(a1.getName());
|
---|
| 54 | uDto.setType(AccountType.USER);
|
---|
| 55 | uDto.setSurname(((User) a1).getSurname());
|
---|
| 56 |
|
---|
| 57 | uDto.setRetained(((User) a1).getRetainedSkills());
|
---|
| 58 | uDto.setToLearn(((User) a1).getSkillsToLearn());
|
---|
| 59 |
|
---|
[4cec0a3] | 60 | List<Job> matchedJobs = this.matchmakerService.getMatchingJobsForUser((User) a1);
|
---|
[b24fe9b] | 61 | List<Project> matchedProjects = this.matchmakerService.getMatchingProjectsForUser((User) a1);
|
---|
| 62 | List<Internship> matchedInternships = this.matchmakerService.getMatchingInternshipsForUser((User) a1);
|
---|
[4cec0a3] | 63 |
|
---|
| 64 | matchedJobs.forEach(job -> {
|
---|
| 65 | JobResponseDTO dto = new JobResponseDTO(job);
|
---|
| 66 | uDto.getJobs().add(dto);
|
---|
| 67 | });
|
---|
| 68 |
|
---|
[b24fe9b] | 69 | matchedProjects.forEach(project -> {
|
---|
| 70 | ProjectResponseDTO dto = new ProjectResponseDTO(project);
|
---|
| 71 | uDto.getProjects().add(dto);
|
---|
| 72 | });
|
---|
| 73 |
|
---|
| 74 | matchedInternships.forEach(internship -> {
|
---|
| 75 | InternshipResponseDTO dto = new InternshipResponseDTO(internship);
|
---|
| 76 | uDto.getInternships().add(dto);
|
---|
| 77 | });
|
---|
| 78 |
|
---|
[723994f] | 79 |
|
---|
| 80 | return uDto;
|
---|
[509cb95] | 81 |
|
---|
[723994f] | 82 | }else if(a1.getClass().equals(Team.class)){
|
---|
| 83 |
|
---|
[509cb95] | 84 | TeamResponseDTO tDto = new TeamResponseDTO();
|
---|
| 85 |
|
---|
| 86 | tDto.setError(null);
|
---|
| 87 |
|
---|
| 88 | tDto.setId(a1.getId());
|
---|
| 89 | tDto.setEmail(a1.getEmail());
|
---|
| 90 | tDto.setName(a1.getName());
|
---|
| 91 | tDto.setType(AccountType.USER);
|
---|
| 92 | tDto.setMembers(((Team) a1).getMembers());
|
---|
| 93 |
|
---|
| 94 | tDto.setJobs(this.workService.getAllJobsByAccount(a1.getId()));
|
---|
| 95 | tDto.setProjects(this.workService.getAllProjectsByAccount(a1.getId()));
|
---|
| 96 |
|
---|
| 97 | return tDto;
|
---|
| 98 |
|
---|
[723994f] | 99 | }else{
|
---|
| 100 |
|
---|
[509cb95] | 101 | CompanyResponseDTO cDto = new CompanyResponseDTO();
|
---|
| 102 |
|
---|
| 103 | cDto.setError(null);
|
---|
| 104 |
|
---|
| 105 | cDto.setId(a1.getId());
|
---|
| 106 | cDto.setEmail(a1.getEmail());
|
---|
| 107 | cDto.setName(a1.getName());
|
---|
| 108 | cDto.setType(AccountType.USER);
|
---|
| 109 | cDto.setAddress(((Company) a1).getAddress());
|
---|
| 110 |
|
---|
| 111 | cDto.setJobs(this.workService.getAllJobsByAccount(a1.getId()));
|
---|
| 112 | cDto.setInternships(this.workService.getAllInternshipsByAccount(a1.getId()));
|
---|
| 113 |
|
---|
| 114 | return cDto;
|
---|
| 115 |
|
---|
[723994f] | 116 | }
|
---|
| 117 | }
|
---|
| 118 |
|
---|
[509cb95] | 119 | return new LoginResponseDTO();
|
---|
[723994f] | 120 | }
|
---|
| 121 |
|
---|
| 122 | }
|
---|