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
RevLine 
[723994f]1package it.finki.tinki.web.controller;
2
[4cec0a3]3import it.finki.tinki.model.Jobs.Internship;
4import it.finki.tinki.model.Jobs.Job;
[723994f]5import it.finki.tinki.model.Users.Account;
[509cb95]6import it.finki.tinki.model.Users.Company;
[723994f]7import it.finki.tinki.model.Users.Team;
8import it.finki.tinki.model.Users.User;
[509cb95]9import it.finki.tinki.model.dto.*;
[723994f]10import it.finki.tinki.model.enumerator.AccountType;
11import it.finki.tinki.service.AccountService;
12import it.finki.tinki.service.MatchmakerService;
[509cb95]13import it.finki.tinki.service.WorkService;
14import org.apache.coyote.Response;
[723994f]15import org.springframework.web.bind.annotation.*;
16import org.springframework.web.server.ResponseStatusException;
17
[4cec0a3]18import java.util.List;
[723994f]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;
[509cb95]28 WorkService workService;
[723994f]29
[509cb95]30 public LoginController(AccountService accountService, MatchmakerService matchmakerService, WorkService workService) {
[723994f]31 this.accountService = accountService;
32 this.matchmakerService = matchmakerService;
[509cb95]33 this.workService = workService;
[723994f]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());
[509cb95]42
[723994f]43 if(a1!=null){
44 if(a1.getClass().equals(User.class)){
45
46 UserResponseDTO uDto = new UserResponseDTO();
47
[509cb95]48 uDto.setError(null);
49
[723994f]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
[4cec0a3]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
[723994f]66
67 return uDto;
[509cb95]68
[723994f]69 }else if(a1.getClass().equals(Team.class)){
70
[509cb95]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
[723994f]86 }else{
87
[509cb95]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
[723994f]103 }
104 }
105
[509cb95]106 return new LoginResponseDTO();
[723994f]107 }
108
109}
Note: See TracBrowser for help on using the repository browser.