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

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

refactoring and further login functionality

  • Property mode set to 100644
File size: 2.2 KB
Line 
1package it.finki.tinki.web.controller;
2
3import it.finki.tinki.model.Users.Account;
4import it.finki.tinki.model.Users.Team;
5import it.finki.tinki.model.Users.User;
6import it.finki.tinki.model.dto.AccountLoginDTO;
7import it.finki.tinki.model.dto.AuthResponseDTO;
8import it.finki.tinki.model.dto.LoginResponseDTO;
9import it.finki.tinki.model.dto.UserResponseDTO;
10import it.finki.tinki.model.enumerator.AccountType;
11import it.finki.tinki.service.AccountService;
12import it.finki.tinki.service.MatchmakerService;
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
26 public LoginController(AccountService accountService, MatchmakerService matchmakerService) {
27 this.accountService = accountService;
28 this.matchmakerService = matchmakerService;
29 }
30
31 @PostMapping(path = "/login")
32 public LoginResponseDTO testPage(@RequestBody AccountLoginDTO body) throws ResponseStatusException {
33
34 System.out.println(body);
35
36 Account a1 = accountService.findUser(body.getEmail(), body.getPassword(), body.getType());
37 if(a1!=null){
38 if(a1.getClass().equals(User.class)){
39
40 UserResponseDTO uDto = new UserResponseDTO();
41
42 uDto.setId(a1.getId());
43 uDto.setEmail(a1.getEmail());
44 uDto.setName(a1.getName());
45 uDto.setType(AccountType.USER);
46 uDto.setSurname(((User) a1).getSurname());
47
48 uDto.setRetained(((User) a1).getRetainedSkills());
49 uDto.setToLearn(((User) a1).getSkillsToLearn());
50
51 uDto.setInternships(this.matchmakerService.getMatchingInternshipsForUser((User) a1));
52 uDto.setJobs(this.matchmakerService.getMatchingJobsForUser((User) a1));
53 uDto.setProjects(this.matchmakerService.getMatchingProjectsForUser((User) a1));
54
55 return uDto;
56 }else if(a1.getClass().equals(Team.class)){
57
58 }else{
59
60 }
61 }
62
63 return null;
64 }
65
66}
Note: See TracBrowser for help on using the repository browser.