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

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

added response dto for job response

  • Property mode set to 100644
File size: 3.5 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.Users.Account;
6import it.finki.tinki.model.Users.Company;
7import it.finki.tinki.model.Users.Team;
8import it.finki.tinki.model.Users.User;
9import it.finki.tinki.model.dto.*;
10import it.finki.tinki.model.enumerator.AccountType;
11import it.finki.tinki.service.AccountService;
12import it.finki.tinki.service.MatchmakerService;
13import it.finki.tinki.service.WorkService;
14import org.apache.coyote.Response;
15import org.springframework.web.bind.annotation.*;
16import org.springframework.web.server.ResponseStatusException;
17
18import java.util.List;
19import java.util.Map;
20
21@RestController
22@CrossOrigin(origins = "http://localhost:3000")
23@RequestMapping("/api")
24public class LoginController {
25
26 AccountService accountService;
27 MatchmakerService matchmakerService;
28 WorkService workService;
29
30 public LoginController(AccountService accountService, MatchmakerService matchmakerService, WorkService workService) {
31 this.accountService = accountService;
32 this.matchmakerService = matchmakerService;
33 this.workService = workService;
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());
42
43 if(a1!=null){
44 if(a1.getClass().equals(User.class)){
45
46 UserResponseDTO uDto = new UserResponseDTO();
47
48 uDto.setError(null);
49
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
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
66
67 return uDto;
68
69 }else if(a1.getClass().equals(Team.class)){
70
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
86 }else{
87
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
103 }
104 }
105
106 return new LoginResponseDTO();
107 }
108
109}
Note: See TracBrowser for help on using the repository browser.