source: src/main/java/it/finki/tinki/web/controller/LoginController.java@ fc8421e

Last change on this file since fc8421e was 17abe5e, checked in by i-ina <76742075+i-ina@…>, 3 years ago

react components for details and bugfix

  • Property mode set to 100644
File size: 5.7 KB
RevLine 
[723994f]1package it.finki.tinki.web.controller;
2
[bd46dbb]3import it.finki.tinki.model.Work.Internship;
4import it.finki.tinki.model.Work.Job;
5import it.finki.tinki.model.Work.Project;
[723994f]6import it.finki.tinki.model.Users.Account;
[509cb95]7import it.finki.tinki.model.Users.Company;
[723994f]8import it.finki.tinki.model.Users.Team;
9import it.finki.tinki.model.Users.User;
[509cb95]10import it.finki.tinki.model.dto.*;
[bd46dbb]11import it.finki.tinki.model.dto.response.account.LoginResponseDTO;
12import it.finki.tinki.model.dto.response.account.CompanyResponseDTO;
13import it.finki.tinki.model.dto.response.account.TeamResponseDTO;
14import it.finki.tinki.model.dto.response.account.UserResponseDTO;
15import it.finki.tinki.model.dto.response.work.InternshipResponseDTO;
16import it.finki.tinki.model.dto.response.work.JobResponseDTO;
17import it.finki.tinki.model.dto.response.work.ProjectResponseDTO;
[723994f]18import it.finki.tinki.model.enumerator.AccountType;
19import it.finki.tinki.service.AccountService;
20import it.finki.tinki.service.MatchmakerService;
[509cb95]21import it.finki.tinki.service.WorkService;
[723994f]22import org.springframework.web.bind.annotation.*;
23import org.springframework.web.server.ResponseStatusException;
24
[4cec0a3]25import java.util.List;
[723994f]26
27@RestController
28@CrossOrigin(origins = "http://localhost:3000")
29@RequestMapping("/api")
30public class LoginController {
31
32 AccountService accountService;
33 MatchmakerService matchmakerService;
[509cb95]34 WorkService workService;
[723994f]35
[509cb95]36 public LoginController(AccountService accountService, MatchmakerService matchmakerService, WorkService workService) {
[723994f]37 this.accountService = accountService;
38 this.matchmakerService = matchmakerService;
[509cb95]39 this.workService = workService;
[723994f]40 }
41
42 @PostMapping(path = "/login")
[277b400]43 public LoginResponseDTO loginProcess(@RequestBody AccountLoginDTO body) throws ResponseStatusException {
[723994f]44
[17abe5e]45 System.out.println(body);
[723994f]46 Account a1 = accountService.findUser(body.getEmail(), body.getPassword(), body.getType());
[509cb95]47
[723994f]48 if(a1!=null){
49 if(a1.getClass().equals(User.class)){
[277b400]50 return processUser(a1);
51 }else if(a1.getClass().equals(Team.class)){
52 return processTeam(a1);
53 }else{
54 return processCompany(a1);
55 }
56 }
[723994f]57
[277b400]58 return new LoginResponseDTO();
59 }
[723994f]60
[277b400]61 private UserResponseDTO processUser(Account a1){
62 UserResponseDTO uDto = new UserResponseDTO();
[4cec0a3]63
[277b400]64 uDto.setError(null);
[4cec0a3]65
[277b400]66 uDto.setId(a1.getId());
67 uDto.setEmail(a1.getEmail());
68 uDto.setName(a1.getName());
69 uDto.setType(AccountType.USER);
70 uDto.setSurname(((User) a1).getSurname());
[b24fe9b]71
[277b400]72 uDto.setRetained(((User) a1).getRetainedSkills());
73 uDto.setToLearn(((User) a1).getSkillsToLearn());
[b24fe9b]74
[277b400]75 List<Job> matchedJobs = this.matchmakerService.getMatchingJobsForUser((User) a1);
76 List<Project> matchedProjects = this.matchmakerService.getMatchingProjectsForUser((User) a1);
77 List<Internship> matchedInternships = this.matchmakerService.getMatchingInternshipsForUser((User) a1);
[723994f]78
[277b400]79 matchedJobs.forEach(job -> {
80 JobResponseDTO dto = new JobResponseDTO(job);
81 uDto.getJobs().add(dto);
82 });
[509cb95]83
[277b400]84 matchedProjects.forEach(project -> {
85 ProjectResponseDTO dto = new ProjectResponseDTO(project);
86 uDto.getProjects().add(dto);
87 });
[723994f]88
[277b400]89 matchedInternships.forEach(internship -> {
90 InternshipResponseDTO dto = new InternshipResponseDTO(internship);
91 uDto.getInternships().add(dto);
92 });
[509cb95]93
94
[277b400]95 return uDto;
96 }
[509cb95]97
[277b400]98 private TeamResponseDTO processTeam(Account a1){
99 TeamResponseDTO tDto = new TeamResponseDTO();
[4b1c93d]100
[277b400]101 tDto.setError(null);
[4b1c93d]102
[277b400]103 tDto.setId(a1.getId());
104 tDto.setEmail(a1.getEmail());
105 tDto.setName(a1.getName());
106 tDto.setType(AccountType.TEAM);
107 tDto.setMembers(((Team) a1).getMembers());
[509cb95]108
[277b400]109 List<Job> jobs = this.workService.getAllJobsByAccount(a1.getId());
110 List<Project> projects = this.workService.getAllProjectsByAccount(a1.getId());
[509cb95]111
[277b400]112 jobs.forEach(job -> {
113 JobResponseDTO dto = new JobResponseDTO(job);
114 tDto.getJobs().add(dto);
115 });
[723994f]116
[277b400]117 projects.forEach(project -> {
118 ProjectResponseDTO dto = new ProjectResponseDTO(project);
119 tDto.getProjects().add(dto);
120 });
[509cb95]121
[277b400]122 return tDto;
123 }
[509cb95]124
[277b400]125 private CompanyResponseDTO processCompany(Account a1){
126 CompanyResponseDTO cDto = new CompanyResponseDTO();
[509cb95]127
[277b400]128 cDto.setError(null);
[4b1c93d]129
[277b400]130 cDto.setId(a1.getId());
131 cDto.setEmail(a1.getEmail());
132 cDto.setName(a1.getName());
133 cDto.setType(AccountType.COMPANY);
134 cDto.setAddress(((Company) a1).getAddress());
[4b1c93d]135
[277b400]136 List<Job> jobs = this.workService.getAllJobsByAccount(a1.getId());
137 List<Internship> internships = this.workService.getAllInternshipsByAccount(a1.getId());
[509cb95]138
[277b400]139 jobs.forEach(job -> {
140 JobResponseDTO dto = new JobResponseDTO(job);
141 cDto.getJobs().add(dto);
142 });
[509cb95]143
[277b400]144 internships.forEach(internship -> {
145 InternshipResponseDTO dto = new InternshipResponseDTO(internship);
146 cDto.getInternships().add(dto);
147 });
[723994f]148
[277b400]149 return cDto;
[723994f]150 }
151
[f067338]152 @GetMapping(path = "/job/search")
153 public List<JobResponseDTO> jobRes(@RequestParam(name = "text") String text){
154 return this.workService.fullTextJobSearch(text);
155 }
156
157 @GetMapping(path = "/internship/search")
158 public List<InternshipResponseDTO> internshipRes(@RequestParam(name = "text") String text){
159 return this.workService.fullTextInternshipSearch(text);
160 }
161
162 @GetMapping(path = "/project/search")
163 public List<ProjectResponseDTO> projectRes(@RequestParam(name = "text") String text){
164 return this.workService.fullTextProjectSearch(text);
165 }
166
[723994f]167}
Note: See TracBrowser for help on using the repository browser.