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

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

refactoring and further login functionality

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