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.register.account.CompanyRegisterDTO;
|
---|
6 | import it.finki.tinki.model.dto.register.account.TeamRegisterDTO;
|
---|
7 | import it.finki.tinki.model.dto.register.account.UserRegisterDTO;
|
---|
8 | import it.finki.tinki.service.AccountService;
|
---|
9 | import it.finki.tinki.service.SkillService;
|
---|
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 AccountRegisterController {
|
---|
20 |
|
---|
21 | AccountService accountService;
|
---|
22 | SkillService skillService;
|
---|
23 |
|
---|
24 | public AccountRegisterController(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(@RequestBody UserRegisterDTO body){
|
---|
31 |
|
---|
32 | List<Skill> retained = this.skillService.returnSkillsBasedOnId(body.getRetainedSkills());
|
---|
33 | List<Skill> toLearn = this.skillService.returnSkillsBasedOnId(body.getSkillsToLearn());
|
---|
34 | Account k = this.accountService.registerUser(body.getEmail(), body.getPassword(), body.getName(), body.getSurname(), retained, toLearn);
|
---|
35 | Map<String, String> response = new HashMap<>();
|
---|
36 |
|
---|
37 | if(k==null){
|
---|
38 | response.put("error", "There was an error when trying to register user.");
|
---|
39 | }else{
|
---|
40 | response.put("success", "Registration completed successfully.");
|
---|
41 | }
|
---|
42 |
|
---|
43 | return response;
|
---|
44 | }
|
---|
45 |
|
---|
46 | @RequestMapping(path = "/team", method = RequestMethod.POST)
|
---|
47 | private Map<String, String> registerTeam(@RequestBody TeamRegisterDTO body){
|
---|
48 |
|
---|
49 | Account k = this.accountService.registerTeam(body.getEmail(), body.getPassword(), body.getName(), body.getMembers());
|
---|
50 | Map<String, String> response = new HashMap<>();
|
---|
51 |
|
---|
52 | if(k==null){
|
---|
53 | response.put("error", "There was an error when trying to register team.");
|
---|
54 | }else{
|
---|
55 | response.put("success", "Registration completed successfully.");
|
---|
56 | }
|
---|
57 |
|
---|
58 | return response;
|
---|
59 | }
|
---|
60 |
|
---|
61 | @RequestMapping(path = "/company", method = RequestMethod.POST)
|
---|
62 | private Map<String, String> registerCompany(@RequestBody CompanyRegisterDTO body){
|
---|
63 |
|
---|
64 | Account k = this.accountService.registerCompany(body.getEmail(),
|
---|
65 | body.getPassword(), body.getName(), body.getCountry(), body.getCity(), body.getStreet());
|
---|
66 | Map<String, String> response = new HashMap<>();
|
---|
67 |
|
---|
68 | if(k==null){
|
---|
69 | response.put("error", "There was an error when trying to register company.");
|
---|
70 | }else{
|
---|
71 | response.put("success", "Registration completed successfully.");
|
---|
72 | }
|
---|
73 |
|
---|
74 | return response;
|
---|
75 | }
|
---|
76 | }
|
---|