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