[723994f] | 1 | package it.finki.tinki.web.controller;
|
---|
[7edede9] | 2 |
|
---|
[509cb95] | 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;
|
---|
[4a15c9c] | 7 | import it.finki.tinki.model.Skill;
|
---|
| 8 | import it.finki.tinki.model.Users.Account;
|
---|
[509cb95] | 9 | import it.finki.tinki.model.Users.User;
|
---|
[4a15c9c] | 10 | import it.finki.tinki.service.AccountService;
|
---|
[509cb95] | 11 | import it.finki.tinki.service.MatchmakerService;
|
---|
[4a15c9c] | 12 | import it.finki.tinki.service.SkillService;
|
---|
[509cb95] | 13 | import it.finki.tinki.service.WorkService;
|
---|
[4a15c9c] | 14 | import org.springframework.web.bind.annotation.*;
|
---|
| 15 |
|
---|
| 16 | import java.util.HashMap;
|
---|
| 17 | import java.util.List;
|
---|
| 18 | import java.util.Map;
|
---|
[7edede9] | 19 |
|
---|
| 20 | @RestController
|
---|
| 21 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
| 22 | @RequestMapping("/api/register")
|
---|
| 23 | public class RegisterController {
|
---|
| 24 |
|
---|
[4a15c9c] | 25 | AccountService accountService;
|
---|
| 26 | SkillService skillService;
|
---|
[509cb95] | 27 | WorkService workService;
|
---|
| 28 | MatchmakerService matchmakerService;
|
---|
[4a15c9c] | 29 |
|
---|
[509cb95] | 30 | public RegisterController(AccountService accountService, SkillService skillService, WorkService workService, MatchmakerService matchmakerService) {
|
---|
[4a15c9c] | 31 | this.accountService = accountService;
|
---|
| 32 | this.skillService = skillService;
|
---|
[509cb95] | 33 | this.workService = workService;
|
---|
| 34 | this.matchmakerService = matchmakerService;
|
---|
[4a15c9c] | 35 | }
|
---|
| 36 |
|
---|
| 37 | @RequestMapping(path = "/user", method = RequestMethod.POST)
|
---|
| 38 | private Map<String, String> registerUser(@RequestParam String email,
|
---|
[509cb95] | 39 | @RequestParam String password,
|
---|
| 40 | @RequestParam String name,
|
---|
| 41 | @RequestParam String surname,
|
---|
| 42 | @RequestParam List<Integer> retainedSkills,
|
---|
| 43 | @RequestParam List<Integer> skillsToLearn){
|
---|
[4a15c9c] | 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 |
|
---|
[509cb95] | 52 | if(k==null){
|
---|
[4a15c9c] | 53 | response.put("error", "There was an error when trying to register user.");
|
---|
| 54 | }else{
|
---|
[509cb95] | 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 |
|
---|
[4a15c9c] | 71 | response.put("success", "Registration completed successfully.");
|
---|
| 72 | }
|
---|
[7edede9] | 73 |
|
---|
[4a15c9c] | 74 | return response;
|
---|
| 75 | }
|
---|
[7edede9] | 76 |
|
---|
[9d4220d] | 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){
|
---|
[7edede9] | 82 |
|
---|
[9d4220d] | 83 | Account k = this.accountService.registerTeam(email, password, name, members);
|
---|
| 84 |
|
---|
| 85 | Map<String, String> response = new HashMap<>();
|
---|
| 86 |
|
---|
[509cb95] | 87 | if(k==null){
|
---|
[9d4220d] | 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 |
|
---|
[509cb95] | 108 | if(k==null){
|
---|
[9d4220d] | 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 | }
|
---|
[7edede9] | 116 | }
|
---|