[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;
|
---|
[bd46dbb] | 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;
|
---|
[4a15c9c] | 8 | import it.finki.tinki.service.AccountService;
|
---|
[509cb95] | 9 | import it.finki.tinki.service.MatchmakerService;
|
---|
[4a15c9c] | 10 | import it.finki.tinki.service.SkillService;
|
---|
[509cb95] | 11 | import it.finki.tinki.service.WorkService;
|
---|
[4a15c9c] | 12 | import org.springframework.web.bind.annotation.*;
|
---|
| 13 |
|
---|
| 14 | import java.util.HashMap;
|
---|
| 15 | import java.util.List;
|
---|
| 16 | import java.util.Map;
|
---|
[7edede9] | 17 |
|
---|
| 18 | @RestController
|
---|
| 19 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
| 20 | @RequestMapping("/api/register")
|
---|
[297bd16] | 21 | public class AccountRegisterController {
|
---|
[7edede9] | 22 |
|
---|
[4a15c9c] | 23 | AccountService accountService;
|
---|
| 24 | SkillService skillService;
|
---|
[509cb95] | 25 | WorkService workService;
|
---|
| 26 | MatchmakerService matchmakerService;
|
---|
[4a15c9c] | 27 |
|
---|
[297bd16] | 28 | public AccountRegisterController(AccountService accountService, SkillService skillService, WorkService workService, MatchmakerService matchmakerService) {
|
---|
[4a15c9c] | 29 | this.accountService = accountService;
|
---|
| 30 | this.skillService = skillService;
|
---|
[509cb95] | 31 | this.workService = workService;
|
---|
| 32 | this.matchmakerService = matchmakerService;
|
---|
[4a15c9c] | 33 | }
|
---|
| 34 |
|
---|
| 35 | @RequestMapping(path = "/user", method = RequestMethod.POST)
|
---|
[b31afbd] | 36 | private Map<String, String> registerUser(@RequestBody UserRegisterDTO body){
|
---|
[4a15c9c] | 37 |
|
---|
[b31afbd] | 38 | List<Skill> retained = this.skillService.returnSkillsBasedOnId(body.getRetainedSkills());
|
---|
| 39 | List<Skill> toLearn = this.skillService.returnSkillsBasedOnId(body.getSkillsToLearn());
|
---|
[4a15c9c] | 40 |
|
---|
[b31afbd] | 41 | Account k = this.accountService.registerUser(body.getEmail(), body.getPassword(), body.getName(), body.getSurname(), retained, toLearn);
|
---|
[4a15c9c] | 42 |
|
---|
| 43 | Map<String, String> response = new HashMap<>();
|
---|
| 44 |
|
---|
[509cb95] | 45 | if(k==null){
|
---|
[4a15c9c] | 46 | response.put("error", "There was an error when trying to register user.");
|
---|
| 47 | }else{
|
---|
| 48 | response.put("success", "Registration completed successfully.");
|
---|
| 49 | }
|
---|
[7edede9] | 50 |
|
---|
[4a15c9c] | 51 | return response;
|
---|
| 52 | }
|
---|
[7edede9] | 53 |
|
---|
[9d4220d] | 54 | @RequestMapping(path = "/team", method = RequestMethod.POST)
|
---|
[31fc5c8] | 55 | private Map<String, String> registerTeam(@RequestBody TeamRegisterDTO body){
|
---|
[7edede9] | 56 |
|
---|
[31fc5c8] | 57 | Account k = this.accountService.registerTeam(body.getEmail(), body.getPassword(), body.getName(), body.getMembers());
|
---|
[9d4220d] | 58 |
|
---|
| 59 | Map<String, String> response = new HashMap<>();
|
---|
| 60 |
|
---|
[509cb95] | 61 | if(k==null){
|
---|
[9d4220d] | 62 | response.put("error", "There was an error when trying to register team.");
|
---|
| 63 | }else{
|
---|
| 64 | response.put("success", "Registration completed successfully.");
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | return response;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | @RequestMapping(path = "/company", method = RequestMethod.POST)
|
---|
[14b648e] | 71 | private Map<String, String> registerCompany(@RequestBody CompanyRegisterDTO body){
|
---|
[31fc5c8] | 72 |
|
---|
| 73 | Account k = this.accountService.registerCompany(body.getEmail(),
|
---|
| 74 | body.getPassword(), body.getName(), body.getCountry(), body.getCity(), body.getStreet());
|
---|
[9d4220d] | 75 |
|
---|
| 76 | Map<String, String> response = new HashMap<>();
|
---|
| 77 |
|
---|
[509cb95] | 78 | if(k==null){
|
---|
[9d4220d] | 79 | response.put("error", "There was an error when trying to register company.");
|
---|
| 80 | }else{
|
---|
| 81 | response.put("success", "Registration completed successfully.");
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | return response;
|
---|
| 85 | }
|
---|
[7edede9] | 86 | }
|
---|