[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;
|
---|
[509cb95] | 6 | import it.finki.tinki.model.dto.*;
|
---|
[bd46dbb] | 7 | import it.finki.tinki.model.dto.response.account.LoginResponseDTO;
|
---|
[723994f] | 8 | import it.finki.tinki.service.AccountService;
|
---|
[5f9d25a] | 9 | import it.finki.tinki.service.BuilderService;
|
---|
[509cb95] | 10 | import it.finki.tinki.service.WorkService;
|
---|
[723994f] | 11 | import org.springframework.web.bind.annotation.*;
|
---|
| 12 | import org.springframework.web.server.ResponseStatusException;
|
---|
| 13 |
|
---|
[4cec0a3] | 14 | import java.util.List;
|
---|
[723994f] | 15 |
|
---|
| 16 | @RestController
|
---|
| 17 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
| 18 | @RequestMapping("/api")
|
---|
| 19 | public class LoginController {
|
---|
| 20 |
|
---|
| 21 | AccountService accountService;
|
---|
[5f9d25a] | 22 | BuilderService builderService;
|
---|
[723994f] | 23 |
|
---|
[33d4f5d] | 24 | public LoginController(AccountService accountService, BuilderService builderService) {
|
---|
[723994f] | 25 | this.accountService = accountService;
|
---|
[5f9d25a] | 26 | this.builderService = builderService;
|
---|
[723994f] | 27 | }
|
---|
| 28 |
|
---|
| 29 | @PostMapping(path = "/login")
|
---|
[277b400] | 30 | public LoginResponseDTO loginProcess(@RequestBody AccountLoginDTO body) throws ResponseStatusException {
|
---|
[723994f] | 31 |
|
---|
| 32 | Account a1 = accountService.findUser(body.getEmail(), body.getPassword(), body.getType());
|
---|
[509cb95] | 33 |
|
---|
[723994f] | 34 | if(a1!=null){
|
---|
| 35 | if(a1.getClass().equals(User.class)){
|
---|
[5f9d25a] | 36 | return this.builderService.buildUserResponseDTO(a1);
|
---|
[277b400] | 37 | }else if(a1.getClass().equals(Team.class)){
|
---|
[5f9d25a] | 38 | return this.builderService.buildTeamResponseDTO(a1);
|
---|
[277b400] | 39 | }else{
|
---|
[5f9d25a] | 40 | return this.builderService.buildCompanyResponseDTO(a1);
|
---|
[277b400] | 41 | }
|
---|
| 42 | }
|
---|
[723994f] | 43 |
|
---|
[277b400] | 44 | return new LoginResponseDTO();
|
---|
| 45 | }
|
---|
[723994f] | 46 | }
|
---|