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

Last change on this file since 4b1c93d was 4b1c93d, checked in by Vzdra <vladko.zdravkovski@…>, 3 years ago

added response types to team and company

  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[723994f]1package it.finki.tinki.web.controller;
2
[4cec0a3]3import it.finki.tinki.model.Jobs.Internship;
4import it.finki.tinki.model.Jobs.Job;
[b24fe9b]5import it.finki.tinki.model.Jobs.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.*;
[723994f]11import it.finki.tinki.model.enumerator.AccountType;
12import it.finki.tinki.service.AccountService;
13import it.finki.tinki.service.MatchmakerService;
[509cb95]14import it.finki.tinki.service.WorkService;
[723994f]15import org.springframework.web.bind.annotation.*;
16import org.springframework.web.server.ResponseStatusException;
17
[4cec0a3]18import java.util.List;
[723994f]19
20@RestController
21@CrossOrigin(origins = "http://localhost:3000")
22@RequestMapping("/api")
23public class LoginController {
24
25 AccountService accountService;
26 MatchmakerService matchmakerService;
[509cb95]27 WorkService workService;
[723994f]28
[509cb95]29 public LoginController(AccountService accountService, MatchmakerService matchmakerService, WorkService workService) {
[723994f]30 this.accountService = accountService;
31 this.matchmakerService = matchmakerService;
[509cb95]32 this.workService = workService;
[723994f]33 }
34
35 @PostMapping(path = "/login")
36 public LoginResponseDTO testPage(@RequestBody AccountLoginDTO body) throws ResponseStatusException {
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
[4cec0a3]56 List<Job> matchedJobs = this.matchmakerService.getMatchingJobsForUser((User) a1);
[b24fe9b]57 List<Project> matchedProjects = this.matchmakerService.getMatchingProjectsForUser((User) a1);
58 List<Internship> matchedInternships = this.matchmakerService.getMatchingInternshipsForUser((User) a1);
[4cec0a3]59
60 matchedJobs.forEach(job -> {
61 JobResponseDTO dto = new JobResponseDTO(job);
62 uDto.getJobs().add(dto);
63 });
64
[b24fe9b]65 matchedProjects.forEach(project -> {
66 ProjectResponseDTO dto = new ProjectResponseDTO(project);
67 uDto.getProjects().add(dto);
68 });
69
70 matchedInternships.forEach(internship -> {
71 InternshipResponseDTO dto = new InternshipResponseDTO(internship);
72 uDto.getInternships().add(dto);
73 });
74
[723994f]75
76 return uDto;
[509cb95]77
[723994f]78 }else if(a1.getClass().equals(Team.class)){
79
[509cb95]80 TeamResponseDTO tDto = new TeamResponseDTO();
81
82 tDto.setError(null);
83
84 tDto.setId(a1.getId());
85 tDto.setEmail(a1.getEmail());
86 tDto.setName(a1.getName());
[336d09e]87 tDto.setType(AccountType.TEAM);
[509cb95]88 tDto.setMembers(((Team) a1).getMembers());
89
[4b1c93d]90 List<Job> jobs = this.workService.getAllJobsByAccount(a1.getId());
91 List<Project> projects = this.workService.getAllProjectsByAccount(a1.getId());
92
93 jobs.forEach(job -> {
94 JobResponseDTO dto = new JobResponseDTO(job);
95 tDto.getJobs().add(dto);
96 });
97
98 projects.forEach(project -> {
99 ProjectResponseDTO dto = new ProjectResponseDTO(project);
100 tDto.getProjects().add(dto);
101 });
[509cb95]102
103 return tDto;
104
[723994f]105 }else{
106
[509cb95]107 CompanyResponseDTO cDto = new CompanyResponseDTO();
108
109 cDto.setError(null);
110
111 cDto.setId(a1.getId());
112 cDto.setEmail(a1.getEmail());
113 cDto.setName(a1.getName());
[336d09e]114 cDto.setType(AccountType.COMPANY);
[509cb95]115 cDto.setAddress(((Company) a1).getAddress());
116
[4b1c93d]117 List<Job> jobs = this.workService.getAllJobsByAccount(a1.getId());
118 List<Internship> internships = this.workService.getAllInternshipsByAccount(a1.getId());
119
120 jobs.forEach(job -> {
121 JobResponseDTO dto = new JobResponseDTO(job);
122 cDto.getJobs().add(dto);
123 });
124
125 internships.forEach(internship -> {
126 InternshipResponseDTO dto = new InternshipResponseDTO(internship);
127 cDto.getInternships().add(dto);
128 });
[509cb95]129
130 return cDto;
131
[723994f]132 }
133 }
134
[509cb95]135 return new LoginResponseDTO();
[723994f]136 }
137
138}
Note: See TracBrowser for help on using the repository browser.