source: src/main/java/it/finki/tinki/web/controller/RegisterController.java@ b24fe9b

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

added dummy data for user skills and fixed bugs

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[723994f]1package it.finki.tinki.web.controller;
[7edede9]2
[509cb95]3import it.finki.tinki.helper.Matchmaker;
4import it.finki.tinki.model.Jobs.Internship;
5import it.finki.tinki.model.Jobs.Job;
6import it.finki.tinki.model.Jobs.Project;
[4a15c9c]7import it.finki.tinki.model.Skill;
8import it.finki.tinki.model.Users.Account;
[509cb95]9import it.finki.tinki.model.Users.User;
[4a15c9c]10import it.finki.tinki.service.AccountService;
[509cb95]11import it.finki.tinki.service.MatchmakerService;
[4a15c9c]12import it.finki.tinki.service.SkillService;
[509cb95]13import it.finki.tinki.service.WorkService;
[4a15c9c]14import org.springframework.web.bind.annotation.*;
15
16import java.util.HashMap;
17import java.util.List;
18import java.util.Map;
[7edede9]19
20@RestController
21@CrossOrigin(origins = "http://localhost:3000")
22@RequestMapping("/api/register")
23public 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,
[a8e8545]42 @RequestParam List<Long> retainedSkills,
43 @RequestParam List<Long> 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{
55 response.put("success", "Registration completed successfully.");
56 }
[7edede9]57
[4a15c9c]58 return response;
59 }
[7edede9]60
[9d4220d]61 @RequestMapping(path = "/team", method = RequestMethod.POST)
62 private Map<String, String> registerTeam(@RequestParam String email,
63 @RequestParam String password,
64 @RequestParam String name,
65 @RequestParam int members){
[7edede9]66
[9d4220d]67 Account k = this.accountService.registerTeam(email, password, name, members);
68
69 Map<String, String> response = new HashMap<>();
70
[509cb95]71 if(k==null){
[9d4220d]72 response.put("error", "There was an error when trying to register team.");
73 }else{
74 response.put("success", "Registration completed successfully.");
75 }
76
77 return response;
78 }
79
80 @RequestMapping(path = "/company", method = RequestMethod.POST)
[a8e8545]81 private Map<String, String> registeCompany(@RequestParam String email,
82 @RequestParam String password,
83 @RequestParam String name,
84 @RequestParam String country,
85 @RequestParam String city,
86 @RequestParam String street){
[9d4220d]87
88 Account k = this.accountService.registerCompany(email, password, name, country, city, street);
89
90 Map<String, String> response = new HashMap<>();
91
[509cb95]92 if(k==null){
[9d4220d]93 response.put("error", "There was an error when trying to register company.");
94 }else{
95 response.put("success", "Registration completed successfully.");
96 }
97
98 return response;
99 }
[7edede9]100}
Note: See TracBrowser for help on using the repository browser.