source: src/main/java/it/finki/tinki/web/controller/LoginController.java@ 5f9d25a

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

refactoring controllers

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[723994f]1package it.finki.tinki.web.controller;
2
[bd46dbb]3import it.finki.tinki.model.Work.Internship;
4import it.finki.tinki.model.Work.Job;
5import it.finki.tinki.model.Work.Project;
[723994f]6import it.finki.tinki.model.Users.Account;
[509cb95]7import it.finki.tinki.model.Users.Company;
[723994f]8import it.finki.tinki.model.Users.Team;
9import it.finki.tinki.model.Users.User;
[509cb95]10import it.finki.tinki.model.dto.*;
[bd46dbb]11import it.finki.tinki.model.dto.response.account.LoginResponseDTO;
12import it.finki.tinki.model.dto.response.account.CompanyResponseDTO;
13import it.finki.tinki.model.dto.response.account.TeamResponseDTO;
14import it.finki.tinki.model.dto.response.account.UserResponseDTO;
15import it.finki.tinki.model.dto.response.work.InternshipResponseDTO;
16import it.finki.tinki.model.dto.response.work.JobResponseDTO;
17import it.finki.tinki.model.dto.response.work.ProjectResponseDTO;
[723994f]18import it.finki.tinki.model.enumerator.AccountType;
19import it.finki.tinki.service.AccountService;
[5f9d25a]20import it.finki.tinki.service.BuilderService;
[723994f]21import it.finki.tinki.service.MatchmakerService;
[509cb95]22import it.finki.tinki.service.WorkService;
[723994f]23import org.springframework.web.bind.annotation.*;
24import org.springframework.web.server.ResponseStatusException;
25
[4cec0a3]26import java.util.List;
[723994f]27
28@RestController
29@CrossOrigin(origins = "http://localhost:3000")
30@RequestMapping("/api")
31public class LoginController {
32
33 AccountService accountService;
[509cb95]34 WorkService workService;
[5f9d25a]35 BuilderService builderService;
[723994f]36
[5f9d25a]37 public LoginController(AccountService accountService, WorkService workService, BuilderService builderService) {
[723994f]38 this.accountService = accountService;
[509cb95]39 this.workService = workService;
[5f9d25a]40 this.builderService = builderService;
[723994f]41 }
42
43 @PostMapping(path = "/login")
[277b400]44 public LoginResponseDTO loginProcess(@RequestBody AccountLoginDTO body) throws ResponseStatusException {
[723994f]45
46 Account a1 = accountService.findUser(body.getEmail(), body.getPassword(), body.getType());
[509cb95]47
[723994f]48 if(a1!=null){
49 if(a1.getClass().equals(User.class)){
[5f9d25a]50 return this.builderService.buildUserResponseDTO(a1);
[277b400]51 }else if(a1.getClass().equals(Team.class)){
[5f9d25a]52 return this.builderService.buildTeamResponseDTO(a1);
[277b400]53 }else{
[5f9d25a]54 return this.builderService.buildCompanyResponseDTO(a1);
[277b400]55 }
56 }
[723994f]57
[277b400]58 return new LoginResponseDTO();
59 }
[723994f]60
[f067338]61 @GetMapping(path = "/job/search")
62 public List<JobResponseDTO> jobRes(@RequestParam(name = "text") String text){
63 return this.workService.fullTextJobSearch(text);
64 }
65
66 @GetMapping(path = "/internship/search")
67 public List<InternshipResponseDTO> internshipRes(@RequestParam(name = "text") String text){
68 return this.workService.fullTextInternshipSearch(text);
69 }
70
71 @GetMapping(path = "/project/search")
72 public List<ProjectResponseDTO> projectRes(@RequestParam(name = "text") String text){
73 return this.workService.fullTextProjectSearch(text);
74 }
[723994f]75}
Note: See TracBrowser for help on using the repository browser.