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

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

cleanup

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