1 | package it.finki.tinki.web.controller;
|
---|
2 |
|
---|
3 | import it.finki.tinki.helper.Matchmaker;
|
---|
4 | import it.finki.tinki.model.Jobs.Internship;
|
---|
5 | import it.finki.tinki.model.Jobs.Job;
|
---|
6 | import it.finki.tinki.model.Jobs.Project;
|
---|
7 | import it.finki.tinki.model.Skill;
|
---|
8 | import it.finki.tinki.model.Users.Account;
|
---|
9 | import it.finki.tinki.model.Users.User;
|
---|
10 | import it.finki.tinki.service.AccountService;
|
---|
11 | import it.finki.tinki.service.MatchmakerService;
|
---|
12 | import it.finki.tinki.service.SkillService;
|
---|
13 | import it.finki.tinki.service.WorkService;
|
---|
14 | import org.springframework.web.bind.annotation.*;
|
---|
15 |
|
---|
16 | import java.util.HashMap;
|
---|
17 | import java.util.List;
|
---|
18 | import java.util.Map;
|
---|
19 |
|
---|
20 | @RestController
|
---|
21 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
22 | @RequestMapping("/api/register")
|
---|
23 | public class RegisterController {
|
---|
24 |
|
---|
25 | AccountService accountService;
|
---|
26 | SkillService skillService;
|
---|
27 | WorkService workService;
|
---|
28 | MatchmakerService matchmakerService;
|
---|
29 |
|
---|
30 | public RegisterController(AccountService accountService, SkillService skillService, WorkService workService, MatchmakerService matchmakerService) {
|
---|
31 | this.accountService = accountService;
|
---|
32 | this.skillService = skillService;
|
---|
33 | this.workService = workService;
|
---|
34 | this.matchmakerService = matchmakerService;
|
---|
35 | }
|
---|
36 |
|
---|
37 | @RequestMapping(path = "/user", method = RequestMethod.POST)
|
---|
38 | private Map<String, String> registerUser(@RequestParam String email,
|
---|
39 | @RequestParam String password,
|
---|
40 | @RequestParam String name,
|
---|
41 | @RequestParam String surname,
|
---|
42 | @RequestParam List<Integer> retainedSkills,
|
---|
43 | @RequestParam List<Integer> skillsToLearn){
|
---|
44 |
|
---|
45 | List<Skill> retained = this.skillService.returnSkillsBasedOnId(retainedSkills);
|
---|
46 | List<Skill> toLearn = this.skillService.returnSkillsBasedOnId(skillsToLearn);
|
---|
47 |
|
---|
48 | Account k = this.accountService.registerUser(email, password, name, surname, retained, toLearn);
|
---|
49 |
|
---|
50 | Map<String, String> response = new HashMap<>();
|
---|
51 |
|
---|
52 | if(k==null){
|
---|
53 | response.put("error", "There was an error when trying to register user.");
|
---|
54 | }else{
|
---|
55 | List<Job> jobs = this.workService.getAllJobs();
|
---|
56 | List<Project> projects = this.workService.getAllProjects();
|
---|
57 | List<Internship> internships = this.workService.getAllInternships();
|
---|
58 |
|
---|
59 | jobs.forEach(job -> {
|
---|
60 | this.matchmakerService.setUpUserJobMatches(job, (User) k);
|
---|
61 | });
|
---|
62 |
|
---|
63 | projects.forEach(project -> {
|
---|
64 | this.matchmakerService.setUpUserProjectMatches(project, (User) k);
|
---|
65 | });
|
---|
66 |
|
---|
67 | internships.forEach(internship -> {
|
---|
68 | this.matchmakerService.setUpUserInternshipMatches(internship, (User) k);
|
---|
69 | });
|
---|
70 |
|
---|
71 | response.put("success", "Registration completed successfully.");
|
---|
72 | }
|
---|
73 |
|
---|
74 | return response;
|
---|
75 | }
|
---|
76 |
|
---|
77 | @RequestMapping(path = "/team", method = RequestMethod.POST)
|
---|
78 | private Map<String, String> registerTeam(@RequestParam String email,
|
---|
79 | @RequestParam String password,
|
---|
80 | @RequestParam String name,
|
---|
81 | @RequestParam int members){
|
---|
82 |
|
---|
83 | Account k = this.accountService.registerTeam(email, password, name, members);
|
---|
84 |
|
---|
85 | Map<String, String> response = new HashMap<>();
|
---|
86 |
|
---|
87 | if(k==null){
|
---|
88 | response.put("error", "There was an error when trying to register team.");
|
---|
89 | }else{
|
---|
90 | response.put("success", "Registration completed successfully.");
|
---|
91 | }
|
---|
92 |
|
---|
93 | return response;
|
---|
94 | }
|
---|
95 |
|
---|
96 | @RequestMapping(path = "/company", method = RequestMethod.POST)
|
---|
97 | private Map<String, String> registerTeam(@RequestParam String email,
|
---|
98 | @RequestParam String password,
|
---|
99 | @RequestParam String name,
|
---|
100 | @RequestParam String country,
|
---|
101 | @RequestParam String city,
|
---|
102 | @RequestParam String street){
|
---|
103 |
|
---|
104 | Account k = this.accountService.registerCompany(email, password, name, country, city, street);
|
---|
105 |
|
---|
106 | Map<String, String> response = new HashMap<>();
|
---|
107 |
|
---|
108 | if(k==null){
|
---|
109 | response.put("error", "There was an error when trying to register company.");
|
---|
110 | }else{
|
---|
111 | response.put("success", "Registration completed successfully.");
|
---|
112 | }
|
---|
113 |
|
---|
114 | return response;
|
---|
115 | }
|
---|
116 | }
|
---|