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

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

finalized register and login and added insert options for jobs

  • Property mode set to 100644
File size: 3.4 KB
Line 
1package it.finki.tinki.web.controller;
2
3import it.finki.tinki.model.Users.Account;
4import it.finki.tinki.model.Users.Company;
5import it.finki.tinki.model.Users.Team;
6import it.finki.tinki.model.Users.User;
7import it.finki.tinki.model.dto.*;
8import it.finki.tinki.model.enumerator.AccountType;
9import it.finki.tinki.service.AccountService;
10import it.finki.tinki.service.MatchmakerService;
11import it.finki.tinki.service.WorkService;
12import org.apache.coyote.Response;
13import org.springframework.web.bind.annotation.*;
14import org.springframework.web.server.ResponseStatusException;
15
16import java.util.Map;
17
18@RestController
19@CrossOrigin(origins = "http://localhost:3000")
20@RequestMapping("/api")
21public class LoginController {
22
23 AccountService accountService;
24 MatchmakerService matchmakerService;
25 WorkService workService;
26
27 public LoginController(AccountService accountService, MatchmakerService matchmakerService, WorkService workService) {
28 this.accountService = accountService;
29 this.matchmakerService = matchmakerService;
30 this.workService = workService;
31 }
32
33 @PostMapping(path = "/login")
34 public LoginResponseDTO testPage(@RequestBody AccountLoginDTO body) throws ResponseStatusException {
35
36 System.out.println(body);
37
38 Account a1 = accountService.findUser(body.getEmail(), body.getPassword(), body.getType());
39
40 if(a1!=null){
41 if(a1.getClass().equals(User.class)){
42
43 UserResponseDTO uDto = new UserResponseDTO();
44
45 uDto.setError(null);
46
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
56 uDto.setInternships(this.matchmakerService.getMatchingInternshipsForUser((User) a1));
57 uDto.setJobs(this.matchmakerService.getMatchingJobsForUser((User) a1));
58 uDto.setProjects(this.matchmakerService.getMatchingProjectsForUser((User) a1));
59
60 return uDto;
61
62 }else if(a1.getClass().equals(Team.class)){
63
64 TeamResponseDTO tDto = new TeamResponseDTO();
65
66 tDto.setError(null);
67
68 tDto.setId(a1.getId());
69 tDto.setEmail(a1.getEmail());
70 tDto.setName(a1.getName());
71 tDto.setType(AccountType.USER);
72 tDto.setMembers(((Team) a1).getMembers());
73
74 tDto.setJobs(this.workService.getAllJobsByAccount(a1.getId()));
75 tDto.setProjects(this.workService.getAllProjectsByAccount(a1.getId()));
76
77 return tDto;
78
79 }else{
80
81 CompanyResponseDTO cDto = new CompanyResponseDTO();
82
83 cDto.setError(null);
84
85 cDto.setId(a1.getId());
86 cDto.setEmail(a1.getEmail());
87 cDto.setName(a1.getName());
88 cDto.setType(AccountType.USER);
89 cDto.setAddress(((Company) a1).getAddress());
90
91 cDto.setJobs(this.workService.getAllJobsByAccount(a1.getId()));
92 cDto.setInternships(this.workService.getAllInternshipsByAccount(a1.getId()));
93
94 return cDto;
95
96 }
97 }
98
99 return new LoginResponseDTO();
100 }
101
102}
Note: See TracBrowser for help on using the repository browser.