[723994f] | 1 | package it.finki.tinki.web.controller;
|
---|
| 2 |
|
---|
| 3 | import it.finki.tinki.model.Users.Account;
|
---|
| 4 | import it.finki.tinki.model.Users.Team;
|
---|
| 5 | import it.finki.tinki.model.Users.User;
|
---|
| 6 | import it.finki.tinki.model.dto.AccountLoginDTO;
|
---|
| 7 | import it.finki.tinki.model.dto.AuthResponseDTO;
|
---|
| 8 | import it.finki.tinki.model.dto.LoginResponseDTO;
|
---|
| 9 | import it.finki.tinki.model.dto.UserResponseDTO;
|
---|
| 10 | import it.finki.tinki.model.enumerator.AccountType;
|
---|
| 11 | import it.finki.tinki.service.AccountService;
|
---|
| 12 | import it.finki.tinki.service.MatchmakerService;
|
---|
| 13 | import org.springframework.web.bind.annotation.*;
|
---|
| 14 | import org.springframework.web.server.ResponseStatusException;
|
---|
| 15 |
|
---|
| 16 | import java.util.Map;
|
---|
| 17 |
|
---|
| 18 | @RestController
|
---|
| 19 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
| 20 | @RequestMapping("/api")
|
---|
| 21 | public 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 | }
|
---|