1 | package it.finki.tinki.web.controller;
|
---|
2 |
|
---|
3 | import it.finki.tinki.model.Work.Internship;
|
---|
4 | import it.finki.tinki.model.Work.Job;
|
---|
5 | import it.finki.tinki.model.Work.Project;
|
---|
6 | import it.finki.tinki.model.Users.Account;
|
---|
7 | import it.finki.tinki.model.Users.Company;
|
---|
8 | import it.finki.tinki.model.Users.Team;
|
---|
9 | import it.finki.tinki.model.Users.User;
|
---|
10 | import it.finki.tinki.model.dto.*;
|
---|
11 | import it.finki.tinki.model.dto.response.account.LoginResponseDTO;
|
---|
12 | import it.finki.tinki.model.dto.response.account.CompanyResponseDTO;
|
---|
13 | import it.finki.tinki.model.dto.response.account.TeamResponseDTO;
|
---|
14 | import it.finki.tinki.model.dto.response.account.UserResponseDTO;
|
---|
15 | import it.finki.tinki.model.dto.response.work.InternshipResponseDTO;
|
---|
16 | import it.finki.tinki.model.dto.response.work.JobResponseDTO;
|
---|
17 | import it.finki.tinki.model.dto.response.work.ProjectResponseDTO;
|
---|
18 | import it.finki.tinki.model.enumerator.AccountType;
|
---|
19 | import it.finki.tinki.service.AccountService;
|
---|
20 | import it.finki.tinki.service.BuilderService;
|
---|
21 | import it.finki.tinki.service.MatchmakerService;
|
---|
22 | import it.finki.tinki.service.WorkService;
|
---|
23 | import org.springframework.web.bind.annotation.*;
|
---|
24 | import org.springframework.web.server.ResponseStatusException;
|
---|
25 |
|
---|
26 | import java.util.List;
|
---|
27 |
|
---|
28 | @RestController
|
---|
29 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
30 | @RequestMapping("/api")
|
---|
31 | public class LoginController {
|
---|
32 |
|
---|
33 | AccountService accountService;
|
---|
34 | WorkService workService;
|
---|
35 | BuilderService builderService;
|
---|
36 |
|
---|
37 | public LoginController(AccountService accountService, WorkService workService, BuilderService builderService) {
|
---|
38 | this.accountService = accountService;
|
---|
39 | this.workService = workService;
|
---|
40 | this.builderService = builderService;
|
---|
41 | }
|
---|
42 |
|
---|
43 | @PostMapping(path = "/login")
|
---|
44 | public LoginResponseDTO loginProcess(@RequestBody AccountLoginDTO body) throws ResponseStatusException {
|
---|
45 |
|
---|
46 | Account a1 = accountService.findUser(body.getEmail(), body.getPassword(), body.getType());
|
---|
47 |
|
---|
48 | if(a1!=null){
|
---|
49 | if(a1.getClass().equals(User.class)){
|
---|
50 | return this.builderService.buildUserResponseDTO(a1);
|
---|
51 | }else if(a1.getClass().equals(Team.class)){
|
---|
52 | return this.builderService.buildTeamResponseDTO(a1);
|
---|
53 | }else{
|
---|
54 | return this.builderService.buildCompanyResponseDTO(a1);
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | return new LoginResponseDTO();
|
---|
59 | }
|
---|
60 |
|
---|
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 | }
|
---|
75 | }
|
---|