source: src/main/java/it/finki/tinki/web/controller/LoginController.java@ 33d4f5d

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

bugfixes and refactoring

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[723994f]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;
[509cb95]6import it.finki.tinki.model.dto.*;
[bd46dbb]7import it.finki.tinki.model.dto.response.account.LoginResponseDTO;
[723994f]8import it.finki.tinki.service.AccountService;
[5f9d25a]9import it.finki.tinki.service.BuilderService;
[509cb95]10import it.finki.tinki.service.WorkService;
[723994f]11import org.springframework.web.bind.annotation.*;
12import org.springframework.web.server.ResponseStatusException;
13
[4cec0a3]14import java.util.List;
[723994f]15
16@RestController
17@CrossOrigin(origins = "http://localhost:3000")
18@RequestMapping("/api")
19public 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}
Note: See TracBrowser for help on using the repository browser.