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