1 | package it.finki.tinki.web.controller;
|
---|
2 |
|
---|
3 | import it.finki.tinki.model.Skill;
|
---|
4 | import it.finki.tinki.model.Users.Account;
|
---|
5 | import it.finki.tinki.model.dto.UserRegisterDTO;
|
---|
6 | import it.finki.tinki.service.AccountService;
|
---|
7 | import it.finki.tinki.service.MatchmakerService;
|
---|
8 | import it.finki.tinki.service.SkillService;
|
---|
9 | import it.finki.tinki.service.WorkService;
|
---|
10 | import org.springframework.web.bind.annotation.*;
|
---|
11 |
|
---|
12 | import java.util.HashMap;
|
---|
13 | import java.util.List;
|
---|
14 | import java.util.Map;
|
---|
15 |
|
---|
16 | @RestController
|
---|
17 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
18 | @RequestMapping("/api/register")
|
---|
19 | public class RegisterController {
|
---|
20 |
|
---|
21 | AccountService accountService;
|
---|
22 | SkillService skillService;
|
---|
23 | WorkService workService;
|
---|
24 | MatchmakerService matchmakerService;
|
---|
25 |
|
---|
26 | public RegisterController(AccountService accountService, SkillService skillService, WorkService workService, MatchmakerService matchmakerService) {
|
---|
27 | this.accountService = accountService;
|
---|
28 | this.skillService = skillService;
|
---|
29 | this.workService = workService;
|
---|
30 | this.matchmakerService = matchmakerService;
|
---|
31 | }
|
---|
32 |
|
---|
33 | @RequestMapping(path = "/user", method = RequestMethod.POST)
|
---|
34 | private Map<String, String> registerUser(@RequestBody UserRegisterDTO body){
|
---|
35 |
|
---|
36 | List<Skill> retained = this.skillService.returnSkillsBasedOnId(body.getRetainedSkills());
|
---|
37 | List<Skill> toLearn = this.skillService.returnSkillsBasedOnId(body.getSkillsToLearn());
|
---|
38 |
|
---|
39 | Account k = this.accountService.registerUser(body.getEmail(), body.getPassword(), body.getName(), body.getSurname(), retained, toLearn);
|
---|
40 |
|
---|
41 | Map<String, String> response = new HashMap<>();
|
---|
42 |
|
---|
43 | if(k==null){
|
---|
44 | response.put("error", "There was an error when trying to register user.");
|
---|
45 | }else{
|
---|
46 | response.put("success", "Registration completed successfully.");
|
---|
47 | }
|
---|
48 |
|
---|
49 | return response;
|
---|
50 | }
|
---|
51 |
|
---|
52 | //TODO: ADD TEAM AND COMPANY REGISTER TDO --------------------------------------v
|
---|
53 |
|
---|
54 | @RequestMapping(path = "/team", method = RequestMethod.POST)
|
---|
55 | private Map<String, String> registerTeam(@RequestBody String email,
|
---|
56 | @RequestBody String password,
|
---|
57 | @RequestBody String name,
|
---|
58 | @RequestBody int members){
|
---|
59 |
|
---|
60 | Account k = this.accountService.registerTeam(email, password, name, members);
|
---|
61 |
|
---|
62 | Map<String, String> response = new HashMap<>();
|
---|
63 |
|
---|
64 | if(k==null){
|
---|
65 | response.put("error", "There was an error when trying to register team.");
|
---|
66 | }else{
|
---|
67 | response.put("success", "Registration completed successfully.");
|
---|
68 | }
|
---|
69 |
|
---|
70 | return response;
|
---|
71 | }
|
---|
72 |
|
---|
73 | @RequestMapping(path = "/company", method = RequestMethod.POST)
|
---|
74 | private Map<String, String> registeCompany(@RequestBody String email,
|
---|
75 | @RequestBody String password,
|
---|
76 | @RequestBody String name,
|
---|
77 | @RequestBody String country,
|
---|
78 | @RequestBody String city,
|
---|
79 | @RequestBody String street){
|
---|
80 |
|
---|
81 | Account k = this.accountService.registerCompany(email, password, name, country, city, street);
|
---|
82 |
|
---|
83 | Map<String, String> response = new HashMap<>();
|
---|
84 |
|
---|
85 | if(k==null){
|
---|
86 | response.put("error", "There was an error when trying to register company.");
|
---|
87 | }else{
|
---|
88 | response.put("success", "Registration completed successfully.");
|
---|
89 | }
|
---|
90 |
|
---|
91 | return response;
|
---|
92 | }
|
---|
93 | }
|
---|