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