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

Last change on this file since 1397178 was 9d4220d, checked in by i-ina <76742075+i-ina@…>, 3 years ago

added register team and register company

  • Property mode set to 100644
File size: 3.5 KB
Line 
1package it.finki.tinki.controller;
2
3import it.finki.tinki.model.Skill;
4import it.finki.tinki.model.Users.Account;
5import it.finki.tinki.model.Users.User;
6import it.finki.tinki.service.AccountService;
7import it.finki.tinki.service.SkillService;
8import org.springframework.http.ResponseEntity;
9import org.springframework.web.bind.annotation.*;
10
11import java.util.ArrayList;
12import java.util.HashMap;
13import java.util.List;
14import java.util.Map;
15
16@RestController
17@CrossOrigin(origins = "http://localhost:3000")
18@RequestMapping("/api/register")
19public class RegisterController {
20
21 AccountService accountService;
22 SkillService skillService;
23
24 public RegisterController(AccountService accountService, SkillService skillService) {
25 this.accountService = accountService;
26 this.skillService = skillService;
27 }
28
29 @RequestMapping(path = "/user", method = RequestMethod.POST)
30 private Map<String, String> registerUser(@RequestParam String email,
31 @RequestParam String password,
32 @RequestParam String name,
33 @RequestParam String surname,
34 @RequestParam List<Integer> retainedSkills,
35 @RequestParam List<Integer> skillsToLearn){
36
37 List<Skill> retained = this.skillService.returnSkillsBasedOnId(retainedSkills);
38 List<Skill> toLearn = this.skillService.returnSkillsBasedOnId(skillsToLearn);
39
40 Account k = this.accountService.registerUser(email, password, name, surname, retained, toLearn);
41
42 Map<String, String> response = new HashMap<>();
43
44 if(k!=null){
45 response.put("error", "There was an error when trying to register user.");
46 }else{
47 response.put("success", "Registration completed successfully.");
48 }
49
50 return response;
51 }
52
53 @RequestMapping(path = "/team", method = RequestMethod.POST)
54 private Map<String, String> registerTeam(@RequestParam String email,
55 @RequestParam String password,
56 @RequestParam String name,
57 @RequestParam int members){
58
59 Account k = this.accountService.registerTeam(email, password, name, members);
60
61 Map<String, String> response = new HashMap<>();
62
63 if(k!=null){
64 response.put("error", "There was an error when trying to register team.");
65 }else{
66 response.put("success", "Registration completed successfully.");
67 }
68
69 return response;
70 }
71
72 @RequestMapping(path = "/company", method = RequestMethod.POST)
73 private Map<String, String> registerTeam(@RequestParam String email,
74 @RequestParam String password,
75 @RequestParam String name,
76 @RequestParam String country,
77 @RequestParam String city,
78 @RequestParam String street){
79
80 Account k = this.accountService.registerCompany(email, password, name, country, city, street);
81
82 Map<String, String> response = new HashMap<>();
83
84 if(k!=null){
85 response.put("error", "There was an error when trying to register company.");
86 }else{
87 response.put("success", "Registration completed successfully.");
88 }
89
90 return response;
91 }
92}
Note: See TracBrowser for help on using the repository browser.