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

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

project and internship response dto

  • 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.apache.coyote.Response;
16import org.springframework.web.bind.annotation.*;
17import org.springframework.web.server.ResponseStatusException;
18
19import java.util.List;
20import java.util.Map;
21
22@RestController
23@CrossOrigin(origins = "http://localhost:3000")
24@RequestMapping("/api")
25public class LoginController {
26
27 AccountService accountService;
28 MatchmakerService matchmakerService;
29 WorkService workService;
30
31 public LoginController(AccountService accountService, MatchmakerService matchmakerService, WorkService workService) {
32 this.accountService = accountService;
33 this.matchmakerService = matchmakerService;
34 this.workService = workService;
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());
43
44 if(a1!=null){
45 if(a1.getClass().equals(User.class)){
46
47 UserResponseDTO uDto = new UserResponseDTO();
48
49 uDto.setError(null);
50
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
60 List<Job> matchedJobs = this.matchmakerService.getMatchingJobsForUser((User) a1);
61 List<Project> matchedProjects = this.matchmakerService.getMatchingProjectsForUser((User) a1);
62 List<Internship> matchedInternships = this.matchmakerService.getMatchingInternshipsForUser((User) a1);
63
64 matchedJobs.forEach(job -> {
65 JobResponseDTO dto = new JobResponseDTO(job);
66 uDto.getJobs().add(dto);
67 });
68
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
79
80 return uDto;
81
82 }else if(a1.getClass().equals(Team.class)){
83
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
99 }else{
100
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
116 }
117 }
118
119 return new LoginResponseDTO();
120 }
121
122}
Note: See TracBrowser for help on using the repository browser.